├── LICENSE ├── README.md ├── b50.txt ├── c21.txt ├── create_matrix.m ├── draw_convergence.m ├── draw_distribution.m ├── draw_net.m ├── draw_pf.m ├── example.txt ├── execute re-encoding.bat ├── extract_value.m ├── fitness.m ├── floyd_algo.m ├── main.m ├── pareto_front.m ├── re-encoding.ps1 ├── read_dataset.m ├── reorganize.m ├── test.m ├── validate.m └── 说明 ├── 优化MOPSO算法流程图.jpeg ├── 优化MOPSO算法流程图.pos ├── 优化MOPSO算法流程图.svg ├── 函数依赖图.png ├── 函数依赖图.pptx ├── 数据集说明.docx └── 算法的若干细节.docx /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 用改进后的多目标粒子群优化(MOPSO)算法解决带有风险矩阵的多辆车配送旅行商问题(TSP) 2 | 3 | - [用改进后的多目标粒子群优化(MOPSO)算法解决带有风险矩阵的多辆车配送旅行商问题(TSP)](#用改进后的多目标粒子群优化mopso算法解决带有风险矩阵的多辆车配送旅行商问题tsp) 4 | - [1. 项目说明](#1-项目说明) 5 | - [2. 资源](#2-资源) 6 | - [2.1. 本文件夹的文件结构](#21-本文件夹的文件结构) 7 | - [2.2. “说明”文件夹的文件结构](#22-说明文件夹的文件结构) 8 | - [2.3. 其他资源](#23-其他资源) 9 | - [3. 使用](#3-使用) 10 | - [3.1. 步骤](#31-步骤) 11 | - [3.2. 出现乱码?](#32-出现乱码) 12 | - [3.3. 在 MATLAB 2022a 下运行失败?](#33-在-matlab-2022a-下运行失败) 13 | - [4. 算法](#4-算法) 14 | - [4.1. 问题情景](#41-问题情景) 15 | - [4.2. 算法思路](#42-算法思路) 16 | - [4.3. 流程图与依赖图](#43-流程图与依赖图) 17 | - [4.4. 时间复杂度](#44-时间复杂度) 18 | - [4.5. 算法优缺点](#45-算法优缺点) 19 | - [优点](#优点) 20 | - [缺点](#缺点) 21 | - [4.6. 了解更多](#46-了解更多) 22 | - [5. 数据集](#5-数据集) 23 | - [引用](#引用) 24 | 25 | ## 1. 项目说明 26 | 27 | 此代码是河南财经政法大学硕士项目的一部分,受 GPL-3.0-only 开源协议保护。GitHub 地址:https://github.com/Ki-Seki/MOPSO-for-Distribution 28 | 29 | This code is a part of a HUEL master degree project under the protection of GPL-3.0-only license. GitHub Link: https://github.com/Ki-Seki/MOPSO-for-Distribution 30 | 31 | ## 2. 资源 32 | 33 | ### 2.1. 本文件夹的文件结构 34 | 35 | |名称或后缀|包含文件数|作用| 36 | |--|--|--| 37 | |`README.md`|1|本文档| 38 | |`*.m`|14|实现本算法的核心代码、测试文件等| 39 | |`*.txt`|3|给出的三个样例数据集| 40 | |`re-encoding.ps1`|1|用于编码格式转换的 PowerShell 脚本| 41 | |`execute re-encoding.bat`|1|用于执行上述脚本的 Batch 脚本| 42 | |`LICENSE`|1|GPL-3.0-only 开源协议| 43 | |`说明`|6|关于此项目算法、数据集的一系列辅助说明文件| 44 | 45 | ### 2.2. “说明”文件夹的文件结构 46 | 47 | |名称|类型|作用| 48 | |--|--|--| 49 | |`优化MOPSO算法流程图.png`|PNG 图片|描述了该算法的流程图| 50 | |`优化MOPSO算法流程图.pos`|POS 源文件|上述文件的源文件,在 [ProcessOn](https://www.processon.com/) 打开即可重新编辑| 51 | |`函数依赖图.png`|PNG 图片|描述了该算法各个模块间的相互依赖关系| 52 | |`函数依赖图.pptx`|PPT 源文件|上述文件的源文件,可重新编辑| 53 | |`算法的若干细节.docx`|WORD 文档|讲解了算法的四个细节:位置的编码与解的编码,速度与位置的重编码,适应度函数的设计,用帕累托前沿来替代粒子群优化中的全局最优| 54 | |`数据集说明.docx`|WORD 文档|以 `example.txt` 为例,详细地对数据集进行了说明| 55 | 56 | ### 2.3. 其他资源 57 | 58 | |名称|类型|作用|链接| 59 | |--|--|--|--| 60 | |`MOPSO说明与使用`|在线视频|包含对 MOPSO 的使用、算法、数据集的介绍|[Loom](https://loom.com/share/folder/5ee40289950a4896a24e5c6392fdca02)| 61 | |`优化MOPSO算法流程图`|在线流程图|MOPSO 的 `main.m` 程序的流程图的在线查看版本|[ProcessOn](https://www.processon.com/view/link/6201fb816376890390d1dd07)| 62 | 63 | ## 3. 使用 64 | 65 | ### 3.1. 步骤 66 | 67 | 1. 选择性修改 `main.m` 中“%% 参数设置”部分的参数 68 | 2. 运行 `main.m` 程序 69 | 3. 在命令行窗口交互式地查看输出,在图片窗口中查看输出的图表 70 | 71 | ### 3.2. 出现乱码? 72 | 73 | 如果打开代码文件出现乱码,请阅读本小节 74 | 75 | MATLAB 对文件的编码遵照系统默认编码格式(GB 2312)。而本项目包括本文件都是 UTF-8 编码的。为了解决这一冲突,提供如下方法(仅在 Windows 平台可用): 76 | 77 | * 在文件管理器中打开本文件夹,双击运行 `execute re-encoding.m` 文件 78 | * 这会生成与本文件夹同级的文件夹 `encoded` ,它包含重新编码后的文件 79 | * 在 MATLAB 中打开 `encoded` 文件夹即可,其中的文件均采用系统默认编码格式 80 | 81 | ### 3.3. 在 MATLAB 2022a 下运行失败? 82 | 83 | 由于 MATLAB 2015b 固有的 Bug 及与 MATLAB 2022a 的版本兼容性问题,直接下载下来的代码运行时会报错。可根据下表按需修改: 84 | 85 | |文件名|行数|原内容|修改后内容| 86 | |--|--|--|--| 87 | |`extract_value.m`|16|`matchsize-field2size-2`|`matchsize-field2size-1`| 88 | |`draw_convergence.m`|8|`suptitle`|`sgtitle`| 89 | 90 | ## 4. 算法 91 | 92 | ### 4.1. 问题情景 93 | 94 | 疫情下不同节点风险等级不同,车辆跨异风险区运输需要相应的消杀成本,如何在此约束下解决含有多辆车及多目标的应急物资配送问题? 95 | 96 | ### 4.2. 算法思路 97 | 98 | 本算法 = 普通粒子群优化 + 多目标优化 + 帕累托前沿 + 针对 TSP 的速度位置重编码 99 | 100 | ### 4.3. 流程图与依赖图 101 | 102 | 有三个地方可以查看该算法的流程图,分别是在线的 [ProcessOn](https://www.processon.com/view/link/6201fb816376890390d1dd07),离线的图片 [优化MOPSO算法流程图.png](.\说明\优化MOPSO算法流程图.png) 和离线的 POS 文件 [优化MOPSO算法流程图.pos](.\说明\优化MOPSO算法流程图.pos). 其中,POS 文件是流程图绘制平台 ProcessOn 的源文件,从其官网打开即可对该文件再做修改。 103 | 104 | 在 `说明` 文件夹下,有函数依赖图,方便查看该算法代码各个模块间的相互依赖关系。 105 | 106 | ### 4.4. 时间复杂度 107 | 108 | 算法核心部分循环 loop_cnt 次;每次都要遍历粒子群中所有粒子,共 particle_cnt 个粒子;算法的瓶颈在于 fitness() 函数,此函数的算法复杂度与 NODE_COUNT 呈正相关。因此最终算法时间复杂度为 O(loop_cnt × particle_cnt × NODE_COUNT). 109 | 110 | 令 N = max{loop_cnt, particle_cnt,NODE_COUNT}, 则算法时间复杂度也可表示为 O(N³). 111 | 112 | ### 4.5. 算法优缺点 113 | 114 | #### 优点 115 | 116 | * 多目标粒子群优化(Multi-Objective PSO)算法:运用多目标优化的理论将单目标的粒子群优化算法改为支持多目标问题的求解 117 | * 风险矩阵:解决疫情下应急物资配送的一个强大数学工具 118 | * 适应度矩阵:构造这一矩阵,大大方便了从单目标到多目标问题的过渡 119 | * 速度与位置的重编码:问题情景为含有多辆车配送的 TSP(旅行商问题),其解的编码是离散的,而普通的粒子群优化算法处理的是连续的值,因此需要速度与位置的重编码 120 | * 帕累托前沿:使用帕累托前沿,也就是非支配解集来表现该多目标问题的解 121 | * 算法通用性非常强:解决 TSP 问题时,普通算法往往直接假设任意两个结点之间都存在直接边相连;而本算法不对此做要求。这更能有效解决现实问题 122 | 123 | #### 缺点 124 | 125 | * 复杂度:达到三次方级别,对于特大型问题的处理效率有待提升 126 | * 两个帕累托前沿的比较方法,用的是平均数比较方法,较为简单 127 | 128 | ### 4.6. 了解更多 129 | 130 | 可以在 [算法的若干细节.docx](./说明/算法的若干细节.docx) 文档中获取对算法的深入理解。该文档重点讲解了该算法的四个部分:“位置的编码与解的编码”,“速度与位置的重编码”,“适应度函数的设计”,“用帕累托前沿来替代粒子群优化中的全局最优”。 131 | 132 | ## 5. 数据集 133 | 134 | 网上并无现成的数据集,需要自己制作数据集。本文件夹提供了三个数据集,其文件名分别为:`example.txt`, `b50.txt`, `c21.txt`。其中,`example.txt` 是一个示例测试数据集,仅有 7 个结点,其他两个数据集后缀的数字均为其中结点数量。 135 | 136 | 在 [数据集说明.docx](./说明/数据集说明.docx) 文档中以 `example.txt` 为例,详细地对数据集进行了说明。 137 | 138 | ## 引用 139 | 140 | BibTex 格式: 141 | 142 | ```bibtex 143 | @unpublished{MOPSOfD, 144 | author = "宋世超", 145 | title = "用改进后的多目标粒子群优化(MOPSO)算法解决带有风险矩阵的多辆车配送旅行商问题(TSP)", 146 | year = 2022 147 | } 148 | ``` 149 | 150 | GB/T 7714-2015 格式: 151 | 152 | ``` 153 | [1]宋世超.用改进后的多目标粒子群优化(MOPSO)算法解决带有风险矩阵的多辆车配送旅行商问题(TSP)[CP].GitHub[2022].https://github.com/Ki-Seki/MOPSO-for-Distribution. 154 | ``` -------------------------------------------------------------------------------- /b50.txt: -------------------------------------------------------------------------------- 1 | DATASET: b50 2 | NODE_COUNT: 50 3 | NODE: 4 | 0 43.18910733 48.68496758 5 | 1 74.03560176 17.41722795 6 | 2 125.7439126 143.5916782 7 | 3 140.016796 5.344924045 8 | 4 18.25020376 120.3795128 9 | 5 77.95325814 27.03274968 10 | 6 29.30449854 56.84136166 11 | 7 11.26073045 32.37145736 12 | 8 30.9385556 58.42743871 13 | 9 8.755975858 16.04662356 14 | 10 131.1052359 12.60021853 15 | 11 134.4875199 98.72766559 16 | 12 43.20808881 50.85688846 17 | 13 136.9954985 17.82868691 18 | 14 23.60570096 40.79206412 19 | 15 124.603527 36.81747663 20 | 16 84.91428948 96.53574847 21 | 17 129.5572659 61.61933058 22 | 18 123.032034 25.53016795 23 | 19 55.43766008 142.4755682 24 | 20 93.80290391 18.39590335 25 | 21 85.62230688 5.636814291 26 | 22 27.76091392 144.2453693 27 | 23 10.25910481 34.56350472 28 | 24 24.87597187 4.65699853 29 | 25 110.7448036 70.55987018 30 | 26 39.54489908 105.3060982 31 | 27 138.5843442 101.9007672 32 | 28 57.50907925 58.62505869 33 | 29 96.47439966 144.6719615 34 | 30 61.90305644 120.7535193 35 | 31 120.8667781 139.257295 36 | 32 142.3590472 56.65623923 37 | 33 66.05658002 113.6901494 38 | 34 132.5369473 108.2634774 39 | 35 39.22559072 121.3254865 40 | 36 69.22794391 6.873900375 41 | 37 31.68178188 133.3757189 42 | 38 54.85587776 88.49858359 43 | 39 73.15156968 81.39174643 44 | 40 83.14156962 40.28216636 45 | 41 117.9253207 41.93434527 46 | 42 127.4919982 116.5495159 47 | 43 54.65097084 4.99302941 48 | 44 136.4635619 104.8809513 49 | 45 146.4918511 42.27021611 50 | 46 68.33451684 112.1124349 51 | 47 53.0752936 60.05557318 52 | 48 91.57856363 90.59027994 53 | 49 110.5025817 108.5734289 54 | EDGE_COUNT: 51 55 | EDGE: 56 | 0 28 57 | 0 27 58 | 1 29 59 | 1 28 60 | 2 30 61 | 2 29 62 | 3 31 63 | 3 30 64 | 4 32 65 | 4 31 66 | 5 38 67 | 6 27 68 | 7 33 69 | 7 32 70 | 8 34 71 | 8 33 72 | 9 35 73 | 9 34 74 | 10 36 75 | 10 35 76 | 11 37 77 | 11 36 78 | 12 38 79 | 12 37 80 | 13 39 81 | 13 38 82 | 14 40 83 | 14 39 84 | 15 41 85 | 15 40 86 | 16 42 87 | 16 41 88 | 17 26 89 | 18 43 90 | 18 42 91 | 19 44 92 | 19 43 93 | 20 45 94 | 20 44 95 | 21 46 96 | 21 45 97 | 22 47 98 | 22 46 99 | 23 48 100 | 23 47 101 | 23 26 102 | 23 25 103 | 24 49 104 | 24 48 105 | 24 27 106 | 24 26 107 | VEHICLE_COUNT: 100 108 | VEHICLE_CAPACITY: 1735 109 | VEHICLE_SHIPPING_COST: 0.53 110 | VEHICLE_FIXED_COST: 100 111 | VEHICLE_DISINFECTION_COST: 300 112 | VEHICLE_VELOCITY: 80 113 | DEMAND: 114 | 1 519 115 | 2 602 116 | 3 917 117 | 4 562 118 | 5 59 119 | 6 761 120 | 7 373 121 | 8 956 122 | 9 610 123 | 10 692 124 | 11 249 125 | 12 895 126 | 13 795 127 | 14 591 128 | 15 320 129 | 16 556 130 | 17 576 131 | 18 135 132 | 19 724 133 | 20 543 134 | 21 225 135 | 22 53 136 | 23 633 137 | 24 84 138 | 25 332 139 | 26 200 140 | 27 92 141 | 28 347 142 | 29 945 143 | 30 570 144 | 31 517 145 | 32 723 146 | 33 345 147 | 34 428 148 | 35 237 149 | 36 732 150 | 37 354 151 | 38 325 152 | 39 599 153 | 40 961 154 | 41 178 155 | 42 147 156 | 43 725 157 | 44 788 158 | 45 178 159 | 46 992 160 | 47 835 161 | 48 380 162 | 49 134 163 | RISK_MATRIX: 164 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 165 | 1 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 166 | 1 1 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 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1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 207 | 1 1 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 208 | 1 1 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 209 | 1 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 210 | 1 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 211 | 1 1 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 212 | 1 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 213 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 214 | EOF -------------------------------------------------------------------------------- /c21.txt: -------------------------------------------------------------------------------- 1 | DATASET: c21 2 | NODE_COUNT: 21 3 | NODE: 4 | 0 68.18250552 52.23756662 5 | 1 56.7263866 32.28742038 6 | 2 15.2350627 143.1505891 7 | 3 64.66491217 111.6610127 8 | 4 143.014375 87.50969998 9 | 5 41.03674743 32.23180419 10 | 6 31.87945314 26.22635449 11 | 7 115.9354515 73.62541245 12 | 8 142.2641418 40.15753628 13 | 9 25.44411033 16.89728301 14 | 10 74.30479648 104.5248395 15 | 11 31.19534741 3.272164183 16 | 12 14.68894782 45.71133773 17 | 13 125.9543362 49.4473015 18 | 14 119.1362749 149.2005003 19 | 15 111.5566357 107.0289025 20 | 16 74.09200024 91.59433617 21 | 17 15.51536768 12.82820252 22 | 18 110.4402347 135.0419069 23 | 19 19.09493919 23.97566252 24 | 20 27.83652742 81.30996107 25 | EDGE_COUNT: 32 26 | EDGE: 27 | 0 1 28 | 0 3 29 | 1 2 30 | 1 4 31 | 2 5 32 | 3 4 33 | 3 6 34 | 4 5 35 | 4 7 36 | 5 8 37 | 6 7 38 | 6 9 39 | 7 8 40 | 7 10 41 | 8 11 42 | 9 10 43 | 9 12 44 | 10 11 45 | 10 13 46 | 11 14 47 | 12 13 48 | 12 15 49 | 13 14 50 | 13 16 51 | 14 17 52 | 15 16 53 | 15 18 54 | 16 17 55 | 16 19 56 | 17 20 57 | 18 19 58 | 19 20 59 | VEHICLE_COUNT: 30 60 | VEHICLE_CAPACITY: 1735 61 | VEHICLE_SHIPPING_COST: 0.53 62 | VEHICLE_FIXED_COST: 100 63 | VEHICLE_DISINFECTION_COST: 300 64 | VEHICLE_VELOCITY: 80 65 | DEMAND: 66 | 1 1408 67 | 2 1380 68 | 3 484 69 | 4 450 70 | 5 409 71 | 6 1013 72 | 7 638 73 | 8 180 74 | 9 1409 75 | 10 202 76 | 11 1332 77 | 12 59 78 | 13 1101 79 | 14 123 80 | 15 96 81 | 16 1387 82 | 17 864 83 | 18 950 84 | 19 139 85 | 20 1302 86 | RISK_MATRIX: 87 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 88 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 89 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 90 | 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 91 | 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 92 | 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 93 | 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 94 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 95 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 96 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 97 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 98 | 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 99 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 | 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 101 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 102 | 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 103 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 104 | 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 105 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 106 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 107 | 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 108 | EOF -------------------------------------------------------------------------------- /create_matrix.m: -------------------------------------------------------------------------------- 1 | % 根据结点集和边集创建邻接矩阵 2 | function m = create_matrix(n, e, default) 3 | % n 结点集,三列(结点编号,横坐标,纵坐标)的矩阵 4 | % e 边集,两列(起点,终点)的矩阵 5 | % default 用 0 还是 Inf 来填充无边相连的点 6 | % m 邻接矩阵 7 | 8 | n_cnt = size(n, 1); 9 | e_cnt = size(e, 1); 10 | m = repmat(default, n_cnt); % 初始化邻接矩阵 11 | 12 | % 对角线清 0 13 | for i = 1 : n_cnt 14 | m(i, i) = 0; 15 | end 16 | 17 | for i = 1 : e_cnt 18 | n1 = e(i, 1) + 1; % 起始节点的索引编号 19 | n2 = e(i, 2) + 1; % 结束节点的索引编号 20 | x1 = n(n1, 2); % 起始节点的横坐标 21 | x2 = n(n2, 2); % 结束节点的横坐标 22 | y1 = n(n1, 3); % 起始节点的纵坐标 23 | y2 = n(n2, 3); % 结束节点的纵坐标 24 | m(n1, n2) = sqrt(power(x1-x2,2) + power(y1-y2,2)); 25 | m(n2, n1) = m(n1, n2); % 对称操作 26 | end 27 | end -------------------------------------------------------------------------------- /draw_convergence.m: -------------------------------------------------------------------------------- 1 | % 绘制 PSO 收敛过程图 2 | function draw_convergence(f, conv, field) 3 | % f 记录迭代:每行包括两目标每次在帕累托前沿中的平均值 4 | % conv 两目标收敛时分别的迭代次数 5 | % field 数据集 6 | 7 | figure('Name','MOPSO 收敛过程','NumberTitle','off') 8 | suptitle(['MOPSO 两目标收敛过程图(数据集:', field.DATASET, ')']); 9 | 10 | %% 绘制 T 的收敛过程 11 | 12 | subplot(2, 1, 1); 13 | plot(f(:, 1), '- .r'); 14 | hold on; 15 | pt = plot(conv, f(conv, 1), 'or'); 16 | labelt = [' (' num2str(conv) ', ' num2str(f(conv, 1)) ')']; % 收敛点的标签 17 | 18 | xlabel('迭代次数'); 19 | ylabel('平均时间(小时)'); 20 | legend(pt, ['收敛点' labelt]); 21 | hold off; 22 | 23 | %% 绘制 Z 的收敛过程 24 | 25 | subplot(2, 1, 2); 26 | plot(f(:, 2), '- .r'); 27 | hold on; 28 | pz = plot(conv, f(conv, 2), 'or'); 29 | labelz = [' (' num2str(conv) ', ' num2str(f(conv, 2)) ')']; % 收敛点的标签 30 | 31 | xlabel('迭代次数'); 32 | ylabel('平均成本(元)'); 33 | legend(pz, ['收敛点' labelz]); 34 | hold off; 35 | end -------------------------------------------------------------------------------- /draw_distribution.m: -------------------------------------------------------------------------------- 1 | % 绘制某个粒子代表的配送方案 2 | function draw_distribution(p, v, field) 3 | % p 最优粒子 4 | % v 车辆配送方案,行向量,每个元素代表一辆车,元素值是该车服务需求点数 5 | % field 数据集 6 | 7 | g = graph(create_matrix(field.NODE, field.EDGE, 0)); % 创建图对象 8 | st = 1; % 某辆车起始服务点,p(st) 是服务点编号 9 | for i = 1 : size(v, 2) % 遍历每辆车 10 | ed = st + v(i) - 1; % 某辆车终止服务点,p(ed) 是服务点编号 11 | 12 | %注意:下面常出现 p(),一般要令其 +1,是因为 matrix 是包括原点的 13 | 14 | %% 获得被该车辆服务的需求点的坐标,以便绘图 15 | 16 | servee = zeros(v(i), 2); 17 | for j = st : ed 18 | x = field.NODE(p(j) + 1, 2); 19 | y = field.NODE(p(j) + 1, 3); 20 | servee(j - st + 1, 1) = x; 21 | servee(j - st + 1, 2) = y; 22 | end 23 | 24 | %% 计算路径 25 | 26 | full_path = [shortestpath(g, 0+1, p(st)+1)]; % 加上原点到第一服务点路径 27 | for j = st+1 : ed % 遍历每辆车服务的点 28 | path = shortestpath(g, p(j-1)+1, p(j)+1); 29 | full_path = [full_path path(2:end)]; 30 | end 31 | path = shortestpath(g, p(ed)+1, 0+1); 32 | full_path = [full_path path(2:end)]; 33 | path_size = size(full_path, 2); 34 | 35 | %% 字符串化路径方便展示 36 | 37 | % 注意:需要 -1,因为 Matlab 下标从 1 开始 38 | 39 | txt_path = num2str(full_path(1)-1); 40 | for j = 2 : path_size 41 | txt_path = [txt_path '→' num2str(full_path(j)-1)]; 42 | end 43 | 44 | %% 绘图 45 | 46 | figure('Name',['第' num2str(i) '辆车配送方案图'],'NumberTitle','off'); 47 | 48 | % 绘制散点图 49 | scatter(field.NODE(:,2), field.NODE(:,3), 'b'); 50 | hold on; 51 | scatter(servee(:, 1), servee(:, 2), 'filled', 'b'); 52 | 53 | % 添加标签 54 | for j = 1 : field.NODE_COUNT 55 | x = field.NODE(j, 2); % 横坐标 56 | y = field.NODE(j, 3); % 纵坐标 57 | label = [num2str(j-1) ' (' num2str(x) ',' num2str(y) ') ']; 58 | if j > 1 % 如果是需求点 59 | label = [label num2str(field.DEMAND(j-1,2))]; 60 | end 61 | offset = 3; % 防止标签被 marker 挡住 62 | text(x+offset, y+offset, label); % 写标签 63 | end 64 | 65 | % 绘制路径 66 | X = zeros(path_size); 67 | Y = zeros(path_size); 68 | for j = 1 : path_size 69 | X(j) = field.NODE(full_path(j), 2); 70 | Y(j) = field.NODE(full_path(j), 3); 71 | end 72 | plot(X, Y, '-r'); 73 | title(['第' num2str(i) '辆车配送方案图(数据集:' field.DATASET ')']); 74 | xlabel('横坐标(千米)'); 75 | ylabel('纵坐标(千米)'); 76 | legend('途径点(编号 坐标 需求量)', '服务点(编号 坐标 需求量)', ['路径:' txt_path]); 77 | hold off; 78 | 79 | %% 更新 st 80 | 81 | st = ed + 1; 82 | end 83 | end -------------------------------------------------------------------------------- /draw_net.m: -------------------------------------------------------------------------------- 1 | % 绘制结点网络图 2 | function draw_net(field, graph_option) 3 | % field 数据集 4 | % graph_option 绘图选项,定义在 main.m 中 5 | 6 | node = field.NODE; 7 | 8 | %% 结点网络路径图 9 | 10 | figure('Name','结点网络路径图','NumberTitle','off') 11 | scatter(node(:,2), node(:,3), 'filled'); 12 | 13 | % 添加标签 14 | for i = 1 : field.NODE_COUNT 15 | x = node(i, 2); % 横坐标 16 | y = node(i, 3); % 纵坐标 17 | label = [num2str(i-1) ' (' num2str(x) ',' num2str(y) ') ']; % 结点标签 18 | if i > 1 % 如果是需求点 19 | label = [label num2str(field.DEMAND(i-1,2))]; % 结点标签加上需求量 20 | end 21 | offset = 3; % 防止标签被 marker 挡住 22 | text(x+offset, y+offset, label); % 写标签 23 | end 24 | 25 | % 如果要求详细绘图,添加边 26 | if graph_option.detail == true 27 | hold on; 28 | for i = 1 : field.EDGE_COUNT 29 | n1 = field.EDGE(i, 1) + 1; % 起始点编号 30 | n2 = field.EDGE(i, 2) + 1; % 结束点编号 31 | x = [node(n1,2), node(n2,2)]; 32 | y = [node(n1,3), node(n2,3)]; 33 | plot(x, y, 'red'); % 连接两个点 34 | end 35 | hold off; 36 | end 37 | 38 | 39 | % 添加说明 40 | xlabel('横坐标(千米)'); 41 | ylabel('纵坐标(千米)'); 42 | title(['结点网络路径图(数据集:', field.DATASET, ')']); 43 | if graph_option.detail == true 44 | legend('结点(编号 坐标 需求量)' ,'边'); 45 | else 46 | legend('结点(编号 坐标 需求量)'); 47 | end 48 | 49 | %% 结点网络拓扑图 50 | 51 | g = graph(create_matrix(field.NODE, field.EDGE, 0)); 52 | figure('Name','结点网络拓扑图','NumberTitle','off') 53 | plot(g, 'NodeLabel', 0:field.NODE_COUNT-1, 'EdgeLabel', g.Edges.Weight); 54 | title(['结点网络拓扑图(数据集:', field.DATASET, ')']); 55 | set(gca,'xtick',[],'xticklabel',[]); % 隐藏坐标轴,因为无实际含义,下同 56 | set(gca,'ytick',[],'yticklabel',[]); 57 | end -------------------------------------------------------------------------------- /draw_pf.m: -------------------------------------------------------------------------------- 1 | % 绘制帕累托前沿图 2 | function draw_pf(fit, pf, field, graph_option) 3 | % fit 适应度矩阵,每行表示一个粒子的适应度,包含 T 总时间和 Z 总成本两个元素 4 | % pf 帕累托前沿解集,是一个逻辑索引,每个元素为布尔值,若为 1 表示对应粒子在帕累托前沿上 5 | % field 数据集 6 | % graph_option 绘图选项,定义在 main.m 中 7 | 8 | figure('Name','帕累托前沿','NumberTitle','off'); 9 | 10 | %% 绘制非支配解散点图 11 | 12 | scatter(fit(pf, 1), fit(pf, 2), 'r'); 13 | xlabel('目标 1:T(小时)'); 14 | ylabel('目标 2:Z(元)'); 15 | title(['帕累托前沿图(数据集:', field.DATASET, ')']); 16 | 17 | %% 为非支配解添加标签 18 | 19 | p = fit(pf, :); % 获取非支配解解集 20 | cnt = size(p, 1); 21 | for i = 1 : cnt 22 | t = num2str(round(p(i, 1), 2)); % 保留两位小数,转换为字符串 23 | z = num2str(round(p(i, 2), 2)); 24 | label = ['(' t ',' z ') ']; 25 | offset = 1.005; % 为了不让标签盖住坐标点,添加偏置 26 | text(p(i, 1)*offset, p(i, 2)*offset, label); 27 | end 28 | 29 | %% 绘制帕累托前沿曲线 30 | 31 | p = sortrows(p, 1); % 按首列(时间)进行升序排序 32 | hold on, plot(p(:,1), p(:,2)), hold off; 33 | 34 | %% 选择性详细绘图 35 | 36 | if graph_option.detail == true 37 | hold on, scatter(fit(~pf, 1), fit(~pf, 2), 'r.'), hold off; % 绘制被支配解 38 | legend('非支配解(时间,成本)', '帕累托前沿', '被支配解'); 39 | else 40 | legend('非支配解(时间,成本)', '帕累托前沿'); 41 | end 42 | end -------------------------------------------------------------------------------- /example.txt: -------------------------------------------------------------------------------- 1 | DATASET: example 2 | NODE_COUNT: 7 3 | NODE: 4 | 0 345 184 5 | 1 21 99 6 | 2 200 190 7 | 3 150 200 8 | 4 177 37 9 | 5 76 211 10 | 6 75 64 11 | EDGE_COUNT: 7 12 | EDGE: 13 | 0 2 14 | 0 4 15 | 1 2 16 | 1 5 17 | 2 3 18 | 3 6 19 | 5 6 20 | VEHICLE_COUNT: 10 21 | VEHICLE_CAPACITY: 450 22 | VEHICLE_SHIPPING_COST: 0.5 23 | VEHICLE_FIXED_COST: 100 24 | VEHICLE_DISINFECTION_COST: 10 25 | VEHICLE_VELOCITY: 80 26 | DEMAND: 27 | 1 345 28 | 2 134 29 | 3 200 30 | 4 365 31 | 5 220 32 | 6 44 33 | RISK_MATRIX: 34 | 1 0 0 1 1 0 0 35 | 1 1 0 1 1 0 0 36 | 1 1 1 1 1 0 0 37 | 0 0 0 1 1 0 0 38 | 0 0 0 0 1 0 0 39 | 1 1 1 1 1 1 0 40 | 1 1 1 1 1 1 1 41 | EOF 42 | -------------------------------------------------------------------------------- /execute re-encoding.bat: -------------------------------------------------------------------------------- 1 | powershell .\re-encoding.ps1 -------------------------------------------------------------------------------- /extract_value.m: -------------------------------------------------------------------------------- 1 | % 将数据集中第 field_num 个字段值提取成字符串 value 2 | function value = extract_value(datatext, field, field_num) 3 | % datatext 数据集字符串 4 | % field 字段名数组 5 | % field_num 要提取的字段的序号 6 | % value 字符串返回值 7 | 8 | field1 = field{field_num}; 9 | field2 = field{field_num + 1}; 10 | regex = [field1, '.+', field2]; 11 | matches = regexp(datatext, regex, 'match'); 12 | match = matches{1}; 13 | matchsize = size(match, 2); 14 | field1size = size(field1, 2); 15 | field2size = size(field2, 2); 16 | value = match(field1size+1 : matchsize-field2size-2); 17 | end -------------------------------------------------------------------------------- /fitness.m: -------------------------------------------------------------------------------- 1 | % 多目标适应度函数,计算粒子群 particle 的配送总时间和总成本 2 | function [fit, vehicle, dist, risk] = fitness(particle, field, matrix) 3 | % particle 粒子群,每行是一个粒子(允许只有一个粒子) 4 | % field 数据集 5 | % matrix 邻接矩阵 6 | % fit 适应度矩阵,每行表示一个粒子的适应度,包含 T 总时间和 Z 总成本两个元素 7 | % 以下返回值按需取用 8 | % vehicle 元胞数组,每行是一个车辆使用情况数组,其中每个元素代表一辆车,元素值是该车服务需求点数 9 | % dist 总运距数组,每行代表一个粒子的总运距 10 | % risk 总消杀次数数组,每行代表一个粒子的总消杀次数 11 | 12 | [m, n] = size(particle); % 获取粒子个数和需求点个数 13 | 14 | % 返回值初始化 15 | fit = zeros(m, 2); 16 | vehicle = cell(m, 1); 17 | dist = zeros(m, 1); 18 | risk = zeros(m, 1); 19 | 20 | for i = 1 : m % 遍历每一个粒子 21 | 22 | p = particle(i, :); % 当前粒子 23 | 24 | %% 求车辆使用情况 25 | 26 | k = 1; % 车辆使用数量 27 | v = [0]; % 车辆使用情况数组 28 | load = 0; % 当前载重 29 | for j = 1 : n % 遍历每一个需求点,其编号为 p(j) 30 | demand = field.DEMAND(p(j), 2); % 需求点需求量 31 | if load + demand > field.VEHICLE_CAPACITY % 若车载不足 32 | k = k + 1; % 车数加一 33 | v = [v 0]; % 车数加一 34 | load = 0; % 载重清空 35 | end 36 | v(k) = v(k) + 1; % 第 k 辆车服务数量加一 37 | load = load + demand; % 增加载重 38 | end 39 | 40 | %% 计算总运距和总消杀成本 41 | 42 | d = 0; % 总运距 43 | r = 0; % 总消杀次数 44 | st = 1; % 某辆车起始服务点,p(st) 是服务点编号 45 | for j = 1 : k % 遍历每一辆车 46 | ed = st + v(j) - 1; % 某辆车终止服务点,p(ed) 是服务点编号 47 | 48 | % 注意:下面常出现 p(),一般要令其 +1,是因为 matrix 是包括原点的 49 | 50 | d = d + matrix(1, p(st)+1); % 加上原点到第一服务点距离 51 | r = r + field.RISK_MATRIX(1, p(st)+1); % 加上原点到第一服务点的风险 52 | for l = st+1 : ed % 遍历第 j 辆车服务的需求点 53 | d = d + matrix(p(l-1)+1, p(l)+1); 54 | r = r + field.RISK_MATRIX(p(l-1)+1, p(l)+1); 55 | end 56 | d = d + matrix(p(ed)+1, 1); % 加上最后服务点到原点距离 57 | r = r + field.RISK_MATRIX(p(ed)+1, 1); % 加上最后服务点到原点风险 58 | 59 | st = ed + 1; % 更新 st 60 | end 61 | 62 | %% 计算当前粒子的总时间和总成本 63 | 64 | t = d / field.VEHICLE_VELOCITY; % 小时 65 | z = d * field.VEHICLE_SHIPPING_COST + ... 66 | k * field.VEHICLE_FIXED_COST + ... 67 | r * field.VEHICLE_DISINFECTION_COST; % 元 68 | 69 | %% 更新返回值 70 | 71 | fit(i, :) = [t, z]; 72 | vehicle{i} = v; 73 | dist(i) = d; 74 | risk(i) = r; 75 | end 76 | end -------------------------------------------------------------------------------- /floyd_algo.m: -------------------------------------------------------------------------------- 1 | % 用弗洛伊德算法求邻接矩阵 2 | function matrix = floyd_algo(node, edge) 3 | % node 点集,三列(结点编号,横坐标,纵坐标)的矩阵 4 | % edge 边集,两列(起点,终点)的矩阵 5 | % matrix 邻接矩阵 6 | 7 | node_cnt = size(node, 1); 8 | matrix = create_matrix(node, edge, Inf); 9 | 10 | for k = 1 : node_cnt % 遍历所有中介点 11 | for i = 1 : node_cnt 12 | for j = 1 : node_cnt 13 | if (matrix(i, k) ~= Inf && matrix(k, j) ~= Inf && ... 14 | matrix(i, k) + matrix(k, j) < matrix(i, j)) 15 | matrix(i, j) = matrix(i, k) + matrix(k, j); % 松弛操作 16 | end 17 | end 18 | end 19 | end 20 | end -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | % 用改进后的多目标粒子群优化(MOPSO)算法解决带有风险矩阵的多辆车配送旅行商问题(TSP) 2 | 3 | % -*- coding: utf-8 -*- 4 | % @Time: 2022/02/09 20:57 5 | % @Author: Song Shichao 6 | % @Email: song.shichao@outlook.com 7 | % @Software: Matlab R2015b 8 | % @Platform: Windows11 64x 21H2 9 | % @CPU: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz 2.11 GHz 10 | % @RAM: 16.0 GB 11 | % @Notice: This code is a part of a HUEL master degree project 12 | % under the protection of GPL-3.0-only license. 13 | % @Link: https://github.com/Ki-Seki/MOPSO-for-Distribution 14 | 15 | % 算法特色 16 | % 多目标粒子群优化(MOPSO)、风险矩阵、适应度矩阵、速度与位置的重编码、帕累托前沿 17 | 18 | % 算法的输入与输出 19 | % 输入:在“参设设置”节 20 | % 输出:命令行输出结果、结点网络路径图、结点网络拓扑图、PSO 收敛过程图、每辆车的配送路径图 21 | 22 | % 注意事项 23 | % 结点从 0 开始编号,但是 MATLAB 是从 1 开始编号的; 24 | % TSP 背景下,适应度值即为路径长度、成本等,适应度值越小越好; 25 | % 邻接矩阵、风险矩阵的下标从配送原点(0 号结点)开始算起; 26 | % MOPSO 中群体最优 g_best 也是粒子群,学术上叫做 repository, 27 | % 本情景中输入的全排列是相当离散的数据,因此 repository 大小基本在 10 个以内, 28 | % 所以其帕累托前沿从观感上,不像是一个曲线 29 | 30 | clear; 31 | clc; 32 | close all; 33 | 34 | %% 参数设置 35 | 36 | rand_type = 'state'; % 随机数类型(无须动) 37 | rand_seed = 1; % 随机数种子(无须动) 38 | 39 | dataset = 'c21'; % 数据集名称(本程序所解决的对象,文件必须存在,不包括文件后缀名) 40 | 41 | loop_cnt = 150; % 进化次数(任意正整数,越小越好) 42 | particle_cnt = 200; % 粒子数目(任意正整数,越小越好) 43 | w = 1.5; % 惯性权重(可以不动,值小于 5,越小越好) 44 | c1 = 4; % 自我学习因子(两个学习因子建议相等,值在 1 到 5 之间) 45 | c2 = 4; % 群体学习因子 46 | 47 | graph_option.detail = false; % 是否详细绘图(合法值:true,false) 48 | % 由于绘图量比较大,所以预留 graph_option 为结构体,方便未来增加字段 49 | 50 | %% 初始化 51 | 52 | rand(rand_type, rand_seed); % 随机数生成器初始化 53 | field = read_dataset(dataset); % 读数据集到 field 结构体,它包含数据集中所有字段值 54 | draw_net(field, graph_option); % 绘制结点网络图 55 | 56 | matrix = floyd_algo(field.NODE, field.EDGE); % 用弗洛伊德算法求邻接矩阵 57 | particle = zeros(particle_cnt, field.NODE_COUNT-1); % 创建粒子种群 58 | for i = 1 : particle_cnt 59 | particle(i, :) = randperm(field.NODE_COUNT-1); % 为每个粒子生成随机的路径序列 60 | end 61 | velocity = rands(particle_cnt, field.NODE_COUNT-1); % 初始化粒子速度 62 | 63 | fit = fitness(particle, field, matrix); % 适应度是一个两列(T 和 Z)的矩阵 64 | pf = pareto_front(fit); % 得到当前帕累托前沿解集,是一个逻辑索引 65 | 66 | p_best = particle; % 个体最优对应的粒子群 67 | g_best = particle(pf, :); % 全局最优对应的粒子,pf 是逻辑索引 68 | p_best_fit = fit; % 个体最优值 69 | g_best_fit = fit(pf, :); % 全局最优值 70 | 71 | best_history = zeros(loop_cnt, 2); % 记录迭代:每行包括两目标每次在帕累托前沿中的平均值 72 | convergence = 0; % 结果收敛时的迭代次数 73 | 74 | %% 粒子群算法核心循环 75 | 76 | for i = 1 : loop_cnt 77 | for j = 1 : particle_cnt 78 | %% 计算速度与位置 79 | 80 | v = velocity(j, :); % 当前粒子速度 81 | x = particle(j, :); % 当前粒子位置 82 | 83 | v = w * v + c1 * rand * (p_best(j, :)-x) + c2 * rand * ... 84 | (g_best(randi(size(g_best, 1)), :)-x); % 速度更新公式 85 | x = x + v; % 位置更新公式 86 | 87 | [velocity(j, :), particle(j, :)] = validate(v, x); % 速度与位置冲编码 88 | 89 | %% 更新个体最优 90 | 91 | tmp = fitness(particle(j, :), field, matrix); 92 | if sum(tmp < p_best_fit(j, :)) == 2 % 如果新解是占优的才更新 93 | p_best(j, :) = particle(j, :); 94 | p_best_fit(j, :) = tmp; 95 | end 96 | end 97 | 98 | %% 更新群体最优:策略是把新粒子全部加入后,再求一遍帕累托前沿 99 | g_best = [g_best; p_best]; 100 | g_best_fit = [g_best_fit; p_best_fit]; 101 | 102 | pf = pareto_front(g_best_fit); % 帕累托前沿的逻辑索引 103 | if i == loop_cnt % 仅绘制最后一次的帕累托前沿 104 | draw_pf(g_best_fit, pf, field, graph_option); % 绘制帕累托前沿 105 | end 106 | g_best = g_best(pf, :); 107 | g_best_fit = g_best_fit(pf, :); 108 | 109 | %% 记录迭代 110 | 111 | avg_fit = mean(g_best_fit); 112 | best_history(i, :) = avg_fit; 113 | if i==1 || sum(best_history(i, :) 7 | 8 | mkdir ..\encoded; # 新建与当前文件夹同级的重编码后的文件夹 9 | Get-ChildItem | ForEach-Object -Process{ # 遍历当前文件夹中的所有文件 10 | if($_ -is [System.IO.FileInfo]){ 11 | $new_name = -join ("..\encoded\", $_.name); # 新文件名 12 | & {get-content $_.name -encoding utf8 | set-content $new_name -encoding Default}; # 编码转换为系统默认编码 13 | } 14 | } -------------------------------------------------------------------------------- /read_dataset.m: -------------------------------------------------------------------------------- 1 | % 从 .txt 数据集中读取数据到结构体数组 field 中 2 | function field = read_dataset(dataset) 3 | % dataset 数据集的名称,不含后缀 .txt 4 | % field 返回值,包含提取出来的数据值 5 | 6 | field_name = { % 数据集的各字段名 7 | 'DATASET: ' 8 | 'NODE_COUNT: ' 9 | 'NODE: ' 10 | 'EDGE_COUNT: ' 11 | 'EDGE: ' 12 | 'VEHICLE_COUNT: ' 13 | 'VEHICLE_CAPACITY: ' 14 | 'VEHICLE_SHIPPING_COST: ' 15 | 'VEHICLE_FIXED_COST: ' 16 | 'VEHICLE_DISINFECTION_COST: ' 17 | 'VEHICLE_VELOCITY: ' 18 | 'DEMAND: ' 19 | 'RISK_MATRIX: ' 20 | 'EOF'}; 21 | 22 | datatext = fileread([dataset '.txt']); % 读取数据集文件为字符串 23 | 24 | field.DATASET = extract_value(datatext, field_name, 1); 25 | field.NODE_COUNT = str2num(extract_value(datatext, field_name, 2)); 26 | field.NODE = str2num(extract_value(datatext, field_name, 3)); 27 | field.EDGE_COUNT = str2num(extract_value(datatext, field_name, 4)); 28 | field.EDGE = str2num(extract_value(datatext, field_name, 5)); 29 | field.VEHICLE_COUNT = str2num(extract_value(datatext, field_name, 6)); 30 | field.VEHICLE_CAPACITY = str2num(extract_value(datatext, field_name, 7)); 31 | field.VEHICLE_SHIPPING_COST = str2num(extract_value(datatext, field_name, 8)); 32 | field.VEHICLE_FIXED_COST = str2num(extract_value(datatext, field_name, 9)); 33 | field.VEHICLE_DISINFECTION_COST = str2num(extract_value(datatext, field_name, 10)); 34 | field.VEHICLE_VELOCITY = str2num(extract_value(datatext, field_name, 11)); 35 | field.DEMAND = str2num(extract_value(datatext, field_name, 12)); 36 | field.RISK_MATRIX = str2num(extract_value(datatext, field_name, 13)); 37 | end -------------------------------------------------------------------------------- /reorganize.m: -------------------------------------------------------------------------------- 1 | % 将粒子中多余的和缺失的元素熨平,使其成为一个全排列 2 | function x = reorganize(x) 3 | % x 是一个非法的粒子,其最大最小值确实为全排列里的最值,但中间的元素存在冗余和缺失 4 | % 返回值 x 是一个经过变换后合法的粒子 5 | 6 | %% 判定是否是全排列,如果是,直接返回即可 7 | % 判定定理:n 维全排列的求和与求积值是一定的,且不可能有 n 维非全排列和、积与其相同 8 | 9 | n = numel(x); 10 | if prod(x)==prod(1:n) && sum(x)==sum(1:n) 11 | return; 12 | end 13 | 14 | %% 找多余的和缺失的元素 15 | 16 | dup = []; % 重复出现的元素所在位置 17 | miss = []; % 缺少出现的元素的值 18 | for i = 1 : size(x, 2) 19 | occur = find(x == i); 20 | if size(occur, 2) == 0 % 若缺失 21 | miss = [miss i]; 22 | elseif size(occur, 2) > 1 % 若冗余 23 | dup = [dup occur(2:end)]; 24 | end 25 | end 26 | 27 | %% 将缺失的元素回填至冗余元素出现的位置 28 | 29 | for i = 1 : size(dup, 2) 30 | x(dup(i)) = miss(i); 31 | end 32 | end -------------------------------------------------------------------------------- /test.m: -------------------------------------------------------------------------------- 1 | % 测试程序以 example 数据集为例 2 | 3 | %% 一些先行过程 4 | 5 | clear; 6 | clc; 7 | close all; 8 | dataset = 'test'; % 数据集名称 9 | coeff.t = 0.95; % 目标 T 的权重 10 | coeff.z = 0.05; % 目标 Z 的权重 11 | field = read_dataset(dataset); % 读数据集到 field 结构体,它包含数据集中所有字段值 12 | matrix = floyd_algo(field.NODE, field.EDGE); % 用弗洛伊德算法求邻接矩阵 13 | 14 | %% 暴力搜索方法找到最优解 15 | 16 | all_particle = perms(1:field.NODE_COUNT-1); % 生成所有可能的解 17 | fit = fitness(all_particle, field, matrix); % 适应度是一个两列(T 和 Z)的矩阵 18 | [~, index] = min(weighted(fit, coeff)); % 找群体最优值对应下标 19 | disp(all_particle(index, :)); % 输出最好的粒子 20 | 21 | %% 测试几个适应度相似的粒子 22 | 23 | disp(fitness([1 3 2 5 6 4], field, matrix)) 24 | disp(fitness([1 2 3 5 6 4], field, matrix)) 25 | disp(fitness([3 4 2 5 6 1], field, matrix)) 26 | 27 | %% 测试需要五辆车时,图会不会正常地被画出来 28 | 29 | p = [3,4,6,2,1,5]; % 这个粒子需要 5 辆车 30 | [fit, vehicle, dist, risk] = fitness(p, field, matrix); 31 | draw_distribution(p, vehicle, field); % 绘制最佳配送方案 32 | -------------------------------------------------------------------------------- /validate.m: -------------------------------------------------------------------------------- 1 | % 在 TSP 问题背景下,使 PSO 中的速度与位置合法化,也就是使生成的解是有效解 2 | function [v, x] = validate(v, x) 3 | % v 速度向量 4 | % x 位置向量 5 | 6 | n = size(x, 2); 7 | m = min(x); 8 | M = max(x); 9 | 10 | x_old = round(x - v); % 复原原来位置,为避免浮点数计算影响,加上四舍五入运算 11 | x_new = (n-1) / (M-m) * (x-m) + 1; % 坐标变换:[m, M] → [1, n] 12 | x_new = round(x_new); % 变换为整数 13 | x_new = reorganize(x_new); % 熨平粒子 14 | 15 | v = x_new - x_old; 16 | x = x_new; 17 | end -------------------------------------------------------------------------------- /说明/优化MOPSO算法流程图.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ki-Seki/MOPSO-for-Distribution/fe3e78ca7694f69f0204f99e41772c750f1bb942/说明/优化MOPSO算法流程图.jpeg -------------------------------------------------------------------------------- /说明/优化MOPSO算法流程图.svg: -------------------------------------------------------------------------------- 1 | 开始i ≤ loop_cnt普通 PSO 算法中的速度与位置的更新结束MOPSO初始化:Floyd 算法更新邻接矩阵、计算初始个体最优和群体最优(帕累托前沿)...超参数设置j ≤ particle_cnt使用 validate() 对速度与位置重编码调用 fitness() 计算粒子 j 的适应度 fit新的 fit 更优更新个体最优所有粒子放入同一集合,计算当前帕累托前沿调用 fitness() 计算非支配解集中所有粒子 fit 的平均值新的 fit 更优更新群体最优记录算法迭代、收敛情况输出结果、图 -------------------------------------------------------------------------------- /说明/函数依赖图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ki-Seki/MOPSO-for-Distribution/fe3e78ca7694f69f0204f99e41772c750f1bb942/说明/函数依赖图.png -------------------------------------------------------------------------------- /说明/函数依赖图.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ki-Seki/MOPSO-for-Distribution/fe3e78ca7694f69f0204f99e41772c750f1bb942/说明/函数依赖图.pptx -------------------------------------------------------------------------------- /说明/数据集说明.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ki-Seki/MOPSO-for-Distribution/fe3e78ca7694f69f0204f99e41772c750f1bb942/说明/数据集说明.docx -------------------------------------------------------------------------------- /说明/算法的若干细节.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ki-Seki/MOPSO-for-Distribution/fe3e78ca7694f69f0204f99e41772c750f1bb942/说明/算法的若干细节.docx --------------------------------------------------------------------------------