Skip to main content
Erschienen in:
Buchtitelbild

Open Access 2023 | OriginalPaper | Buchkapitel

12. Codes

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

This chapter gives utility codes used by various procedures presented in the book. It also gives some programs for testing many of the metaheuristics discussed in the book.
Hinweise
Electronic Supplementary Material The online version of this article (https://​doi.​org/​10.​1007/​978-3-031-13714-3_​12) contains supplementary material, which is available to authorized users.
This appendix provides the codes of utility procedures (random number generation, TSP data structures, KD-tree) appearing in various algorithms discussed in this book. Then, several codes are provided for testing complete metaheuristics.
These codes have been simplified in such a way that a user who is not familiar with coding or the use of program libraries can quickly execute them. Their programming style is therefore not so exemplary!

12.1 Random Numbers

Code 12.1 random_generators.py Implementation of a pseudo-random generator due to l’Ecuyer [1] as well as utility functions to generate integers between two bounds, random permutations and random symmetric matrices
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaaa_HTML.png

12.2 TSP Utilities

Code 12.2 tsp_utilities.py Utility functions for the traveling salesman: computation of the length of a tour when a solution is provided in the form of an array giving the order in which the cities are visited; transformation of a solution from one form to another (order, successors, predecessors); comparison of tours
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaab_HTML.png
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaac_HTML.png

12.3 TSP Lin and Kernighan Improvement Procedure

Code 12.3 tsp_ LK.pyEjection chain for the TSP
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaad_HTML.png
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaae_HTML.png

12.4 KD-Tree Insertion and Inspection

Code 12.4 kd_tree_add_scan.pyCodes to define the general structure of the nodes of a KD-tree, to add an element to a KD-tree, and to inspect the whole tree. The inspection procedure just prints out the elements
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaaf_HTML.png

12.5 KD-Tree Delete

Code 12.5 kd_tree_delete.pyCode for removing a node in a KD-tree
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaag_HTML.png

12.6 KD-Tree Update Pareto Set

Code 12.6 kd_tree_update_pareto.pyCode for updating a Pareto set represented by a KD-tree
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaah_HTML.png
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaai_HTML.png

12.7 TSP 2-Opt and 3-Opt Test Program

Code 12.7 test_tsp_2_and_3opt.pyThis code first generates a symmetric matrix with random distances and starts with a random solution. The latter is improved with a local search applying the first-move improving policy with the 2-opt neighborhood. This method is relatively rapid for instances with up to a few thousand cities. Then, all sub-paths of 100 successive cities in this solution are improved with a 3-opt neighborhood. This method runs in almost linear time, but only produces good solutions if the starting solution is adequate. The solution is then improved with a full 3-opt neighborhood. Its complexity is considerably higher; the computational time becomes significant beyond a few hundred cities. Ultimately, the solution is improved with the 2-opt neighborhood, but applying the best move policy at each iteration
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaaj_HTML.png
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaak_HTML.png

12.8 Multi-objective TSP Test Program

Code 12.8 test_tsp_3opt_pareto.py A program for testing a local Pareto search for a TSP with a randomly generated distance matrix. For a 20-city and 3-objective instance, this program generates an approximation to the Pareto set with more than 3000 solutions. Since the implementation is highly recursive, the recursion stack and console user limits must be appropriately resized
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaal_HTML.png

12.9 Fast Ant TSP Test Program

Code 12.9 test_tsp_FANT.pyProgram to test a method inspired by artificial ant colonies
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaam_HTML.png

12.10 Taboo Search TSP Test Program

Code 12.10 test_tsp_TS.pyA taboo search test program for a TSP with a randomly generated symmetric distance matrix
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaan_HTML.png
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaao_HTML.png

12.11 Memetic TSP Test Program

Code 12.11 test_tsp_GA.pyA memetic algorithm test program for a TSP with a randomly generated symmetric distance matrix
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaap_HTML.png

12.12 GRASP with Path Relinking TSP Test Program

Code 12.12 test_tsp_GRASP_PR.pyA GRASP with path relinking test program. This method uses GRASP which calls for a local search based on ejection chains, as well as other utility functions
https://static-content.springer.com/image/chp%3A10.1007%2F978-3-031-13714-3_12/MediaObjects/522503_1_En_12_Figaaq_HTML.png
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://​creativecommons.​org/​licenses/​by/​4.​0/​), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Metadaten
Titel
Codes
verfasst von
Éric D. Taillard
Copyright-Jahr
2023
DOI
https://doi.org/10.1007/978-3-031-13714-3_12

Premium Partner