├── .codecov.yml ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── brkga_mp_ipr ├── __init__.py ├── algorithm.py ├── enums.py ├── exceptions.py ├── types.py └── types_io.py ├── docs ├── .buildinfo ├── .doctrees │ ├── api.doctree │ ├── brkga_mp_ipr.algorithm.doctree │ ├── brkga_mp_ipr.doctree │ ├── brkga_mp_ipr.enums.doctree │ ├── brkga_mp_ipr.exceptions.doctree │ ├── brkga_mp_ipr.types.doctree │ ├── brkga_mp_ipr.types_io.doctree │ ├── environment.pickle │ ├── index.doctree │ ├── modules.doctree │ ├── page_guide.doctree │ ├── page_license.doctree │ ├── page_md_src_contributing.doctree │ └── page_todo.doctree ├── .nojekyll ├── _modules │ ├── brkga_mp_ipr │ │ ├── algorithm.html │ │ ├── enums.html │ │ ├── exceptions.html │ │ ├── types.html │ │ └── types_io.html │ └── index.html ├── _sources │ ├── api.rst.txt │ ├── brkga_mp_ipr.algorithm.rst.txt │ ├── brkga_mp_ipr.enums.rst.txt │ ├── brkga_mp_ipr.exceptions.rst.txt │ ├── brkga_mp_ipr.rst.txt │ ├── brkga_mp_ipr.types.rst.txt │ ├── brkga_mp_ipr.types_io.rst.txt │ ├── index.rst.txt │ ├── modules.rst.txt │ ├── page_guide.rst.txt │ ├── page_license.rst.txt │ ├── page_md_src_contributing.rst.txt │ └── page_todo.rst.txt ├── _static │ ├── add_target.js │ ├── basic.css │ ├── css │ │ ├── badge_only.css │ │ └── theme.css │ ├── custom_theme.css │ ├── doctools.js │ ├── documentation_options.js │ ├── favicon.ico │ ├── file.png │ ├── fonts │ │ ├── Inconsolata-Bold.ttf │ │ ├── Inconsolata-Regular.ttf │ │ ├── Inconsolata.ttf │ │ ├── Lato-Bold.ttf │ │ ├── Lato-Regular.ttf │ │ ├── Lato │ │ │ ├── lato-bold.eot │ │ │ ├── lato-bold.ttf │ │ │ ├── lato-bold.woff │ │ │ ├── lato-bold.woff2 │ │ │ ├── lato-bolditalic.eot │ │ │ ├── lato-bolditalic.ttf │ │ │ ├── lato-bolditalic.woff │ │ │ ├── lato-bolditalic.woff2 │ │ │ ├── lato-italic.eot │ │ │ ├── lato-italic.ttf │ │ │ ├── lato-italic.woff │ │ │ ├── lato-italic.woff2 │ │ │ ├── lato-regular.eot │ │ │ ├── lato-regular.ttf │ │ │ ├── lato-regular.woff │ │ │ └── lato-regular.woff2 │ │ ├── RobotoSlab-Bold.ttf │ │ ├── RobotoSlab-Regular.ttf │ │ ├── RobotoSlab │ │ │ ├── roboto-slab-v7-bold.eot │ │ │ ├── roboto-slab-v7-bold.ttf │ │ │ ├── roboto-slab-v7-bold.woff │ │ │ ├── roboto-slab-v7-bold.woff2 │ │ │ ├── roboto-slab-v7-regular.eot │ │ │ ├── roboto-slab-v7-regular.ttf │ │ │ ├── roboto-slab-v7-regular.woff │ │ │ └── roboto-slab-v7-regular.woff2 │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont.woff │ │ └── fontawesome-webfont.woff2 │ ├── jquery-3.4.1.js │ ├── jquery.js │ ├── js │ │ ├── modernizr.min.js │ │ └── theme.js │ ├── language_data.js │ ├── logo.png │ ├── logo_name_150.png │ ├── logo_name_300.png │ ├── logo_name_600.png │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── underscore-1.3.1.js │ └── underscore.js ├── api.html ├── brkga_mp_ipr.algorithm.html ├── brkga_mp_ipr.enums.html ├── brkga_mp_ipr.exceptions.html ├── brkga_mp_ipr.html ├── brkga_mp_ipr.types.html ├── brkga_mp_ipr.types_io.html ├── genindex.html ├── index.html ├── modules.html ├── objects.inv ├── page_guide.html ├── page_license.html ├── page_md_src_contributing.html ├── page_todo.html ├── py-modindex.html ├── search.html └── searchindex.js ├── examples └── tsp │ ├── config.conf │ ├── greedy_tour.py │ ├── instances │ ├── brazil58.dat │ ├── burma14.dat │ ├── rd400.dat │ └── vm1084.dat │ ├── main_complete.py │ ├── main_minimal.py │ ├── tsp_decoder.py │ └── tsp_instance.py ├── pylintrc ├── setup.py ├── src_docs ├── Makefile └── src │ ├── assets │ ├── favicon.ico │ ├── logo.png │ ├── logo_name_150.png │ ├── logo_name_300.png │ └── logo_name_600.png │ └── rst │ ├── _static │ ├── add_target.js │ └── custom_theme.css │ ├── api.rst │ ├── brkga_mp_ipr.algorithm.rst │ ├── brkga_mp_ipr.enums.rst │ ├── brkga_mp_ipr.exceptions.rst │ ├── brkga_mp_ipr.rst │ ├── brkga_mp_ipr.types.rst │ ├── brkga_mp_ipr.types_io.rst │ ├── conf.py │ ├── index.rst │ ├── modules.rst │ ├── page_guide.rst │ ├── page_index.rst │ ├── page_license.rst │ ├── page_md_src_contributing.rst │ └── page_todo.rst ├── tests ├── __init__.py ├── create_mock_brkga_data.py ├── decoders.py ├── instance.py ├── paths_constants.py ├── resources │ ├── configuration_files │ │ ├── custom_bias_function.conf │ │ ├── empty.conf │ │ ├── missing_param.conf │ │ ├── missing_value.conf │ │ ├── regular.conf │ │ ├── unknown_param.conf │ │ ├── wrong_bias_function.conf │ │ ├── wrong_pr_selection.conf │ │ ├── wrong_pr_type.conf │ │ └── wrong_type.conf │ ├── solutions │ │ ├── best_solution1.pickle │ │ ├── best_solution2.pickle │ │ ├── best_solution3.pickle │ │ ├── best_solution4.pickle │ │ └── best_solution5.pickle │ └── states │ │ ├── state1.pickle │ │ ├── state2.pickle │ │ ├── state3.pickle │ │ ├── state4.pickle │ │ └── state5.pickle ├── test_0_enums.py ├── test_1_types.py ├── test_2_types_io.py ├── test_3_algorithm_initialization.py ├── test_4_algorithm_support_methods.py ├── test_5_algorithm_population_manipulation.py ├── test_6_algorithm_evolutionary_methods.py └── test_7_algorithm_path_relink_methods.py └── tox.ini /.codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Documentation: http://docs.travis-ci.com/user/languages/python/ 2 | language: python 3 | # os: 4 | # - linux 5 | # - osx 6 | # # - windows 7 | 8 | python: 9 | - 3.7.5 10 | 11 | notifications: 12 | email: false 13 | 14 | install: 15 | - pip3 install --upgrade pip 16 | - pip3 install pytest pytest-cov tox tox-travis coveralls codecov dill 17 | 18 | script: tox 19 | 20 | after_success: 21 | - coveralls 22 | - codecov 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ======================= 3 | 4 | Although the code is an experimental one, we aim to write an efficient and 5 | consistent code. So, you should keep in mind the balance between memory 6 | utilization and code efficiency and pay special attention to cache utilization. 7 | 8 | Style 9 | ----------------------- 10 | 11 | Please, follow the general [PEP8 coding style](https://pep8.org). Since it is 12 | too long to describe all details here, study the code already written. 13 | However, in general, 14 | 15 | - Name classes, methods, and variables as clear and meaningful as possible; 16 | 17 | - Write short commentaries on the code flow to reading more accessible and 18 | faster; 19 | 20 | - Properly document the code, especially the data structures and methods 21 | definitions. Do not forget to link/refer them; 22 | 23 | - All classes, attributes, methods, functions, and so must have type 24 | annotations. The user must be able to know exactly what kind of objects 25 | he/she is dealing with. Use the `typing` package, and use `from __future__ 26 | import annotations`; 27 | 28 | - No trailing spaces, no tabs, Unix/POSIX end of line. Try to keep line 29 | within 80 columns and do not exceed 90 columns; 30 | 31 | - We encourage the use of Python f-strings where the make the code easier to 32 | read; 33 | 34 | - Use section separations (sequence of `#`), for clarity, especially into 35 | BrkgaMpIpr class. This class has lots of long methods, which can be 36 | categorized into different groups of functionality. 37 | 38 | - Do not use system specific code/headers. Your code must compile in several 39 | systems with minimum change; 40 | 41 | - All submissions will need to pass the "pylint" test using the supplied 42 | `pylintrc` file. Note that this file is pretty generic, but it may be 43 | changed in the future; 44 | 45 | - Make sure that, for each method/function, you write unit tests that cover 46 | all corner cases, and few regular cases (> 1); 47 | 48 | - New code without proper unit tests will not be merged; 49 | 50 | - Do not commit or do a pull request until the code pass in all tests. 51 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BRKGA-MP-IPR License 2 | ======================== 3 | 4 | Copyright (c) 2019, Carlos Eduardo de Andrade. All other rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are only permitted provided that the following conditions are 8 | met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | 3. Neither the name of the copyright holder nor the names of its contributors 18 | may be used to endorse or promote products derived from this software 19 | without specific prior written permission. 20 | 21 | 4. All publications, softwares, or any other materials mentioning features or 22 | use of this software (as a whole package or any parts of it) and/or the data 23 | used to test it must cite the following article explicitly: 24 | 25 | > C.E. Andrade. R.F. Toso, J.F. Gonçalves, M.G.C. Resende. The Multi-Parent 26 | > Biased Random-key Genetic Algorithm with Implicit Path Relinking. _European 27 | > Journal of Operational Research_, volume 289, number 1, pages 17–30, 2021. 28 | > DOI https://doi.org/10.1016/j.ejor.2019.11.037 29 | 30 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 31 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 32 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 33 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 34 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 36 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 38 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | -------------------------------------------------------------------------------- /brkga_mp_ipr/__init__.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # brkga_mp_ipr package Version 0.1 - Nov 21, 2019 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 05, 2019 by ceandrade 9 | # Last update: Nov 21, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | """ 24 | This package provides a very easy-to-use framework for the Multi-Parent 25 | Biased Random-Key Genetic Algorithm with Implict Path Relink (BRKGA-MP-IPR). 26 | Assuming that your have a decoder to your problem, we can setup, run, and 27 | extract the value of the best solution in less than 5 commands (obvisiously, 28 | you may need few other lines fo code to do a proper test). 29 | """ 30 | 31 | __all__ = [ 32 | "enums", 33 | "exceptions", 34 | "types", 35 | "types_io", 36 | "algorithm" 37 | ] 38 | -------------------------------------------------------------------------------- /brkga_mp_ipr/enums.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # enums.py: Definitions of useful enumerations. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 05, 2019 by ceandrade 9 | # Last update: Nov 09, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | from enum import Enum, Flag, unique 25 | 26 | ############################################################################### 27 | # Enumerations 28 | ############################################################################### 29 | 30 | class ParsingEnum(Enum): 31 | """ 32 | Implements a base Enum class that returns an Enum object from a string 33 | (case insensitive). 34 | """ 35 | 36 | @classmethod 37 | def _missing_(cls, name): 38 | """ 39 | When the constructor cannot find the attribute, it calls this 40 | function. Then, we check if the string of the given name/object is in 41 | the attribute list of the Enum. If so, we return the attribute. 42 | """ 43 | for member in cls: 44 | if member.name.upper() == str(name).upper(): 45 | return member 46 | return None 47 | 48 | def __str__(self): 49 | """ 50 | Just return the name instead of . 51 | """ 52 | return self.name 53 | 54 | ############################################################################### 55 | 56 | @unique 57 | class Sense(ParsingEnum): 58 | """ 59 | Tells the algorithm either to ``MINIMIZE`` or ``MAXIMIZE`` the 60 | objective function. 61 | """ 62 | MINIMIZE = 0 63 | MAXIMIZE = 1 64 | 65 | ############################################################################### 66 | 67 | @unique 68 | class BiasFunctionType(ParsingEnum): 69 | r""" 70 | Specifies a bias function when choosing parents to mating. This function 71 | substitutes the :math:`\rho` (rho) parameter from the original BRKGA. 72 | For a given rank :math:`r`, we have the following functions: 73 | 74 | - ``CONSTANT``: 1 / number of parents for mating (all individuals have the 75 | same probability) 76 | 77 | - ``CUBIC``: :math:`r^{-3}` 78 | 79 | - ``EXPONENTIAL``: :math:`\epsilon^{-r}` 80 | 81 | - ``LINEAR``: :math:`1 / r` 82 | 83 | - ``LOGINVERSE``: :math:`1 / \log(r + 1)` 84 | 85 | - ``QUADRATIC``: :math:`r^{-2}` 86 | """ 87 | CONSTANT = 0 88 | CUBIC = 1 89 | EXPONENTIAL = 2 90 | LINEAR = 3 91 | LOGINVERSE = 4 92 | QUADRATIC = 5 93 | CUSTOM = 6 94 | 95 | ############################################################################### 96 | 97 | @unique 98 | class PathRelinkingType(ParsingEnum): 99 | """ 100 | Specifies type of path relinking: 101 | 102 | - ``DIRECT``: changes each key for the correspondent in the other 103 | chromosome. 104 | 105 | - ``PERMUTATION``: switches the order of a key for that in the other 106 | chromosome. 107 | """ 108 | DIRECT = 0 109 | PERMUTATION = 1 110 | 111 | ############################################################################### 112 | 113 | @unique 114 | class PathRelinkingSelection(ParsingEnum): 115 | """ 116 | Specifies which individuals used to build the path: 117 | 118 | - ``BESTSOLUTION``: selects, in the order, the best solution of each 119 | population. 120 | 121 | - ``RANDOMELITE``: chooses uniformly random solutions from the elite sets. 122 | """ 123 | BESTSOLUTION = 0 124 | RANDOMELITE = 1 125 | 126 | ############################################################################### 127 | 128 | @unique 129 | class PathRelinkingResult(Flag): 130 | """ 131 | Specifies the result type/status of path relink procedure: 132 | 133 | - ``TOO_HOMOGENEOUS``: the chromosomes among the populations are too 134 | homogeneous and the path relink will not generate improveded solutions. 135 | 136 | - ``NO_IMPROVEMENT``: path relink was done but no improveded solution was 137 | found. 138 | 139 | - ``ELITE_IMPROVEMENT``: an improved solution among the elite set was 140 | found, but the best solution was not improved. 141 | 142 | - ``BEST_IMPROVEMENT``: the best solution was improved. 143 | """ 144 | TOO_HOMOGENEOUS = 0 145 | NO_IMPROVEMENT = 1 146 | ELITE_IMPROVEMENT = 3 147 | BEST_IMPROVEMENT = 7 148 | 149 | ################################################################################ 150 | 151 | @unique 152 | class ShakingType(ParsingEnum): 153 | """ 154 | Specifies the type of shaking to be performed. 155 | 156 | - ``CHANGE``: applies the following perturbations: 157 | 1) Inverts the value of a random chosen, i.e., from :math:`value` to 158 | :math:`1 - value`; 159 | 2) Assigns a random value to a random key. 160 | 161 | - ``SWAP``: applies two swap perturbations: 162 | 1) Swaps the values of a randomly chosen key :math:`i` and its 163 | neighbor :math:`i + 1`; 164 | 2) Swaps values of two randomly chosen keys. 165 | """ 166 | CHANGE = 0 167 | SWAP = 1 168 | -------------------------------------------------------------------------------- /brkga_mp_ipr/exceptions.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # exceptions.py: Definitions BRKGA exceptions. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 07, 2019 by ceandrade 9 | # Last update: Nov 07, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | class LoadError(RuntimeError): 25 | """ 26 | Specifies an error while reading a configuration file. 27 | """ 28 | -------------------------------------------------------------------------------- /brkga_mp_ipr/types.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # types.py: Definitions of internal data structures and external API. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 05, 2019 by ceandrade 9 | # Last update: Nov 08, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | from __future__ import annotations 25 | import copy 26 | 27 | from brkga_mp_ipr.enums import BiasFunctionType, PathRelinkingType, \ 28 | PathRelinkingSelection 29 | 30 | ############################################################################### 31 | 32 | class BrkgaParams: 33 | """ 34 | Represents the BRKGA and IPR hyper-parameters. 35 | 36 | Attributes: 37 | ** BRKGA Hyper-parameters ** 38 | 39 | population_size (int): Number of elements in the population [> 0]. 40 | 41 | elite_percentage (float): Percentage of individuals to become the 42 | elite set (0, 1]. 43 | 44 | mutants_percentage (float): Percentage of mutants to be inserted in 45 | the population. 46 | 47 | num_elite_parents (int): Number of elite parents for mating [> 0]. 48 | 49 | total_parents (int): Number of total parents for mating [> 0]. 50 | 51 | bias_type (BiasFunction): Type of bias that will be used. 52 | 53 | num_independent_populations (int): Number of independent parallel 54 | populations. 55 | 56 | **Path Relinking parameters** 57 | 58 | pr_number_pairs (int): Number of pairs of chromosomes to be tested 59 | to path relinking. 60 | 61 | pr_minimum_distance (float): Mininum distance between chromosomes 62 | selected to path-relinking. 63 | 64 | pr_type (PathRelinkingType): Path relinking type. 65 | pr_selection (PathRelinkingSelection): Individual selection to 66 | path-relinking. 67 | 68 | alpha_block_size (float): Defines the block size based on the size of 69 | the population. 70 | 71 | pr_percentage (float): Percentage / path size to be computed. 72 | Value in (0, 1]. 73 | """ 74 | 75 | def __init__(self): 76 | """ 77 | Initializes a BrkgaParams object. 78 | """ 79 | self.population_size = 0 80 | self.elite_percentage = 0.0 81 | self.mutants_percentage = 0.0 82 | self.num_elite_parents = 0 83 | self.total_parents = 0 84 | self.bias_type = BiasFunctionType.CONSTANT 85 | self.num_independent_populations = 0 86 | self.pr_number_pairs = 0 87 | self.pr_minimum_distance = 0.0 88 | self.pr_type = PathRelinkingType.DIRECT 89 | self.pr_selection = PathRelinkingSelection.BESTSOLUTION 90 | self.alpha_block_size = 0.0 91 | self.pr_percentage = 0.0 92 | 93 | ############################################################################### 94 | 95 | class ExternalControlParams: 96 | """ 97 | Represents additional control parameters that can be used outside this 98 | framework. 99 | 100 | Attributes: 101 | exchange_interval (int): Interval at which elite chromosomes are 102 | exchanged (0 means no exchange) [> 0]. 103 | 104 | num_exchange_indivuduals (int): Number of elite chromosomes exchanged 105 | from each population [> 0]. 106 | 107 | reset_interval (int): Interval at which the populations are reset 108 | (0 means no reset) [> 0]. 109 | """ 110 | 111 | def __init__(self, exchange_interval: int = 0, 112 | num_exchange_indivuduals: int = 0, 113 | reset_interval: int = 0): 114 | """ 115 | Initializes a ExternalControlParams object. 116 | """ 117 | self.exchange_interval = exchange_interval 118 | self.num_exchange_indivuduals = num_exchange_indivuduals 119 | self.reset_interval = reset_interval 120 | 121 | ############################################################################### 122 | 123 | class BaseChromosome(list): 124 | """ 125 | This class represents a chromosome using a vector in the unitary 126 | hypercube, i.e., :math:`v \\in [0,1]^n` where :math:`n` is the size of the 127 | array (dimensions of the hypercube). 128 | 129 | Note that this base class is a simple list of float numbers and can be 130 | used in the algorithm directly. However, in some cases, the user wants 131 | additional capabilities in the Chromosome class, such as extra data and 132 | so. For instance, in the example below, the chromosome also keeps the 133 | makespan and total completion time for a scheduling problem: 134 | 135 | .. code-block:: python 136 | 137 | class SchedulingChromosome(BaseChromosome): 138 | def __init__(self, value): 139 | super().__init__(value) 140 | self.makespan = 0.0 141 | self.total_completion_time = 0.0 142 | 143 | Note that when subclassing BaseChromosome, we must define the method 144 | ``__init__(self, value)`` and call the parent (``BaseChromosome``) 145 | constructor. We need at least one argument to be passed to 146 | ``BaseChromosome`` constructor. 147 | """ 148 | 149 | ############################################################################### 150 | 151 | class Population(): 152 | """ 153 | Encapsulates a population of chromosomes. Note that this struct is **NOT** 154 | meant to be used externally of this unit. 155 | 156 | Attributes: 157 | chromosomes (List[BaseChromosome]): Population of chromosomes. 158 | 159 | fitness (List[Tuple[float, int]]): Fitness of a each chromosome. 160 | Each pair represents the fitness and the chromosome index. 161 | """ 162 | 163 | def __init__(self, other_population: Population = None): 164 | """ 165 | Initializes a new population. If ``other_population`` is not ``None``, 166 | we copy it. 167 | 168 | Args: 169 | other_population (Population): The population to be copied. 170 | """ 171 | 172 | self.chromosomes = list() 173 | self.fitness = list() 174 | 175 | if other_population is not None: 176 | self.chromosomes = copy.deepcopy(other_population.chromosomes) 177 | self.fitness = copy.deepcopy(other_population.fitness) 178 | -------------------------------------------------------------------------------- /brkga_mp_ipr/types_io.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # types_io.py: I/O functions for parameters (types). 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 06, 2019 by ceandrade 9 | # Last update: Nov 07, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | from itertools import chain 25 | 26 | from brkga_mp_ipr.types import BrkgaParams, ExternalControlParams 27 | from brkga_mp_ipr.exceptions import LoadError 28 | 29 | ############################################################################### 30 | 31 | def load_configuration(configuration_file: str) -> \ 32 | (BrkgaParams, ExternalControlParams): 33 | """ 34 | Loads the parameters from `configuration_file` returning them as a tuple. 35 | 36 | Args: 37 | configuration_file (str): plain text file containing the configuration. 38 | 39 | Returns: 40 | A tuple containing a `BrkgaParams` and a `ExternalControlParams` object. 41 | 42 | Raises: 43 | IsADirectoryError: If `configuration_file` is a folder. 44 | 45 | FileNotFoundError: If `configuration_file` does not exist. 46 | 47 | LoadError: In cases of missing data or bad-formatted data. 48 | """ 49 | 50 | brkga_params = BrkgaParams() 51 | control_params = ExternalControlParams() 52 | 53 | param_names_types = { 54 | name: type(value) 55 | for name, value in chain(vars(brkga_params).items(), 56 | vars(control_params).items()) 57 | } 58 | 59 | param_given = {name: False for name in param_names_types.keys()} 60 | 61 | with open(configuration_file) as hd: 62 | lines = hd.readlines() 63 | 64 | if not lines: 65 | raise LoadError(f"Cannot read {configuration_file}") 66 | 67 | for (line_number, line) in enumerate(lines): 68 | line = line.strip() 69 | if len(line) == 0 or line[0] == '#': 70 | continue 71 | 72 | param_name = None 73 | value = None 74 | 75 | try: 76 | param_name, value = [x.strip().lower() for x in line.split()] 77 | except ValueError: 78 | raise LoadError(f"Line {line_number}: " 79 | f"missing parameter or value") 80 | 81 | if param_name in vars(brkga_params): 82 | data = brkga_params 83 | elif param_name in vars(control_params): 84 | data = control_params 85 | else: 86 | raise LoadError(f"Line {line_number}: " 87 | f"parameter '{param_name}' unknown") 88 | try: 89 | setattr(data, param_name, param_names_types[param_name](value)) 90 | param_given[param_name] = True 91 | except ValueError: 92 | raise LoadError(f"Line {line_number}: " 93 | f"invalid value for '{param_name}': {value}") 94 | # end for 95 | 96 | missing_params = [] 97 | for name, value in param_given.items(): 98 | if not value: 99 | missing_params.append(name) 100 | 101 | if missing_params: 102 | missing_params = ", ".join(missing_params) 103 | raise LoadError(f"Missing parameters: {missing_params}") 104 | 105 | return (brkga_params, control_params) 106 | 107 | ############################################################################### 108 | 109 | def write_configuration(filename: str, brkga_params: BrkgaParams, 110 | external_params: ExternalControlParams) -> None: 111 | """ 112 | Writes `brkga_params` and `external_params` into `filename`. 113 | 114 | Args: 115 | filename (str): A file where the configuration will be written. 116 | 117 | brkga_params (BrkgaParams): The BRKGA-MP-IPR parameters. 118 | 119 | external_params (ExternalControlParams): The control parameters. 120 | 121 | Raises: 122 | IsADirectoryError: If `filename` is a folder. 123 | 124 | PermissionError: If we cannot write into the file. 125 | """ 126 | 127 | output_string = "" 128 | 129 | for name, value in vars(brkga_params).items(): 130 | output_string += f"{name} {value}\n" 131 | 132 | for name, value in vars(external_params).items(): 133 | output_string += f"{name} {value}\n" 134 | 135 | with open(filename, "w") as hd: 136 | hd.write(output_string) 137 | -------------------------------------------------------------------------------- /docs/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 583086671c0fcd9cc29a49b57abef0a9 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/.doctrees/api.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/api.doctree -------------------------------------------------------------------------------- /docs/.doctrees/brkga_mp_ipr.algorithm.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/brkga_mp_ipr.algorithm.doctree -------------------------------------------------------------------------------- /docs/.doctrees/brkga_mp_ipr.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/brkga_mp_ipr.doctree -------------------------------------------------------------------------------- /docs/.doctrees/brkga_mp_ipr.enums.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/brkga_mp_ipr.enums.doctree -------------------------------------------------------------------------------- /docs/.doctrees/brkga_mp_ipr.exceptions.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/brkga_mp_ipr.exceptions.doctree -------------------------------------------------------------------------------- /docs/.doctrees/brkga_mp_ipr.types.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/brkga_mp_ipr.types.doctree -------------------------------------------------------------------------------- /docs/.doctrees/brkga_mp_ipr.types_io.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/brkga_mp_ipr.types_io.doctree -------------------------------------------------------------------------------- /docs/.doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/.doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/index.doctree -------------------------------------------------------------------------------- /docs/.doctrees/modules.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/modules.doctree -------------------------------------------------------------------------------- /docs/.doctrees/page_guide.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/page_guide.doctree -------------------------------------------------------------------------------- /docs/.doctrees/page_license.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/page_license.doctree -------------------------------------------------------------------------------- /docs/.doctrees/page_md_src_contributing.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/page_md_src_contributing.doctree -------------------------------------------------------------------------------- /docs/.doctrees/page_todo.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.doctrees/page_todo.doctree -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/.nojekyll -------------------------------------------------------------------------------- /docs/_modules/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Overview: module code — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 104 | 105 |
106 | 107 | 108 | 114 | 115 | 116 |
117 | 118 |
119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |
137 | 138 |
    139 | 140 |
  • Docs »
  • 141 | 142 |
  • Overview: module code
  • 143 | 144 | 145 |
  • 146 | 147 |
  • 148 | 149 |
150 | 151 | 152 |
153 |
154 |
155 |
156 | 157 |

All modules for which code is available

158 | 164 | 165 |
166 | 167 |
168 |
169 | 170 | 171 |
172 | 173 |
174 |

175 | © Copyright 2019, Carlos E. Andrade 176 | 177 |

178 |
179 | Built with Sphinx using a theme provided by Read the Docs. 180 | 181 |
182 | 183 |
184 |
185 | 186 |
187 | 188 |
189 | 190 | 191 | 192 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /docs/_sources/api.rst.txt: -------------------------------------------------------------------------------- 1 | API 2 | ============ 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | brkga_mp_ipr 8 | -------------------------------------------------------------------------------- /docs/_sources/brkga_mp_ipr.algorithm.rst.txt: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.algorithm module 2 | =============================== 3 | 4 | .. automodule:: brkga_mp_ipr.algorithm 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/brkga_mp_ipr.enums.rst.txt: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.enums module 2 | =========================== 3 | 4 | .. automodule:: brkga_mp_ipr.enums 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/brkga_mp_ipr.exceptions.rst.txt: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.exceptions module 2 | ================================ 3 | 4 | .. automodule:: brkga_mp_ipr.exceptions 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/brkga_mp_ipr.rst.txt: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr package 2 | ====================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | brkga_mp_ipr.algorithm 11 | brkga_mp_ipr.enums 12 | brkga_mp_ipr.exceptions 13 | brkga_mp_ipr.types 14 | brkga_mp_ipr.types_io 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: brkga_mp_ipr 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /docs/_sources/brkga_mp_ipr.types.rst.txt: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.types module 2 | =========================== 3 | 4 | .. automodule:: brkga_mp_ipr.types 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/brkga_mp_ipr.types_io.rst.txt: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.types\_io module 2 | =============================== 3 | 4 | .. automodule:: brkga_mp_ipr.types_io 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. include:: page_index.rst 2 | 3 | .. toctree:: 4 | :hidden: 5 | 6 | page_guide.rst 7 | page_license.rst 8 | page_todo.rst 9 | page_md_src_contributing.rst 10 | 11 | Related Pages 12 | ------------------------------------------------------------------------------- 13 | 14 | | :doc:`page_guide` 15 | | :doc:`page_todo` 16 | | :doc:`page_md_src_contributing` 17 | 18 | 19 | Reference and Index 20 | ------------------------------------------------------------------------------- 21 | 22 | .. toctree:: 23 | :hidden: 24 | 25 | api.rst 26 | 27 | | :doc:`api` 28 | | :ref:`genindex` 29 | 30 | -------------------------------------------------------------------------------- /docs/_sources/modules.rst.txt: -------------------------------------------------------------------------------- 1 | brkga_mp_ipr 2 | ============ 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | brkga_mp_ipr 8 | -------------------------------------------------------------------------------- /docs/_sources/page_license.rst.txt: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; License 2 | .. _doxid-page_license: 3 | 4 | BRKGA-MP-IPR License 5 | ================================================================================ 6 | 7 | Copyright (c) 2019, Carlos Eduardo de Andrade. All other rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are only permitted provided that the following conditions are 11 | met: 12 | 13 | 1. Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | 3. Neither the name of the copyright holder nor the names of its contributors 21 | may be used to endorse or promote products derived from this software 22 | without specific prior written permission. 23 | 24 | 4. All publications, softwares, or any other materials mentioning features or 25 | use of this software (as a whole package or any parts of it) and/or the data 26 | used to test it must cite the following article explicitly: 27 | 28 | C.E. Andrade. R.F. Toso, J.F. Gonçalves, M.G.C. Resende. The Multi-Parent 29 | Biased Random-key Genetic Algorithm with Implicit Path Relinking. *European 30 | Journal of Operational Research*, volume 289, number 1, pages 17–30, 2021. 31 | DOI `10.1016/j.ejor.2019.11.037 `_ 32 | 33 | 34 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 35 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 36 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | -------------------------------------------------------------------------------- /docs/_sources/page_md_src_contributing.rst.txt: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; Contributing 2 | .. _doxid-md_src_contributing: 3 | 4 | Contributing 5 | =============================================================================== 6 | 7 | Although the code is an experimental one, we aim to write an efficient and 8 | consistent code. So, you should keep in mind the balance between memory 9 | utilization and code efficiency and pay special attention to cache utilization. 10 | 11 | Style 12 | ------------------------------------------------------------------------------- 13 | 14 | Please, follow the general `PEP8 coding style `_. Since it is 15 | too long to describe all details here, study the code already written. 16 | However, in general: 17 | 18 | * Name classes, methods, and variables as clear and meaningful as possible; 19 | 20 | * Write short commentaries on the code flow to reading more accessible and 21 | faster; 22 | 23 | * Properly document the code, especially the data structures and methods 24 | definitions. Do not forget to link/refer them; 25 | 26 | * All classes, attributes, methods, functions, and so must have type 27 | annotations. The user must be able to know exactly what kind of objects 28 | he/she is dealing with. Use the ``typing`` package, and use ``from __future__ 29 | import annotations``; 30 | 31 | * No trailing spaces,kd no tabs, Unix/POSIX end of line. Try to keep line 32 | within 80 columns and do not exceed 90 columns; 33 | 34 | * We encourage the use of Python f-strings where the make the code easier to 35 | read; 36 | 37 | * Use section separations (sequence of `#`), for clarity, especially into 38 | BrkgaMpIpr class. This class has lots of long methods, which can be 39 | categorized into different groups of functionality. 40 | 41 | * Do not use system specific code/headers. Your code must compile in several 42 | systems with minimum change; 43 | 44 | * All submissions will need to pass the "pylint" test using the supplied 45 | ``pylintrc`` file. Note that this file is pretty generic, but it may be 46 | changed in the future; 47 | 48 | * Make sure that, for each method/function, you write unit tests that cover 49 | all corner cases, and few regular cases (> 1); 50 | 51 | * New code without proper unit tests will not be merged; 52 | 53 | * Do not commit or do a pull request until the code pass in all tests. 54 | 55 | -------------------------------------------------------------------------------- /docs/_sources/page_todo.rst.txt: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; Todo List 2 | .. _doxid-todo: 3 | 4 | Todo List 5 | =============================================================================== 6 | 7 | Coding side 8 | -------------------------------------------------------------------------------- 9 | 10 | - Implement the remaining population manipulation methods and tests 11 | (short term); 12 | 13 | - Implement the path relinking methods and tests (long term). 14 | 15 | CI and tests side 16 | -------------------------------------------------------------------------------- 17 | 18 | - Configure Travis-Ci correctly, such that we can run tests on Mac OSX and 19 | Windows too. 20 | 21 | Documentation side 22 | -------------------------------------------------------------------------------- 23 | 24 | - Create a comprehensive tutorial as we did for C++ and Julia versions. 25 | -------------------------------------------------------------------------------- /docs/_static/add_target.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | $("a[href^='http']").attr('target','_blank'); 3 | }); 4 | -------------------------------------------------------------------------------- /docs/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../fonts/fontawesome-webfont.eot");src:url("../fonts/fontawesome-webfont.eot?#iefix") format("embedded-opentype"),url("../fonts/fontawesome-webfont.woff") format("woff"),url("../fonts/fontawesome-webfont.ttf") format("truetype"),url("../fonts/fontawesome-webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} 2 | -------------------------------------------------------------------------------- /docs/_static/custom_theme.css: -------------------------------------------------------------------------------- 1 | .wy-side-nav-search { 2 | color: #9b9b9b; 3 | background: #343131; 4 | } 5 | -------------------------------------------------------------------------------- /docs/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.9', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false 12 | }; -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/fonts/Inconsolata-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Inconsolata-Bold.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Inconsolata-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Inconsolata-Regular.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Inconsolata.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Inconsolata.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato-Bold.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato-Regular.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bold.eot -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bold.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bold.woff -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bolditalic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bolditalic.eot -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bolditalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bolditalic.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bolditalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bolditalic.woff -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-bolditalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-bolditalic.woff2 -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-italic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-italic.eot -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-italic.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-italic.woff -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-italic.woff2 -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-regular.eot -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-regular.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-regular.woff -------------------------------------------------------------------------------- /docs/_static/fonts/Lato/lato-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/Lato/lato-regular.woff2 -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab-Bold.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab-Regular.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2 -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff -------------------------------------------------------------------------------- /docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2 -------------------------------------------------------------------------------- /docs/_static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/_static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/_static/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/_static/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /docs/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | /* sphinx_rtd_theme version 0.4.3 | MIT license */ 2 | /* Built 20190212 16:02 */ 3 | require=function r(s,a,l){function c(e,n){if(!a[e]){if(!s[e]){var i="function"==typeof require&&require;if(!n&&i)return i(e,!0);if(u)return u(e,!0);var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}var o=a[e]={exports:{}};s[e][0].call(o.exports,function(n){return c(s[e][1][n]||n)},o,o.exports,r,s,a,l)}return a[e].exports}for(var u="function"==typeof require&&require,n=0;n"),i("table.docutils.footnote").wrap("
"),i("table.docutils.citation").wrap("
"),i(".wy-menu-vertical ul").not(".simple").siblings("a").each(function(){var e=i(this);expand=i(''),expand.on("click",function(n){return t.toggleCurrent(e),n.stopPropagation(),!1}),e.prepend(expand)})},reset:function(){var n=encodeURI(window.location.hash)||"#";try{var e=$(".wy-menu-vertical"),i=e.find('[href="'+n+'"]');if(0===i.length){var t=$('.document [id="'+n.substring(1)+'"]').closest("div.section");0===(i=e.find('[href="#'+t.attr("id")+'"]')).length&&(i=e.find('[href="#"]'))}0this.docHeight||(this.navBar.scrollTop(i),this.winPosition=n)},onResize:function(){this.winResize=!1,this.winHeight=this.win.height(),this.docHeight=$(document).height()},hashChange:function(){this.linkScroll=!0,this.win.one("hashchange",function(){this.linkScroll=!1})},toggleCurrent:function(n){var e=n.closest("li");e.siblings("li.current").removeClass("current"),e.siblings().find("li.current").removeClass("current"),e.find("> ul li.current").removeClass("current"),e.toggleClass("current")}},"undefined"!=typeof window&&(window.SphinxRtdTheme={Navigation:e.exports.ThemeNav,StickyNav:e.exports.ThemeNav}),function(){for(var r=0,n=["ms","moz","webkit","o"],e=0;e 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | API — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 109 | 110 |
111 | 112 | 113 | 119 | 120 | 121 |
122 | 123 |
124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 |
142 | 143 |
    144 | 145 |
  • Docs »
  • 146 | 147 |
  • API
  • 148 | 149 | 150 |
  • 151 | 152 | 153 | View page source 154 | 155 | 156 |
  • 157 | 158 |
159 | 160 | 161 |
162 |
163 |
164 |
165 | 166 | 185 | 186 | 187 |
188 | 189 |
190 |
191 | 192 | 200 | 201 | 202 |
203 | 204 |
205 |

206 | © Copyright 2019, Carlos E. Andrade 207 | 208 |

209 |
210 | Built with Sphinx using a theme provided by Read the Docs. 211 | 212 |
213 | 214 |
215 |
216 | 217 |
218 | 219 |
220 | 221 | 222 | 223 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | -------------------------------------------------------------------------------- /docs/brkga_mp_ipr.exceptions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | brkga_mp_ipr.exceptions module — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 106 | 107 |
108 | 109 | 110 | 116 | 117 | 118 |
119 | 120 |
121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 |
139 | 140 | 160 | 161 | 162 |
163 |
164 |
165 |
166 | 167 |
168 |

brkga_mp_ipr.exceptions module

169 |
170 |
171 | exception brkga_mp_ipr.exceptions.LoadError[source]
172 |

Bases: RuntimeError

173 |

Specifies an error while reading a configuration file.

174 |
175 | 176 |
177 | 178 | 179 |
180 | 181 |
182 |
183 | 184 | 192 | 193 | 194 |
195 | 196 |
197 |

198 | © Copyright 2019, Carlos E. Andrade 199 | 200 |

201 |
202 | Built with Sphinx using a theme provided by Read the Docs. 203 | 204 |
205 | 206 |
207 |
208 | 209 |
210 | 211 |
212 | 213 | 214 | 215 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | -------------------------------------------------------------------------------- /docs/modules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | brkga_mp_ipr — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 104 | 105 |
106 | 107 | 108 | 114 | 115 | 116 |
117 | 118 |
119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |
137 | 138 |
    139 | 140 |
  • Docs »
  • 141 | 142 |
  • brkga_mp_ipr
  • 143 | 144 | 145 |
  • 146 | 147 | 148 | View page source 149 | 150 | 151 |
  • 152 | 153 |
154 | 155 | 156 |
157 |
158 |
159 |
160 | 161 |
162 |

brkga_mp_ipr

163 | 179 |
180 | 181 | 182 |
183 | 184 |
185 |
186 | 187 | 188 |
189 | 190 |
191 |

192 | © Copyright 2019, Carlos E. Andrade 193 | 194 |

195 |
196 | Built with Sphinx using a theme provided by Read the Docs. 197 | 198 |
199 | 200 |
201 |
202 | 203 |
204 | 205 |
206 | 207 | 208 | 209 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/docs/objects.inv -------------------------------------------------------------------------------- /docs/page_todo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Todo List — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 111 | 112 |
113 | 114 | 115 | 121 | 122 | 123 |
124 | 125 |
126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 |
144 | 145 |
    146 | 147 |
  • Docs »
  • 148 | 149 |
  • Todo List
  • 150 | 151 | 152 |
  • 153 | 154 | 155 | View page source 156 | 157 | 158 |
  • 159 | 160 |
161 | 162 | 163 |
164 |
165 |
166 |
167 | 168 |
169 |

Todo List

170 |
171 |

Coding side

172 |
    173 |
  • Implement the remaining population manipulation methods and tests 174 | (short term);

  • 175 |
  • Implement the path relinking methods and tests (long term).

  • 176 |
177 |
178 |
179 |

CI and tests side

180 |
    181 |
  • Configure Travis-Ci correctly, such that we can run tests on Mac OSX and 182 | Windows too.

  • 183 |
184 |
185 |
186 |

Documentation side

187 |
    188 |
  • Create a comprehensive tutorial as we did for C++ and Julia versions.

  • 189 |
190 |
191 |
192 | 193 | 194 |
195 | 196 |
197 |
198 | 199 | 207 | 208 | 209 |
210 | 211 |
212 |

213 | © Copyright 2019, Carlos E. Andrade 214 | 215 |

216 |
217 | Built with Sphinx using a theme provided by Read the Docs. 218 | 219 |
220 | 221 |
222 |
223 | 224 |
225 | 226 |
227 | 228 | 229 | 230 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /docs/py-modindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Python Module Index — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
52 | 53 | 107 | 108 |
109 | 110 | 111 | 117 | 118 | 119 |
120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |
140 | 141 |
    142 | 143 |
  • Docs »
  • 144 | 145 |
  • Python Module Index
  • 146 | 147 | 148 |
  • 149 | 150 |
  • 151 | 152 |
153 | 154 | 155 |
156 |
157 |
158 |
159 | 160 | 161 |

Python Module Index

162 | 163 |
164 | b 165 |
166 | 167 | 168 | 169 | 171 | 172 | 174 | 177 | 178 | 179 | 182 | 183 | 184 | 187 | 188 | 189 | 192 | 193 | 194 | 197 | 198 | 199 | 202 |
 
170 | b
175 | brkga_mp_ipr 176 |
    180 | brkga_mp_ipr.algorithm 181 |
    185 | brkga_mp_ipr.enums 186 |
    190 | brkga_mp_ipr.exceptions 191 |
    195 | brkga_mp_ipr.types 196 |
    200 | brkga_mp_ipr.types_io 201 |
203 | 204 | 205 |
206 | 207 |
208 |
209 | 210 | 211 |
212 | 213 |
214 |

215 | © Copyright 2019, Carlos E. Andrade 216 | 217 |

218 |
219 | Built with Sphinx using a theme provided by Read the Docs. 220 | 221 |
222 | 223 |
224 |
225 | 226 |
227 | 228 |
229 | 230 | 231 | 232 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Search — BRKGA-MP-IPR 0.9 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 105 | 106 |
107 | 108 | 109 | 115 | 116 | 117 |
118 | 119 |
120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 |
138 | 139 |
    140 | 141 |
  • Docs »
  • 142 | 143 |
  • Search
  • 144 | 145 | 146 |
  • 147 | 148 | 149 | 150 |
  • 151 | 152 |
153 | 154 | 155 |
156 |
157 |
158 |
159 | 160 | 168 | 169 | 170 |
171 | 172 |
173 | 174 |
175 | 176 |
177 |
178 | 179 | 180 |
181 | 182 |
183 |

184 | © Copyright 2019, Carlos E. Andrade 185 | 186 |

187 |
188 | Built with Sphinx using a theme provided by Read the Docs. 189 | 190 |
191 | 192 |
193 |
194 | 195 |
196 | 197 |
198 | 199 | 200 | 201 | 206 | 207 | 208 | 209 | 210 | 211 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /examples/tsp/config.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # config.conf: example of a configuration file for BRKGA-MP-IPR frameworks. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Dec 28, 2018 by ceandrade 9 | # Last update: Jan 09, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | # Population size 25 | population_size 2000 26 | 27 | # Elite percentage 28 | elite_percentage 0.30 29 | 30 | # Mutants percentage 31 | mutants_percentage 0.15 32 | 33 | # Number of elite parents to mate 34 | num_elite_parents 2 35 | 36 | # Total number of parents to mate 37 | total_parents 3 38 | 39 | # Bias function to be used to rank the parents 40 | bias_type LOGINVERSE 41 | 42 | # Number of independent populations 43 | num_independent_populations 3 44 | 45 | # Number of pairs of chromosomes to be tested to path relinking. 46 | pr_number_pairs 0 47 | 48 | # Mininum distance between chromosomes to path-relink 49 | pr_minimum_distance 0.15 50 | 51 | # Path relink type 52 | pr_type PERMUTATION 53 | 54 | # Individual selection to path-relink 55 | pr_selection BESTSOLUTION 56 | 57 | # Defines the block size based on the size of the population 58 | alpha_block_size 1.0 59 | 60 | # Percentage/path size 61 | pr_percentage 1.0 62 | 63 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 64 | exchange_interval 200 65 | 66 | # Number of elite chromosomes exchanged from each population 67 | num_exchange_indivuduals 2 68 | 69 | # Interval at which the populations are reset (0 means no reset) 70 | reset_interval 600 71 | -------------------------------------------------------------------------------- /examples/tsp/greedy_tour.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # greedy_tour.py: Simple greedy TSP tour linking the closest nodes in sequence. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 18, 2019 by ceandrade 9 | # Last update: Nov 18, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ################################################################################ 23 | 24 | from typing import List, Tuple 25 | 26 | from tsp_instance import TSPInstance 27 | 28 | """ 29 | function greedy_tour(instance::TSP_Instance)::Array{Int64, 1} 30 | 31 | Build a greedy Traveling Salesman Problem tour starting from node 1. 32 | 33 | # Returns 34 | The tour cost and a permutation of the nodes representing it. 35 | """ 36 | def greedy_tour(instance: TSPInstance) -> Tuple[float, List]: 37 | """ 38 | Builds a greedy Traveling Salesman Problem tour starting from node 0. 39 | 40 | Args: 41 | instance: a TSP instance. 42 | 43 | Returns: 44 | A tuple with the tour cost and a permutation of the nodes 45 | representing it. 46 | """ 47 | 48 | tour = [0] * instance.num_nodes 49 | tour[0] = 0 50 | remaining_nodes = set(range(1, instance.num_nodes)) 51 | 52 | INF = max(instance.distances) + 10.0 53 | cost = 0.0 54 | current_node = 0 55 | next_node = 0 56 | idx = 1 57 | while len(remaining_nodes) > 0: 58 | best_dist = INF 59 | for j in remaining_nodes: 60 | dist = instance.distance(current_node, j) 61 | if dist < best_dist: 62 | best_dist = dist 63 | next_node = j 64 | 65 | cost += best_dist 66 | tour[idx] = next_node 67 | remaining_nodes.remove(next_node) 68 | current_node = next_node 69 | idx += 1 70 | # end while 71 | 72 | cost += instance.distance(tour[0], tour[-1]) 73 | return (cost, tour) 74 | -------------------------------------------------------------------------------- /examples/tsp/instances/brazil58.dat: -------------------------------------------------------------------------------- 1 | 58 2 | 2635 2713 2437 1600 2845 6002 1743 594 2182 2906 1658 464 3334 3987 2870 2601 330 3049 1302 3399 1946 1278 669 627 2878 1737 3124 2878 307 5217 799 3305 3716 2251 2878 3467 4316 2963 512 2515 4850 1937 367 3601 3936 2430 2691 2087 1861 2358 2263 1425 2266 2166 3870 1417 739 3 | 314 2636 666 1096 4645 693 2889 287 772 1135 2875 1424 2185 1193 846 2142 1127 3104 1484 490 990 1950 2855 975 926 1214 599 2535 3860 3027 1407 1811 359 1060 1557 2959 394 2740 98 3538 856 2026 1710 1733 508 194 532 2906 435 335 2470 137 234 2072 1196 1517 4 | 2730 706 791 4588 922 2991 217 760 1050 2915 1119 1776 1451 5410 2182 846 3333 578 721 1030 1990 2895 670 835 909 287 2575 3803 3067 1102 1505 158 439 1248 2902 287 2780 276 3436 771 2066 1395 1740 407 279 334 3135 337 235 2699 451 546 1882 2699 1557 5 | 2824 3457 6083 2120 2040 2844 2973 3937 1958 3710 4363 2941 3207 1991 3512 1571 3392 2013 2922 2368 2170 3336 3503 3500 2884 2109 5298 2108 3643 4092 2934 3093 3843 4391 2763 2083 2543 4925 3236 2107 3939 4274 3008 2522 3006 806 2936 3026 947 2464 2364 4208 3116 2390 6 | 1247 4746 716 2223 584 1442 694 2089 1577 2230 1609 1003 1260 1297 2535 1511 908 324 1116 2183 1126 260 1367 996 1863 3961 2355 1565 1959 660 1106 1710 3060 991 2068 523 3594 434 1354 1861 2196 658 750 563 2929 586 668 2493 494 557 2130 524 851 7 | 5126 1653 3545 708 1298 1342 3451 347 1126 1989 250 2736 138 3786 888 1452 1671 2336 3431 124 1165 189 640 3110 4341 3603 489 855 730 364 598 3440 841 3316 919 3974 1063 2620 940 1090 722 921 761 3866 652 754 3430 1096 1191 1232 1582 2098 8 | 4267 6553 4826 3830 5951 6417 5423 6089 3142 4876 5676 5181 6678 4720 4074 5071 5724 6675 5000 4993 5221 4494 6265 785 6776 5265 5756 4628 4747 5511 1686 4276 6472 4447 2230 5167 5784 5561 5891 4902 4353 4922 6480 4759 4771 6044 4299 4199 5830 5271 5404 9 | 2296 923 1175 1282 2162 1906 2559 1133 1352 1422 1651 2423 1588 209 1030 1461 2420 1538 965 1716 1112 2010 3482 2521 1839 2288 1000 1289 2039 2551 955 2217 715 3125 1145 1529 2131 2466 1087 718 1083 2225 1015 960 1789 537 436 2400 1238 1199 10 | 2869 3459 2366 147 3741 4399 3417 3163 924 3462 681 3734 2493 1934 1377 130 3402 2449 3531 3219 343 5766 228 3724 4128 2883 3277 3870 4835 3214 184 2746 4875 2492 925 4017 4362 2985 2973 2831 1544 2913 2891 1103 2717 2655 4504 1972 1447 11 | 1004 781 2793 1036 1694 1694 458 1844 757 3125 1096 827 908 1702 2773 587 844 826 455 2453 4041 2945 1019 1423 75 572 1165 3140 560 2658 227 3674 502 1944 1312 1650 170 383 169 3136 98 80 2700 411 508 1584 948 1435 12 | 2128 3322 1609 2266 693 1041 2585 1353 3586 887 974 2553 2624 3583 1177 1488 1398 673 3173 3045 3684 1444 1935 941 926 1686 2149 455 3380 894 2688 1433 2692 1740 2070 1081 696 1101 3388 1009 950 2952 1063 964 2009 1972 2286 13 | 2265 1695 2353 2819 1117 1557 1416 2636 1755 1608 456 1002 2245 1246 257 1485 1225 1925 5166 2417 1678 2082 871 1231 1824 4265 1290 2130 1019 4799 279 1441 1971 2309 772 1148 618 2844 700 802 2413 1188 1248 2243 248 1210 14 | 3607 4265 3283 3029 931 3328 817 3600 2359 1876 1267 200 3158 2339 3397 3120 211 5632 366 3590 4004 2766 3134 3736 4701 3185 135 2914 5274 2267 815 3883 4221 2667 3043 2606 1451 2595 2697 1011 2563 2623 4155 1834 1337 15 | 665 2300 578 2845 474 4116 1216 1705 1901 2693 3848 652 1480 224 968 3547 4648 4020 176 394 1153 692 137 3752 1169 3744 1301 4291 1420 3047 479 629 1059 1249 1079 4119 982 967 3683 1424 1421 771 1939 2901 16 | 2957 1236 3706 992 4774 1471 2358 2654 3346 4589 1177 2151 887 1564 4099 5304 4591 818 262 1716 1350 528 4408 1827 4306 1905 4947 2073 3590 562 607 1717 2093 1742 4772 1645 1747 4036 2082 2179 760 2592 3554 17 | 1734 2543 2044 3544 1578 932 1939 2582 3304 1868 1861 2089 1362 3131 2357 3642 2133 2624 1491 1615 2379 1456 1144 3338 1310 1990 2035 2650 2429 2759 1770 1216 1790 3346 1622 1639 2910 1162 1062 2698 2139 2278 18 | 2267 300 3542 638 1202 1328 2094 3187 129 915 368 390 2866 4091 3359 561 965 480 114 711 3190 591 3072 669 3724 846 2379 854 1192 392 671 511 3565 408 388 3129 846 950 1126 1347 1860 19 | 2566 1273 2905 1619 1175 564 1068 2600 1638 2841 2470 770 5113 1240 3039 3433 2134 2580 3184 4182 2465 953 1997 4756 1834 114 3335 3670 2388 2349 1984 1715 2068 2074 1284 1968 2031 3604 1340 636 20 | 3841 945 1507 1627 2393 3486 178 1214 254 652 3165 4396 3658 531 730 1079 374 476 3495 856 3371 968 4029 1140 2678 806 960 691 978 810 3864 707 687 3428 1145 1249 1096 1646 2159 21 | 3998 2620 2217 1647 693 3665 2676 3906 3487 1052 5893 537 4108 4503 3201 3635 4249 4962 3366 800 3064 5536 2804 1385 4401 4739 3199 3129 3032 1070 3122 3209 634 2948 2846 4673 2395 1681 22 | 1383 1835 2627 3846 767 1771 788 520 3380 3925 3872 938 1200 842 524 943 3024 607 3585 892 3558 1470 2871 1288 1438 1118 742 1143 3801 1046 976 3365 1076 1174 1185 1989 2951 23 | 1238 1612 2617 1332 1174 1495 875 2211 3289 2718 1634 2087 774 1109 1838 2388 754 2414 607 2922 1348 1726 1930 2265 991 517 983 2422 919 880 1986 459 359 2199 1438 1350 24 | 801 1865 1450 554 2243 1546 1545 4286 2037 1889 2293 984 1542 2040 3385 1315 1750 847 3919 600 1061 2182 2510 1093 1074 887 2425 1021 992 1994 818 881 2454 432 1394 25 | 1256 2083 1252 2324 2058 936 4929 1428 2517 2686 1841 2057 2806 4038 2123 1141 1849 4572 1275 452 2805 3143 1610 2020 1612 1869 1542 1642 1422 1748 1811 3082 754 259 26 | 3310 2324 3551 3185 372 5890 190 3754 4148 2849 3295 3899 4959 3180 125 2712 5533 2524 954 4050 4385 2836 2939 2644 1669 2764 2857 1233 2683 2746 4319 2004 1326 27 | 1044 432 519 2995 4215 3487 709 908 609 243 639 3314 720 3200 798 3848 969 2486 984 1138 528 800 640 3751 536 517 3315 975 1078 1274 1329 1189 28 | 1275 1023 2004 4208 2496 1468 1637 669 1022 1627 3307 1088 2209 783 3841 184 1524 1756 2094 570 946 523 3178 498 600 2742 754 817 2033 498 1460 29 | 758 3236 4436 4225 283 606 848 482 359 3535 959 3441 1037 4069 1210 2727 701 851 702 1039 879 3929 777 756 3493 1214 1311 1494 1570 2532 30 | 2865 3709 3036 478 1293 354 274 1036 2808 366 3070 447 3342 949 2356 708 837 577 367 623 3325 525 523 2889 631 728 1635 1304 2266 31 | 5480 549 3434 3828 2529 2975 3579 4549 2860 257 2392 5123 2204 656 3730 4065 2527 2619 2354 1608 2444 2537 1172 2406 2305 3999 1684 1006 32 | 5991 4480 4971 3843 3962 4791 901 3491 5687 3662 1445 4615 4999 4776 5106 4117 3568 4137 5695 3969 3986 5259 3514 3414 5045 4708 4619 33 | 3926 4320 3021 3467 4171 5060 3352 297 2884 5634 2696 1126 4222 4557 3008 3114 2846 1607 2936 3162 1171 2855 2918 4491 2176 1498 34 | 547 1041 675 290 3579 1152 3639 1230 4113 1402 2925 213 435 802 1232 1072 4052 970 949 3616 1407 1511 413 1763 2725 35 | 1444 1016 257 4002 1493 4041 1638 4604 1802 3319 354 229 1356 1849 1475 4501 1139 1352 4065 1839 1931 300 1932 2899 36 | 594 1187 2942 329 2734 148 3476 567 2020 1335 1672 243 287 268 3213 171 107 2777 315 419 1606 1087 2049 37 | 759 3061 705 3180 635 3595 971 2466 968 1306 506 705 625 3502 524 502 3066 960 1064 1240 1303 1974 38 | 3825 1236 3784 1381 4359 1553 3070 342 492 1099 1592 1218 4252 1115 1095 3816 1560 1672 634 1908 2570 39 | 2590 4848 2761 544 3481 4068 3875 4505 3145 2667 3236 4764 3073 3083 4328 2613 2513 4144 3590 3718 40 | 3065 432 3124 1014 2351 1445 1783 602 345 688 3168 590 488 2732 498 589 1717 1369 2331 41 | 2597 5330 2409 839 3935 4270 2721 2923 2559 1582 2649 2753 1146 2568 2651 4204 1889 1211 42 | 3294 722 1883 1423 1783 391 192 416 2928 319 217 2492 184 282 1795 1095 2042 43 | 4015 4642 4409 4739 3750 3201 3770 5338 3607 3617 4902 3147 3047 4678 4124 4252 44 | 1720 1698 2037 554 852 339 3004 429 533 2571 889 993 1967 527 1123 45 | 3221 3556 2274 2235 1870 1601 1954 1960 1170 1854 1917 3490 1226 522 46 | 273 1340 1525 1355 4344 1258 942 3908 1700 1798 312 2051 3033 47 | 1668 1863 1693 4679 1596 1580 4243 2038 2134 254 2389 3351 48 | 520 86 3299 72 170 2864 558 662 1489 856 1434 49 | 543 2931 448 342 2495 239 288 1797 1266 1878 50 | 3295 97 199 2859 588 692 1637 858 1339 51 | 3227 3206 446 2750 2649 4617 2417 1882 52 | 102 2791 486 590 1535 8700 1441 53 | 2770 389 497 1514 888 1543 54 | 2314 2213 4181 2105 1446 55 | 112 1972 994 1345 56 | 2076 1057 1408 57 | 2328 2986 58 | 962 59 | 60 | -------------------------------------------------------------------------------- /examples/tsp/instances/burma14.dat: -------------------------------------------------------------------------------- 1 | 14 2 | 153 510 706 966 581 455 70 160 372 157 567 342 398 3 | 422 664 997 598 507 197 311 479 310 581 417 376 4 | 289 744 390 437 491 645 880 618 374 455 211 5 | 491 265 410 664 804 1070 768 259 499 310 6 | 400 514 902 990 1261 947 418 635 636 7 | 168 522 634 910 593 19 284 239 8 | 389 482 757 439 163 124 232 9 | 154 406 133 508 273 355 10 | 276 43 623 358 498 11 | 318 898 633 761 12 | 582 315 464 13 | 275 221 14 | 247 15 | 16 | -------------------------------------------------------------------------------- /examples/tsp/main_minimal.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # main_minimal.py: minimal script for calling BRKGA algorithms to solve 3 | # instances of the Traveling Salesman Problem. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. 6 | # All Rights Reserved. 7 | # 8 | # This code is released under LICENSE.md. 9 | # 10 | # Created on: Nov 18, 2019 by ceandrade 11 | # Last update: Nov 18, 2019 by ceandrade 12 | # 13 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 17 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 | # POSSIBILITY OF SUCH DAMAGE. 24 | ############################################################################### 25 | 26 | import sys 27 | 28 | from brkga_mp_ipr.enums import Sense 29 | from brkga_mp_ipr.types_io import load_configuration 30 | from brkga_mp_ipr.algorithm import BrkgaMpIpr 31 | 32 | from tsp_instance import TSPInstance 33 | from tsp_decoder import TSPDecoder 34 | 35 | ############################################################################### 36 | 37 | def main() -> None: 38 | if len(sys.argv) < 4: 39 | print("Usage: python main_minimal.py " 40 | " ") 41 | sys.exit(1) 42 | 43 | ######################################## 44 | # Read the command-line arguments and the instance 45 | ######################################## 46 | 47 | seed = int(sys.argv[1]) 48 | configuration_file = sys.argv[2] 49 | num_generations = int(sys.argv[3]) 50 | instance_file = sys.argv[4] 51 | 52 | print("Reading data...") 53 | instance = TSPInstance(instance_file) 54 | 55 | ######################################## 56 | # Read algorithm parameters 57 | ######################################## 58 | 59 | print("Reading parameters...") 60 | brkga_params, _ = load_configuration(configuration_file) 61 | 62 | ######################################## 63 | # Build the BRKGA data structures and initialize 64 | ######################################## 65 | 66 | print("Building BRKGA data and initializing...") 67 | 68 | decoder = TSPDecoder(instance) 69 | 70 | brkga = BrkgaMpIpr( 71 | decoder=decoder, 72 | sense=Sense.MINIMIZE, 73 | seed=seed, 74 | chromosome_size=instance.num_nodes, 75 | params=brkga_params 76 | ) 77 | 78 | # NOTE: don't forget to initialize the algorithm. 79 | brkga.initialize() 80 | 81 | ######################################## 82 | # Find good solutions / evolve 83 | ######################################## 84 | 85 | print(f"Evolving {num_generations} generations...") 86 | brkga.evolve(num_generations) 87 | 88 | best_cost = brkga.get_best_fitness() 89 | print(f"Best cost: {best_cost}") 90 | 91 | ############################################################################### 92 | 93 | if __name__ == "__main__": 94 | main() 95 | -------------------------------------------------------------------------------- /examples/tsp/tsp_decoder.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # tsp_decoder.py: simple permutation decoder for the Traveling Salesman Problem. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 18, 2019 by ceandrade 9 | # Last update: Nov 18, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | from brkga_mp_ipr.types import BaseChromosome 25 | from tsp_instance import TSPInstance 26 | 27 | class TSPDecoder(): 28 | """ 29 | Simple Traveling Salesman Problem decoder. It creates a permutation of 30 | nodes induced by the chromosome and computes the cost of the tour. 31 | """ 32 | 33 | def __init__(self, instance: TSPInstance): 34 | self.instance = instance 35 | 36 | ########################################################################### 37 | 38 | def decode(self, chromosome: BaseChromosome, rewrite: bool) -> float: 39 | """ 40 | Given a chromossome, builds a tour. 41 | 42 | Note that in this example, ``rewrite`` has not been used. 43 | """ 44 | 45 | permutation = sorted( 46 | (key, index) for index, key in enumerate(chromosome) 47 | ) 48 | 49 | cost = self.instance.distance(permutation[0][1], permutation[-1][1]) 50 | for i in range(len(permutation) - 1): 51 | cost += self.instance.distance(permutation[i][1], 52 | permutation[i + 1][1]) 53 | return cost 54 | -------------------------------------------------------------------------------- /examples/tsp/tsp_instance.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # tsp_instance.py: data structures and support function to deal with instances 3 | # of the Traveling Salesman Problem. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Nov 18, 2019 by ceandrade 10 | # Last update: Nov 18, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | from brkga_mp_ipr.exceptions import LoadError 26 | 27 | class TSPInstance(): 28 | """ 29 | Represents an instance for the Traveling Salesman Problem. The constructor 30 | loads a upper triangular matrix as following: 31 | 32 | number of nodes (n) 33 | dist12 dist13 dist14 ... dist1n 34 | dist23 dist24 ... dist2(n - 1) 35 | ... 36 | dist(n-2)(n-1) 37 | 38 | For example, for n = 4 we have 39 | 40 | 4 41 | 12 13 14 42 | 23 24 43 | 34 44 | """ 45 | 46 | def __init__(self, filename: str): 47 | """ 48 | Initializes the instance loading from a file. 49 | """ 50 | 51 | with open(filename, "r") as hd: 52 | lines = hd.readlines() 53 | 54 | if not lines: 55 | raise LoadError(f"Cannot read file '{filename}'") 56 | 57 | line_number = 1 58 | try: 59 | self.num_nodes = int(lines[0]) 60 | 61 | matrix_size = (self.num_nodes * (self.num_nodes - 1)) / 2 62 | self.distances = [] 63 | 64 | for i in range(1, self.num_nodes): 65 | line_number = i + 1 66 | values = [float(x.strip()) for x in lines[i].split()] 67 | self.distances.extend(values) 68 | except Exception: 69 | raise LoadError(f"Error reading line {line_number} of '{filename}'") 70 | 71 | ########################################################################### 72 | 73 | def distance(self, i: int, j: int) -> float: 74 | """ 75 | Returns the distance between nodes `i` and `j`. 76 | """ 77 | if i > j: 78 | i, j = j, i 79 | return self.distances[(i * (self.num_nodes - 1)) - ((i - 1) * i // 2) + 80 | (j - i - 1)] 81 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | setup.py: Configurations for install and setup BRKGA-MP-IPR. 3 | 4 | (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | 6 | This code is released under LICENSE.md. 7 | 8 | Created on: Nov 15, 2019 by ceandrade 9 | Last update: Nov 25, 2019 by ceandrade 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGE. 22 | """ 23 | 24 | import setuptools 25 | 26 | test_deps = [ 27 | "dill>=0.3.1.1", 28 | "pytest" 29 | ] 30 | extras = { 31 | 'test': test_deps, 32 | } 33 | 34 | with open("README.md", "r") as fh: 35 | long_description = fh.read() 36 | 37 | setuptools.setup( 38 | name="brkga_mp_ipr", 39 | version="0.9.1", 40 | author="Carlos Eduardo de Andrade", 41 | author_email="ce.andrade@gmail.com", 42 | description="The Multi-Parent Biased Random-Key Genetic Algorithm " 43 | "with Implict Path Relink", 44 | long_description=long_description, 45 | long_description_content_type="text/markdown", 46 | url="https://github.com/ceandrade/brkga_mp_ipr_python", 47 | packages=setuptools.find_packages(), 48 | classifiers=[ 49 | "Intended Audience :: Science/Research", 50 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 51 | "Topic :: Scientific/Engineering :: Mathematics", 52 | "Topic :: Software Development :: Libraries", 53 | "Programming Language :: Python :: 3.7", 54 | "Operating System :: OS Independent", 55 | "License :: OSI Approved :: BSD License" 56 | ], 57 | python_requires='>=3.7.2', 58 | tests_require=test_deps, 59 | extras_require=extras, 60 | ) 61 | -------------------------------------------------------------------------------- /src_docs/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # (c) Copyright 2019, Carlos Eduardo de Andrade. 3 | # All Rights Reserved. 4 | # 5 | # Created on : Nov 21, 2019 by andrade 6 | # Last update: Nov 21, 2019 by andrade 7 | # 8 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 9 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 10 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 12 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 15 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 16 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 17 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | # POSSIBILITY OF SUCH DAMAGE. 19 | ############################################################################### 20 | 21 | .PHONY: all clean 22 | 23 | all: 24 | sphinx-apidoc -f -e --extensions autodoc,todo,mathjax,viewcode \ 25 | -o src/rst ../brkga_mp_ipr 26 | sphinx-build -b html src/rst build/html 27 | touch build/html/.nojekyll 28 | rm -rf ../docs 29 | cp -a build/html ../docs 30 | cp -a src/assets/logo*png ../docs/_static 31 | 32 | clean: 33 | rm -rf build 34 | -------------------------------------------------------------------------------- /src_docs/src/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/src_docs/src/assets/favicon.ico -------------------------------------------------------------------------------- /src_docs/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/src_docs/src/assets/logo.png -------------------------------------------------------------------------------- /src_docs/src/assets/logo_name_150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/src_docs/src/assets/logo_name_150.png -------------------------------------------------------------------------------- /src_docs/src/assets/logo_name_300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/src_docs/src/assets/logo_name_300.png -------------------------------------------------------------------------------- /src_docs/src/assets/logo_name_600.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/src_docs/src/assets/logo_name_600.png -------------------------------------------------------------------------------- /src_docs/src/rst/_static/add_target.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | $("a[href^='http']").attr('target','_blank'); 3 | }); 4 | -------------------------------------------------------------------------------- /src_docs/src/rst/_static/custom_theme.css: -------------------------------------------------------------------------------- 1 | .wy-side-nav-search { 2 | color: #9b9b9b; 3 | background: #343131; 4 | } 5 | -------------------------------------------------------------------------------- /src_docs/src/rst/api.rst: -------------------------------------------------------------------------------- 1 | API 2 | ============ 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | brkga_mp_ipr 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/brkga_mp_ipr.algorithm.rst: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.algorithm module 2 | =============================== 3 | 4 | .. automodule:: brkga_mp_ipr.algorithm 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/brkga_mp_ipr.enums.rst: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.enums module 2 | =========================== 3 | 4 | .. automodule:: brkga_mp_ipr.enums 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/brkga_mp_ipr.exceptions.rst: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.exceptions module 2 | ================================ 3 | 4 | .. automodule:: brkga_mp_ipr.exceptions 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/brkga_mp_ipr.rst: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr package 2 | ====================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | brkga_mp_ipr.algorithm 11 | brkga_mp_ipr.enums 12 | brkga_mp_ipr.exceptions 13 | brkga_mp_ipr.types 14 | brkga_mp_ipr.types_io 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: brkga_mp_ipr 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /src_docs/src/rst/brkga_mp_ipr.types.rst: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.types module 2 | =========================== 3 | 4 | .. automodule:: brkga_mp_ipr.types 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/brkga_mp_ipr.types_io.rst: -------------------------------------------------------------------------------- 1 | brkga\_mp\_ipr.types\_io module 2 | =============================== 3 | 4 | .. automodule:: brkga_mp_ipr.types_io 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file does only contain a selection of the most common options. For a 6 | # full list see the documentation: 7 | # http://www.sphinx-doc.org/en/master/config 8 | 9 | # -- Path setup -------------------------------------------------------------- 10 | 11 | # If extensions (or modules to document with autodoc) are in another directory, 12 | # add these directories to sys.path here. If the directory is relative to the 13 | # documentation root, use os.path.abspath to make it absolute, like shown here. 14 | # 15 | # -- Project information ---------------------------------------------------- 16 | 17 | project = 'BRKGA-MP-IPR' 18 | copyright = '2019, Carlos E. Andrade' 19 | author = 'Carlos E. Andrade' 20 | 21 | # The short X.Y version 22 | version = '' 23 | # The full version, including alpha/beta/rc tags 24 | release = '0.9' 25 | 26 | html_logo = "../assets/logo.png" 27 | html_favicon = "../assets/favicon.ico" 28 | 29 | # -- General configuration --------------------------------------------------- 30 | 31 | # If your documentation needs a minimal Sphinx version, state it here. 32 | # 33 | # needs_sphinx = '1.0' 34 | 35 | # Add any Sphinx extension module names here, as strings. They can be 36 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 37 | # ones. 38 | extensions = [ 39 | 'sphinx.ext.autodoc', 40 | 'sphinx.ext.viewcode', 41 | 'sphinx.ext.todo', 42 | 'sphinx.ext.mathjax', 43 | ] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix(es) of source filenames. 49 | # You can specify multiple suffix as a list of string: 50 | # 51 | source_suffix = ['.rst', '.md'] 52 | #source_suffix = '.rst' 53 | 54 | # The master toctree document. 55 | master_doc = 'index' 56 | 57 | # The language for content autogenerated by Sphinx. Refer to documentation 58 | # for a list of supported languages. 59 | # 60 | # This is also used if you do content translation via gettext catalogs. 61 | # Usually you set "language" from the command line for these cases. 62 | language = None 63 | 64 | # List of patterns, relative to source directory, that match files and 65 | # directories to ignore when looking for source files. 66 | # This pattern also affects html_static_path and html_extra_path. 67 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'page_index.rst'] 68 | 69 | # The name of the Pygments (syntax highlighting) style to use. 70 | pygments_style = None 71 | 72 | 73 | # -- Options for HTML output ------------------------------------------------- 74 | 75 | # The theme to use for HTML and HTML Help pages. See the documentation for 76 | # a list of builtin themes. 77 | # 78 | #html_theme = 'alabaster' 79 | html_theme = 'sphinx_rtd_theme' 80 | 81 | # Theme options are theme-specific and customize the look and feel of a theme 82 | # further. For a list of options available for each theme, see the 83 | # documentation. 84 | # 85 | # html_theme_options = {} 86 | 87 | # Add any paths that contain custom static files (such as style sheets) here, 88 | # relative to this directory. They are copied after the builtin static files, 89 | # so a file named "default.css" will overwrite the builtin "default.css". 90 | html_static_path = ['_static'] 91 | 92 | # Custom sidebar templates, must be a dictionary that maps document names 93 | # to template names. 94 | # 95 | # The default sidebars (for documents that don't match any pattern) are 96 | # defined by theme itself. Builtin themes are using these templates by 97 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', 98 | # 'searchbox.html']``. 99 | # 100 | # html_sidebars = {} 101 | 102 | 103 | # -- Options for HTMLHelp output --------------------------------------------- 104 | 105 | # Output file base name for HTML help builder. 106 | htmlhelp_basename = 'BRKGA-MP-IPRdoc' 107 | 108 | 109 | # -- Options for LaTeX output ------------------------------------------------ 110 | 111 | latex_elements = { 112 | # The paper size ('letterpaper' or 'a4paper'). 113 | # 114 | # 'papersize': 'letterpaper', 115 | 116 | # The font size ('10pt', '11pt' or '12pt'). 117 | # 118 | # 'pointsize': '10pt', 119 | 120 | # Additional stuff for the LaTeX preamble. 121 | # 122 | # 'preamble': '', 123 | 124 | # Latex figure (float) alignment 125 | # 126 | # 'figure_align': 'htbp', 127 | } 128 | 129 | # Grouping the document tree into LaTeX files. List of tuples 130 | # (source start file, target name, title, 131 | # author, documentclass [howto, manual, or own class]). 132 | latex_documents = [ 133 | (master_doc, 'BRKGA-MP-IPR.tex', 'BRKGA-MP-IPR Documentation', 134 | 'Carlos E. Andrade', 'manual'), 135 | ] 136 | 137 | 138 | # -- Options for manual page output ------------------------------------------ 139 | 140 | # One entry per manual page. List of tuples 141 | # (source start file, name, description, authors, manual section). 142 | man_pages = [ 143 | (master_doc, 'brkga-mp-ipr', 'BRKGA-MP-IPR Documentation', 144 | [author], 1) 145 | ] 146 | 147 | 148 | # -- Options for Texinfo output ---------------------------------------------- 149 | 150 | # Grouping the document tree into Texinfo files. List of tuples 151 | # (source start file, target name, title, author, 152 | # dir menu entry, description, category) 153 | texinfo_documents = [ 154 | (master_doc, 'BRKGA-MP-IPR', 'BRKGA-MP-IPR Documentation', 155 | author, 'BRKGA-MP-IPR', 'BRKGA-MP-IPR Documentation', 156 | 'Optimization framework'), 157 | ] 158 | 159 | 160 | # -- Options for Epub output ------------------------------------------------- 161 | 162 | # Bibliographic Dublin Core info. 163 | epub_title = project 164 | 165 | # The unique identifier of the text. This can be a ISBN number 166 | # or the project homepage. 167 | # 168 | # epub_identifier = '' 169 | 170 | # A unique identification for the text. 171 | # 172 | # epub_uid = '' 173 | 174 | # A list of files that should not be packed into the epub file. 175 | epub_exclude_files = ['search.html'] 176 | 177 | 178 | # -- Extension configuration ------------------------------------------------- 179 | 180 | # -- Options for todo extension ---------------------------------------------- 181 | 182 | # If true, `todo` and `todoList` produce output, else they produce nothing. 183 | todo_include_todos = True 184 | 185 | # -- Additional CSS and Javascript ------------------------------------------ 186 | 187 | def setup(app): 188 | app.add_javascript('add_target.js') 189 | app.add_stylesheet('custom_theme.css') 190 | -------------------------------------------------------------------------------- /src_docs/src/rst/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: page_index.rst 2 | 3 | .. toctree:: 4 | :hidden: 5 | 6 | page_guide.rst 7 | page_license.rst 8 | page_todo.rst 9 | page_md_src_contributing.rst 10 | 11 | Related Pages 12 | ------------------------------------------------------------------------------- 13 | 14 | | :doc:`page_guide` 15 | | :doc:`page_todo` 16 | | :doc:`page_md_src_contributing` 17 | 18 | 19 | Reference and Index 20 | ------------------------------------------------------------------------------- 21 | 22 | .. toctree:: 23 | :hidden: 24 | 25 | api.rst 26 | 27 | | :doc:`api` 28 | | :ref:`genindex` 29 | 30 | -------------------------------------------------------------------------------- /src_docs/src/rst/modules.rst: -------------------------------------------------------------------------------- 1 | brkga_mp_ipr 2 | ============ 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | brkga_mp_ipr 8 | -------------------------------------------------------------------------------- /src_docs/src/rst/page_index.rst: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; BRKGA-MP-IPR Guide and Documentation - Python version 2 | .. _doxid-indexpage: 3 | 4 | BRKGA-MP-IPR Guide and Documentation - Python version 5 | ================================================================================ 6 | 7 | BRKGA-MP-IPR provides a _very easy-to-use_ framework for the 8 | Multi-Parent Biased Random-Key Genetic Algorithm with Implict Path Relink 9 | (**BRKGA-MP-IPR**). Assuming that your have a *decoder* to your problem, 10 | we can setup, run, and extract the value of the best solution in less than 11 | 5 commands (obvisiously, you may need few other lines fo code to do a proper 12 | test). 13 | 14 | This Python version is very flexible and suitable for prototyping. However, 15 | it is not as fast as the 16 | `C++ version `_ or the 17 | `Julia version `_. 18 | Moreover, due to Python Interpreter limitations (see 19 | https://wiki.python.org/moin/GlobalInterpreterLock), real multithread is 20 | not possible, defeating the BRKGA's capability of parallel decoding, which 21 | speeds up the optimization by large paces. 22 | 23 | If Python is not suitable to you, we may find useful the 24 | `C++ version `_ or the 25 | `Julia version `_ of this 26 | framework. At this moment, we have no plans to implement the BRKGA-MP-IPR in 27 | other languages such as Java or C#. But if you want to do so, you are must 28 | welcome. But please, keep the API as close as possible to the C++ API (or 29 | Julia API in case you decide go C), and use the best coding and documentation 30 | practices of your chosen language/framework. 31 | 32 | - `C++ version `_ 33 | - `Julia version `_ 34 | 35 | If you are not familiar with how BRKGA works, take a look on 36 | `Standard BRKGA `_ and 37 | `Multi-Parent BRKGA `_. 38 | In the future, we will provide a *Prime on BRKGA-MP* 39 | section. If you know what *elite set*, *decoder*, and so means, we 40 | can get to the guts on the :ref:`Guide `. 41 | 42 | License and Citing 43 | -------------------------------------------------------------------------------- 44 | 45 | BRKGA-MP-IPR uses a permissive BSD-like license and it can be used as it 46 | pleases you. And since this framework is also part of an academic effort, we 47 | kindly ask you to remember to cite the originating paper of this work. 48 | Indeed, Clause 4 estipulates that "all publications, softwares, or any other 49 | materials mentioning features or use of this software (as a whole package or 50 | any parts of it) and/or the data used to test it must cite the following 51 | article explicitly:": 52 | 53 | C.E. Andrade. R.F. Toso, J.F. Gonçalves, M.G.C. Resende. The Multi-Parent 54 | Biased Random-key Genetic Algorithm with Implicit Path Relinking. *European 55 | Journal of Operational Research*, volume 289, number 1, pages 17–30, 2021. 56 | DOI `10.1016/j.ejor.2019.11.037 `_ 57 | 58 | About the logo 59 | ------------------------------------------------------------------------------- 60 | 61 | The logo is just a play with 3 chromosomes crossing with each other 62 | (multi-parent) during the mating process. The lines also represent solutions 63 | paths that encounter with each other generating new solutions during the 64 | path-relink 65 | -------------------------------------------------------------------------------- /src_docs/src/rst/page_license.rst: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; License 2 | .. _doxid-page_license: 3 | 4 | BRKGA-MP-IPR License 5 | ================================================================================ 6 | 7 | Copyright (c) 2019, Carlos Eduardo de Andrade. All other rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are only permitted provided that the following conditions are 11 | met: 12 | 13 | 1. Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | 3. Neither the name of the copyright holder nor the names of its contributors 21 | may be used to endorse or promote products derived from this software 22 | without specific prior written permission. 23 | 24 | 4. All publications, softwares, or any other materials mentioning features or 25 | use of this software (as a whole package or any parts of it) and/or the data 26 | used to test it must cite the following article explicitly: 27 | 28 | C.E. Andrade. R.F. Toso, J.F. Gonçalves, M.G.C. Resende. The Multi-Parent 29 | Biased Random-key Genetic Algorithm with Implicit Path Relinking. *European 30 | Journal of Operational Research*, volume 289, number 1, pages 17–30, 2021. 31 | DOI `10.1016/j.ejor.2019.11.037 `_ 32 | 33 | 34 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 35 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 36 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | -------------------------------------------------------------------------------- /src_docs/src/rst/page_md_src_contributing.rst: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; Contributing 2 | .. _doxid-md_src_contributing: 3 | 4 | Contributing 5 | =============================================================================== 6 | 7 | Although the code is an experimental one, we aim to write an efficient and 8 | consistent code. So, you should keep in mind the balance between memory 9 | utilization and code efficiency and pay special attention to cache utilization. 10 | 11 | Style 12 | ------------------------------------------------------------------------------- 13 | 14 | Please, follow the general `PEP8 coding style `_. Since it is 15 | too long to describe all details here, study the code already written. 16 | However, in general: 17 | 18 | * Name classes, methods, and variables as clear and meaningful as possible; 19 | 20 | * Write short commentaries on the code flow to reading more accessible and 21 | faster; 22 | 23 | * Properly document the code, especially the data structures and methods 24 | definitions. Do not forget to link/refer them; 25 | 26 | * All classes, attributes, methods, functions, and so must have type 27 | annotations. The user must be able to know exactly what kind of objects 28 | he/she is dealing with. Use the ``typing`` package, and use ``from __future__ 29 | import annotations``; 30 | 31 | * No trailing spaces,kd no tabs, Unix/POSIX end of line. Try to keep line 32 | within 80 columns and do not exceed 90 columns; 33 | 34 | * We encourage the use of Python f-strings where the make the code easier to 35 | read; 36 | 37 | * Use section separations (sequence of `#`), for clarity, especially into 38 | BrkgaMpIpr class. This class has lots of long methods, which can be 39 | categorized into different groups of functionality. 40 | 41 | * Do not use system specific code/headers. Your code must compile in several 42 | systems with minimum change; 43 | 44 | * All submissions will need to pass the "pylint" test using the supplied 45 | ``pylintrc`` file. Note that this file is pretty generic, but it may be 46 | changed in the future; 47 | 48 | * Make sure that, for each method/function, you write unit tests that cover 49 | all corner cases, and few regular cases (> 1); 50 | 51 | * New code without proper unit tests will not be merged; 52 | 53 | * Do not commit or do a pull request until the code pass in all tests. 54 | 55 | -------------------------------------------------------------------------------- /src_docs/src/rst/page_todo.rst: -------------------------------------------------------------------------------- 1 | .. index:: pair: page; Todo List 2 | .. _doxid-todo: 3 | 4 | Todo List 5 | =============================================================================== 6 | 7 | Coding side 8 | -------------------------------------------------------------------------------- 9 | 10 | - Implement the remaining population manipulation methods and tests 11 | (short term); 12 | 13 | - Implement the path relinking methods and tests (long term). 14 | 15 | CI and tests side 16 | -------------------------------------------------------------------------------- 17 | 18 | - Configure Travis-Ci correctly, such that we can run tests on Mac OSX and 19 | Windows too. 20 | 21 | Documentation side 22 | -------------------------------------------------------------------------------- 23 | 24 | - Create a comprehensive tutorial as we did for C++ and Julia versions. 25 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | brkga_mp_ipr package tests - Version 0.9 - Nov 16, 2019 3 | 4 | (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | 6 | This code is released under LICENSE.md. 7 | 8 | Created on: Nov 16, 2019 by ceandrade 9 | Last update: Nov 16, 2019 by ceandrade 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGE. 22 | """ 23 | # Tests usually have no __init__.py files. However, tox fails if it cannot find 24 | # an __init__.py file, and the test folder contains extra fixture classes. 25 | -------------------------------------------------------------------------------- /tests/decoders.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # decoders.py: decoders for tests. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 09, 2019 by ceandrade 9 | # Last update: Nov 09, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ################################################################################ 23 | 24 | from brkga_mp_ipr.types import BaseChromosome 25 | from tests.instance import Instance 26 | 27 | class SumDecode(): 28 | def __init__(self, instance: Instance): 29 | self.instance = instance 30 | 31 | def decode(self, chromosome: BaseChromosome, rewrite: bool) -> float: 32 | tmp = [x + y for x, y in zip(chromosome, self.instance.data)] 33 | tmp = [x / max(tmp) for x in tmp] 34 | if rewrite: 35 | for i in range(len(chromosome)): 36 | chromosome[i] = tmp[i] 37 | return sum(tmp) 38 | 39 | ################################################################################ 40 | 41 | class RankDecode(): 42 | def __init__(self, instance: Instance): 43 | self.instance = instance 44 | 45 | def decode(self, chromosome: BaseChromosome, rewrite: bool) -> float: 46 | tmp = [x + y for x, y in zip(chromosome, self.instance.data)] 47 | rank = 0 48 | for i, value in enumerate(tmp[1:]): 49 | if value > tmp[i]: 50 | rank += 1 51 | if rewrite: 52 | for i in range(len(chromosome)): 53 | chromosome[i] = tmp[i] 54 | return float(rank) 55 | -------------------------------------------------------------------------------- /tests/instance.py: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # instance.py: simple data container for tests. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Nov 09, 2019 by ceandrade 9 | # Last update: Nov 09, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ################################################################################ 23 | 24 | from random import Random 25 | 26 | class Instance(): 27 | def __init__(self, size: int): 28 | rng = Random(8724632840343) 29 | self.data = [rng.random() for _ in range(size)] 30 | -------------------------------------------------------------------------------- /tests/paths_constants.py: -------------------------------------------------------------------------------- 1 | """ 2 | tests.paths_constants Version 0.1 - Nov 01, 2019 3 | 4 | This module contains paths and constants for tests. 5 | 6 | @author: Carlos Eduardo de Andrade 7 | 8 | (c) Copyright 2019, AT&T Labs Research. 9 | AT&T Intellectual Property. All Rights Reserved. 10 | 11 | Created on Nov 01, 2019 by andrade 12 | Modified on Nov 15, 2019 by andrade 13 | 14 | See LICENSE.md file for license information. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | """ 28 | 29 | import os 30 | import pkg_resources 31 | 32 | ############################################################################### 33 | # Resources for testing 34 | ############################################################################### 35 | 36 | RESOURCE_DIR = pkg_resources.resource_filename(__name__, "resources") 37 | CONFIG_DIR = os.path.join(RESOURCE_DIR, "configuration_files") 38 | STATE_DIR = os.path.join(RESOURCE_DIR, "states") 39 | SOLUTION_DIR = os.path.join(RESOURCE_DIR, "solutions") 40 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/custom_bias_function.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # custom_bias_function.conf: example of a configuration file for 3 | # BRKGA-MP-IPR frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_size 500 27 | 28 | # Elite percentage 29 | elite_percentage 0.30 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | bias_type CUSTOM 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type PERMUTATION 54 | 55 | # Individual selection to path-relink 56 | pr_selection RANDOMELITE 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/empty.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/configuration_files/empty.conf -------------------------------------------------------------------------------- /tests/resources/configuration_files/missing_param.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # missing_param.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | 27 | # Elite percentage 28 | elite_percentage 0.30 29 | 30 | # Mutants percentage 31 | 32 | # Number of elite parents to mate 33 | num_elite_parents 2 34 | 35 | # Total number of parents to mate 36 | 37 | # Bias function to be used to rank the parents 38 | #bias_type LOGINVERSE 39 | 40 | # Number of independent populations 41 | num_independent_populations 3 42 | 43 | # Number of pairs of chromosomes to be tested to path relinking. 44 | pr_number_pairs 0 45 | 46 | # Mininum distance between chromosomes to path-relink 47 | pr_minimum_distance 0.15 48 | 49 | # Path relink type 50 | pr_type PERMUTATION 51 | 52 | # Individual selection to path-relink 53 | pr_selection RANDOMELITE 54 | 55 | # Defines the block size based on the size of the population 56 | alpha_block_size 1.0 57 | 58 | # Percentage/path size 59 | pr_percentage 1.0 60 | 61 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 62 | exchange_interval 200 63 | 64 | # Number of elite chromosomes exchanged from each population 65 | num_exchange_indivuduals 2 66 | 67 | # Interval at which the populations are reset (0 means no reset) 68 | reset_interval 600 69 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/missing_value.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # missing_value.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_size 27 | 28 | # Elite percentage 29 | elite_percentage 0.30 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | #bias_type LOGINVERSE 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type PERMUTATION 54 | 55 | # Individual selection to path-relink 56 | pr_selection RANDOMELITE 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/regular.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # regular.conf: example of a configuration file for BRKGA-MP-IPR frameworks. 3 | # 4 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | # 6 | # This code is released under LICENSE.md. 7 | # 8 | # Created on: Dec 28, 2018 by ceandrade 9 | # Last update: Jan 07, 2019 by ceandrade 10 | # 11 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | # POSSIBILITY OF SUCH DAMAGE. 22 | ############################################################################### 23 | 24 | # Population size 25 | population_size 500 26 | 27 | # Elite percentage 28 | elite_percentage 0.30 29 | 30 | # Mutants percentage 31 | mutants_percentage 0.15 32 | 33 | # Number of elite parents to mate 34 | num_elite_parents 2 35 | 36 | # Total number of parents to mate 37 | total_parents 3 38 | 39 | # Bias function to be used to rank the parents 40 | bias_type LOGINVERSE 41 | 42 | # Number of independent populations 43 | num_independent_populations 3 44 | 45 | # Number of pairs of chromosomes to be tested to path relinking. 46 | pr_number_pairs 0 47 | 48 | # Mininum distance between chromosomes to path-relink 49 | pr_minimum_distance 0.15 50 | 51 | # Path relink type 52 | pr_type PERMUTATION 53 | 54 | # Individual selection to path-relink 55 | pr_selection RANDOMELITE 56 | 57 | # Defines the block size based on the size of the population 58 | alpha_block_size 1.0 59 | 60 | # Percentage/path size 61 | pr_percentage 1.0 62 | 63 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 64 | exchange_interval 200 65 | 66 | # Number of elite chromosomes exchanged from each population 67 | num_exchange_indivuduals 2 68 | 69 | # Interval at which the populations are reset (0 means no reset) 70 | reset_interval 600 71 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/unknown_param.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # unknown_param.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_sizee 500 27 | 28 | # Elite percentage 29 | elite_percentage 0.30 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | #bias_type LOGINVERSE 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type PERMUTATION 54 | 55 | # Individual selection to path-relink 56 | pr_selection RANDOMELITE 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/wrong_bias_function.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # wrong_bias_function.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_size 500 27 | 28 | # Elite percentage 29 | elite_percentage 0.30 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | bias_type LOGINVRSE 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type PERMUTATION 54 | 55 | # Individual selection to path-relink 56 | pr_selection RANDOMELITE 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/wrong_pr_selection.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # wrong_pr_selection.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_size 500 27 | 28 | # Elite percentage 29 | elite_percentage 0.30 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | bias_type LOGINVERSE 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type PERMUTATION 54 | 55 | # Individual selection to path-relink 56 | pr_selection WORSEONES 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/wrong_pr_type.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # wrong_pr_type.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_size 500 27 | 28 | # Elite percentage 29 | elite_percentage 0.30 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | bias_type LOGINVERSE 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type SCRAMBLED 54 | 55 | # Individual selection to path-relink 56 | pr_selection RANDOMELITE 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/configuration_files/wrong_type.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # wrong_type.conf: example of a configuration file for BRKGA-MP-IPR 3 | # frameworks. 4 | # 5 | # (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | # 7 | # This code is released under LICENSE.md. 8 | # 9 | # Created on: Dec 28, 2018 by ceandrade 10 | # Last update: Jan 07, 2019 by ceandrade 11 | # 12 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | # POSSIBILITY OF SUCH DAMAGE. 23 | ############################################################################### 24 | 25 | # Population size 26 | population_size 500.123 27 | 28 | # Elite percentage 29 | elite_percentage 0.3 30 | 31 | # Mutants percentage 32 | mutants_percentage 0.15 33 | 34 | # Number of elite parents to mate 35 | num_elite_parents 2 36 | 37 | # Total number of parents to mate 38 | total_parents 3 39 | 40 | # Bias function to be used to rank the parents 41 | bias_type LOGINVERSE 42 | 43 | # Number of independent populations 44 | num_independent_populations 3 45 | 46 | # Number of pairs of chromosomes to be tested to path relinking. 47 | pr_number_pairs 0 48 | 49 | # Mininum distance between chromosomes to path-relink 50 | pr_minimum_distance 0.15 51 | 52 | # Path relink type 53 | pr_type PERMUTATION 54 | 55 | # Individual selection to path-relink 56 | pr_selection RANDOMELITE 57 | 58 | # Defines the block size based on the size of the population 59 | alpha_block_size 1.0 60 | 61 | # Percentage/path size 62 | pr_percentage 1.0 63 | 64 | # Interval at which elite chromosomes are exchanged (0 means no exchange) 65 | exchange_interval 200 66 | 67 | # Number of elite chromosomes exchanged from each population 68 | num_exchange_indivuduals 2 69 | 70 | # Interval at which the populations are reset (0 means no reset) 71 | reset_interval 600 72 | -------------------------------------------------------------------------------- /tests/resources/solutions/best_solution1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/solutions/best_solution1.pickle -------------------------------------------------------------------------------- /tests/resources/solutions/best_solution2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/solutions/best_solution2.pickle -------------------------------------------------------------------------------- /tests/resources/solutions/best_solution3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/solutions/best_solution3.pickle -------------------------------------------------------------------------------- /tests/resources/solutions/best_solution4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/solutions/best_solution4.pickle -------------------------------------------------------------------------------- /tests/resources/solutions/best_solution5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/solutions/best_solution5.pickle -------------------------------------------------------------------------------- /tests/resources/states/state1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/states/state1.pickle -------------------------------------------------------------------------------- /tests/resources/states/state2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/states/state2.pickle -------------------------------------------------------------------------------- /tests/resources/states/state3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/states/state3.pickle -------------------------------------------------------------------------------- /tests/resources/states/state4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/states/state4.pickle -------------------------------------------------------------------------------- /tests/resources/states/state5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceandrade/brkga_mp_ipr_python/ce2984cd29ff6c53b82848d3f679ca9fe164cc0d/tests/resources/states/state5.pickle -------------------------------------------------------------------------------- /tests/test_1_types.py: -------------------------------------------------------------------------------- 1 | """ 2 | test_types.py: Tests for types. 3 | 4 | (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | 6 | This code is released under LICENSE.md. 7 | 8 | Created on: Nov 06, 2019 by ceandrade 9 | Last update: Nov 13, 2019 by ceandrade 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGE. 22 | """ 23 | 24 | import unittest 25 | from brkga_mp_ipr.types import * 26 | 27 | class Test(unittest.TestCase): 28 | """ 29 | Test units for types. 30 | """ 31 | 32 | ########################################################################### 33 | 34 | def setUp(self): 35 | """ 36 | Sets up some configurations. 37 | """ 38 | 39 | Test.maxDiff = None 40 | 41 | ########################################################################### 42 | 43 | def test_BrkgaParams(self): 44 | """ 45 | Tests BrkgaParams constructor. 46 | """ 47 | 48 | brkga_params = BrkgaParams() 49 | 50 | self.assertEqual(brkga_params.population_size, 0) 51 | self.assertEqual(brkga_params.elite_percentage, 0.0) 52 | self.assertEqual(brkga_params.mutants_percentage, 0.0) 53 | self.assertEqual(brkga_params.num_elite_parents, 0) 54 | self.assertEqual(brkga_params.total_parents, 0) 55 | self.assertEqual(brkga_params.bias_type, BiasFunctionType.CONSTANT) 56 | self.assertEqual(brkga_params.num_independent_populations, 0) 57 | self.assertEqual(brkga_params.pr_number_pairs, 0) 58 | self.assertEqual(brkga_params.pr_minimum_distance, 0.0) 59 | self.assertEqual(brkga_params.pr_type, PathRelinkingType.DIRECT) 60 | self.assertEqual(brkga_params.pr_selection, PathRelinkingSelection.BESTSOLUTION) 61 | self.assertEqual(brkga_params.alpha_block_size, 0.0) 62 | self.assertEqual(brkga_params.pr_percentage, 0.0) 63 | 64 | ########################################################################### 65 | 66 | def test_ExternalControlParams(self): 67 | """ 68 | Tests ExternalControlParams constructor. 69 | """ 70 | 71 | extra_params = ExternalControlParams() 72 | self.assertEqual(extra_params.exchange_interval, 0) 73 | self.assertEqual(extra_params.num_exchange_indivuduals, 0) 74 | self.assertEqual(extra_params.reset_interval, 0) 75 | 76 | extra_params = ExternalControlParams(10, 20, 30) 77 | self.assertEqual(extra_params.exchange_interval, 10) 78 | self.assertEqual(extra_params.num_exchange_indivuduals, 20) 79 | self.assertEqual(extra_params.reset_interval, 30) 80 | 81 | extra_params = ExternalControlParams( 82 | exchange_interval = 30, 83 | num_exchange_indivuduals = 10, 84 | reset_interval = 20 85 | ) 86 | self.assertEqual(extra_params.exchange_interval, 30) 87 | self.assertEqual(extra_params.num_exchange_indivuduals, 10) 88 | self.assertEqual(extra_params.reset_interval, 20) 89 | 90 | ########################################################################### 91 | 92 | def test_BaseChromosome(self): 93 | """ 94 | Tests BaseChromosome constructor. 95 | """ 96 | 97 | tmp = BaseChromosome([1, 2, 3]) 98 | self.assertEqual(tmp, [1, 2, 3]) 99 | 100 | class SchedulingChromosome(BaseChromosome): 101 | def __init__(self, value): 102 | super().__init__(value) 103 | self.makespan = 0.0 104 | self.total_completion_time = 0.0 105 | 106 | tmp = SchedulingChromosome([1, 2, 3]) 107 | self.assertEqual(tmp, [1, 2, 3]) 108 | self.assertEqual(tmp.makespan, 0.0) 109 | self.assertEqual(tmp.total_completion_time, 0.0) 110 | 111 | ########################################################################### 112 | 113 | def test_Population(self): 114 | """ 115 | Tests BaseChromosome constructor. 116 | """ 117 | 118 | pop1 = Population() 119 | self.assertEqual(pop1.chromosomes, list()) 120 | self.assertEqual(pop1.fitness, list()) 121 | 122 | pop1.chromosomes = [1, 2, 3] 123 | pop1.fitness = [(1, 10), (2, 20), (3, 30)] 124 | pop2 = Population(pop1) 125 | 126 | self.assertIsNot(pop1, pop2) 127 | self.assertEqual(pop1.chromosomes, pop2.chromosomes) 128 | self.assertIsNot(pop1.chromosomes, pop2.chromosomes) 129 | self.assertEqual(pop1.fitness, pop2.fitness) 130 | self.assertIsNot(pop1.fitness, pop2.fitness) 131 | 132 | 133 | ############################################################################### 134 | 135 | if __name__ == "__main__": 136 | unittest.main() 137 | -------------------------------------------------------------------------------- /tests/test_2_types_io.py: -------------------------------------------------------------------------------- 1 | """ 2 | test_types_io.py: Tests for I/O functions. 3 | 4 | (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | 6 | This code is released under LICENSE.md. 7 | 8 | Created on: Nov 06, 2019 by ceandrade 9 | Last update: Nov 07, 2019 by ceandrade 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGE. 22 | """ 23 | 24 | import tempfile 25 | import unittest 26 | 27 | from brkga_mp_ipr.types import * 28 | from brkga_mp_ipr.types_io import * 29 | from tests.paths_constants import * 30 | 31 | class Test(unittest.TestCase): 32 | """ 33 | Test units for types I/O functions. 34 | """ 35 | 36 | ########################################################################### 37 | 38 | def setUp(self): 39 | """ 40 | Set up some configurations. 41 | """ 42 | 43 | Test.maxDiff = None 44 | 45 | ########################################################################### 46 | 47 | def test_load_configuration(self): 48 | """ 49 | Test load functions. 50 | """ 51 | 52 | self.assertRaises(IsADirectoryError, load_configuration, ".") 53 | self.assertRaises(FileNotFoundError, load_configuration, "") 54 | 55 | filename = os.path.join(CONFIG_DIR, "empty.conf") 56 | with self.assertRaises(LoadError) as context: 57 | load_configuration(filename) 58 | self.assertEqual(str(context.exception).strip(), 59 | f"Cannot read {filename}") 60 | 61 | filename = os.path.join(CONFIG_DIR, "unknown_param.conf") 62 | with self.assertRaises(LoadError) as context: 63 | load_configuration(filename) 64 | self.assertEqual(str(context.exception).strip(), 65 | "Line 25: parameter 'population_sizee' unknown") 66 | 67 | filename = os.path.join(CONFIG_DIR, "missing_value.conf") 68 | with self.assertRaises(LoadError) as context: 69 | load_configuration(filename) 70 | self.assertEqual(str(context.exception).strip(), 71 | "Line 25: missing parameter or value") 72 | 73 | filename = os.path.join(CONFIG_DIR, "wrong_type.conf") 74 | with self.assertRaises(LoadError) as context: 75 | load_configuration(filename) 76 | self.assertEqual(str(context.exception).strip(), 77 | "Line 25: invalid value for 'population_size': 500.123") 78 | 79 | filename = os.path.join(CONFIG_DIR, "wrong_bias_function.conf") 80 | with self.assertRaises(LoadError) as context: 81 | load_configuration(filename) 82 | self.assertEqual(str(context.exception).strip(), 83 | "Line 40: invalid value for 'bias_type': loginvrse") 84 | 85 | filename = os.path.join(CONFIG_DIR, "wrong_pr_selection.conf") 86 | with self.assertRaises(LoadError) as context: 87 | load_configuration(filename) 88 | self.assertEqual(str(context.exception).strip(), 89 | "Line 55: invalid value for 'pr_selection': worseones") 90 | 91 | filename = os.path.join(CONFIG_DIR, "missing_param.conf") 92 | with self.assertRaises(LoadError) as context: 93 | load_configuration(filename) 94 | self.assertEqual(str(context.exception).strip(), 95 | "Missing parameters: population_size, mutants_percentage, total_parents, bias_type") 96 | 97 | brkga_params, control_params = \ 98 | load_configuration(os.path.join(CONFIG_DIR, "regular.conf")) 99 | 100 | self.assertEqual(brkga_params.population_size, 500) 101 | self.assertEqual(brkga_params.elite_percentage, 0.30) 102 | self.assertEqual(brkga_params.mutants_percentage, 0.15) 103 | self.assertEqual(brkga_params.num_elite_parents, 2) 104 | self.assertEqual(brkga_params.total_parents, 3) 105 | self.assertEqual(brkga_params.bias_type, BiasFunctionType.LOGINVERSE) 106 | self.assertEqual(brkga_params.num_independent_populations, 3) 107 | self.assertEqual(brkga_params.pr_number_pairs, 0) 108 | self.assertEqual(brkga_params.pr_minimum_distance, 0.15) 109 | self.assertEqual(brkga_params.pr_type, PathRelinkingType.PERMUTATION) 110 | self.assertEqual(brkga_params.pr_selection, PathRelinkingSelection.RANDOMELITE) 111 | self.assertEqual(brkga_params.alpha_block_size, 1.0) 112 | self.assertEqual(brkga_params.pr_percentage, 1.0) 113 | self.assertEqual(control_params.exchange_interval, 200) 114 | self.assertEqual(control_params.num_exchange_indivuduals, 2) 115 | self.assertEqual(control_params.reset_interval, 600) 116 | 117 | ########################################################################### 118 | 119 | def test_write_configuration(self): 120 | """ 121 | Test write functions. 122 | """ 123 | 124 | ######################### 125 | # From config file 126 | ######################### 127 | 128 | brkga_params, control_params = \ 129 | load_configuration(os.path.join(CONFIG_DIR, "regular.conf")) 130 | 131 | self.assertRaises(PermissionError, write_configuration, 132 | "/invalid", brkga_params, control_params) 133 | 134 | self.assertRaises(IsADirectoryError, write_configuration, 135 | ".", brkga_params, control_params) 136 | 137 | tmp = tempfile.NamedTemporaryFile(mode="r") 138 | write_configuration(tmp.name, brkga_params, control_params) 139 | 140 | tmp.seek(0) 141 | result = tmp.read().lower() 142 | tmp.close() 143 | 144 | standard = """population_size 500 145 | elite_percentage 0.3 146 | mutants_percentage 0.15 147 | num_elite_parents 2 148 | total_parents 3 149 | bias_type loginverse 150 | num_independent_populations 3 151 | pr_number_pairs 0 152 | pr_minimum_distance 0.15 153 | pr_type permutation 154 | pr_selection randomelite 155 | alpha_block_size 1.0 156 | pr_percentage 1.0 157 | exchange_interval 200 158 | num_exchange_indivuduals 2 159 | reset_interval 600 160 | """ 161 | self.assertEqual(result, standard) 162 | 163 | ######################### 164 | # TODO: From direct building 165 | ######################### 166 | 167 | ############################################################################### 168 | 169 | if __name__ == "__main__": 170 | unittest.main() 171 | -------------------------------------------------------------------------------- /tests/test_5_algorithm_population_manipulation.py: -------------------------------------------------------------------------------- 1 | """ 2 | test_algorithm_population_manipulation.py: Tests the populaiton manipulation 3 | methods. 4 | 5 | (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 6 | 7 | This code is released under LICENSE.md. 8 | 9 | Created on: Nov 08, 2019 by ceandrade 10 | Last update: Nov 13, 2019 by ceandrade 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 16 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | POSSIBILITY OF SUCH DAMAGE. 23 | """ 24 | 25 | from copy import deepcopy 26 | import math 27 | from random import Random 28 | import unittest 29 | 30 | from brkga_mp_ipr.algorithm import BrkgaMpIpr 31 | from brkga_mp_ipr.enums import * 32 | from brkga_mp_ipr.types import BaseChromosome, BrkgaParams 33 | from brkga_mp_ipr.types_io import load_configuration 34 | 35 | from tests.instance import Instance 36 | from tests.decoders import SumDecode, RankDecode 37 | from tests.paths_constants import * 38 | 39 | class Test(unittest.TestCase): 40 | """ 41 | Test units for types. 42 | """ 43 | 44 | ########################################################################### 45 | 46 | def setUp(self): 47 | """ 48 | Sets up some configurations. 49 | """ 50 | 51 | Test.maxDiff = None 52 | 53 | self.chromosome_size = 100 54 | 55 | self.default_brkga_params = BrkgaParams() 56 | self.default_brkga_params.population_size = 10 57 | self.default_brkga_params.elite_percentage = 0.3 58 | self.default_brkga_params.mutants_percentage = 0.1 59 | self.default_brkga_params.num_elite_parents = 1 60 | self.default_brkga_params.total_parents = 2 61 | self.default_brkga_params.bias_type = BiasFunctionType.LOGINVERSE 62 | self.default_brkga_params.num_independent_populations = 3 63 | self.default_brkga_params.pr_number_pairs = 0 64 | self.default_brkga_params.pr_minimum_distance = 0.0 65 | self.default_brkga_params.pr_type = PathRelinkingType.DIRECT 66 | self.default_brkga_params.pr_selection = PathRelinkingSelection.BESTSOLUTION 67 | self.default_brkga_params.alpha_block_size = 1.0 68 | self.default_brkga_params.pr_percentage = 1.0 69 | 70 | self.instance = Instance(self.chromosome_size) 71 | self.sum_decoder = SumDecode(self.instance) 72 | self.rank_decoder = RankDecode(self.instance) 73 | 74 | self.default_param_values = { 75 | "decoder": self.sum_decoder, 76 | "sense": Sense.MAXIMIZE, 77 | "seed": 98747382473209, 78 | "chromosome_size": self.chromosome_size, 79 | "params": self.default_brkga_params, 80 | "evolutionary_mechanism_on": True, 81 | "chrmosome_type": BaseChromosome 82 | } 83 | 84 | ########################################################################### 85 | 86 | def test_exchange_elite(self): 87 | """ 88 | Tests exchange_elite() method. 89 | """ 90 | 91 | param_values = deepcopy(self.default_param_values) 92 | brkga = BrkgaMpIpr(**param_values) 93 | self.assertRaises(NotImplementedError, brkga.exchange_elite, 0) 94 | 95 | ########################################################################### 96 | 97 | def test_reset(self): 98 | """ 99 | Tests reset() method. 100 | """ 101 | 102 | param_values = deepcopy(self.default_param_values) 103 | params = param_values["params"] 104 | brkga = BrkgaMpIpr(**param_values) 105 | 106 | with self.assertRaises(RuntimeError) as context: 107 | brkga.reset() 108 | self.assertEqual(str(context.exception).strip(), 109 | "The algorithm hasn't been initialized. " 110 | "Call 'initialize()' before 'reset()'") 111 | 112 | brkga.initialize() 113 | 114 | # Create a local RNG and advance it until the same state as the 115 | # internal BRKGA RNG after initialization. 116 | local_rng = Random(param_values["seed"]) 117 | skip = 1000 + params.num_independent_populations * \ 118 | params.population_size * brkga.chromosome_size 119 | for _ in range(skip): 120 | local_rng.random() 121 | 122 | # Assert the both generators are in the same state. 123 | self.assertEqual(brkga._rng.getstate(), local_rng.getstate()) 124 | 125 | # Create a local chromosome and applied the decoder on it. 126 | local_chr = BaseChromosome([ 127 | local_rng.random() for _ in range(param_values["chromosome_size"]) 128 | ]) 129 | param_values["decoder"].decode(local_chr, rewrite=True) 130 | 131 | # Reset and test the first individual. 132 | brkga.reset() 133 | self.assertEqual(brkga._current_populations[0].chromosomes[0], 134 | local_chr) 135 | 136 | # After reset, the reset phase flag should be deactivated. 137 | self.assertFalse(brkga._reset_phase) 138 | 139 | ########################################################################### 140 | 141 | def test_shake(self): 142 | """ 143 | Tests shake() method. 144 | """ 145 | 146 | param_values = deepcopy(self.default_param_values) 147 | brkga = BrkgaMpIpr(**param_values) 148 | self.assertRaises(NotImplementedError, brkga.shake, 0, 149 | ShakingType.SWAP, 0) 150 | 151 | ########################################################################### 152 | 153 | def test_inject_chromosome(self): 154 | """ 155 | Tests inject_chromosome() method. 156 | """ 157 | 158 | param_values = deepcopy(self.default_param_values) 159 | brkga = BrkgaMpIpr(**param_values) 160 | self.assertRaises(NotImplementedError, brkga.inject_chromosome, 161 | BaseChromosome(), 0, 0, 0) 162 | 163 | 164 | ############################################################################### 165 | 166 | if __name__ == "__main__": 167 | unittest.main() -------------------------------------------------------------------------------- /tests/test_7_algorithm_path_relink_methods.py: -------------------------------------------------------------------------------- 1 | """ 2 | test_algorithm_path_relink_methods.py.py: Tests the path relink methods. 3 | 4 | (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 5 | 6 | This code is released under LICENSE.md. 7 | 8 | Created on: Nov 08, 2019 by ceandrade 9 | Last update: Nov 08, 2019 by ceandrade 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 15 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGE. 22 | """ 23 | 24 | from copy import deepcopy 25 | import math 26 | from random import Random 27 | import unittest 28 | 29 | from brkga_mp_ipr.algorithm import BrkgaMpIpr 30 | from brkga_mp_ipr.enums import * 31 | from brkga_mp_ipr.types import BaseChromosome, BrkgaParams 32 | from brkga_mp_ipr.types_io import load_configuration 33 | 34 | from tests.instance import Instance 35 | from tests.decoders import SumDecode, RankDecode 36 | from tests.paths_constants import * 37 | 38 | ############################################################################### 39 | 40 | class Test(unittest.TestCase): 41 | """ 42 | Test units for path relink methods. 43 | """ 44 | 45 | ########################################################################### 46 | 47 | def setUp(self): 48 | """ 49 | Sets up some configurations. 50 | """ 51 | 52 | Test.maxDiff = None 53 | 54 | self.chromosome_size = 100 55 | 56 | self.default_brkga_params = BrkgaParams() 57 | self.default_brkga_params.population_size = 10 58 | self.default_brkga_params.elite_percentage = 0.3 59 | self.default_brkga_params.mutants_percentage = 0.1 60 | self.default_brkga_params.num_elite_parents = 1 61 | self.default_brkga_params.total_parents = 2 62 | self.default_brkga_params.bias_type = BiasFunctionType.LOGINVERSE 63 | self.default_brkga_params.num_independent_populations = 3 64 | self.default_brkga_params.pr_number_pairs = 0 65 | self.default_brkga_params.pr_minimum_distance = 0.0 66 | self.default_brkga_params.pr_type = PathRelinkingType.DIRECT 67 | self.default_brkga_params.pr_selection = PathRelinkingSelection.BESTSOLUTION 68 | self.default_brkga_params.alpha_block_size = 1.0 69 | self.default_brkga_params.pr_percentage = 1.0 70 | 71 | self.instance = Instance(self.chromosome_size) 72 | self.sum_decoder = SumDecode(self.instance) 73 | self.rank_decoder = RankDecode(self.instance) 74 | 75 | self.default_param_values = { 76 | "decoder": self.sum_decoder, 77 | "sense": Sense.MAXIMIZE, 78 | "seed": 98747382473209, 79 | "chromosome_size": self.chromosome_size, 80 | "params": self.default_brkga_params, 81 | "evolutionary_mechanism_on": True, 82 | "chrmosome_type": BaseChromosome 83 | } 84 | 85 | ########################################################################### 86 | 87 | def test__direct_path_relink(self): 88 | """ 89 | Tests _direct_path_relink() method. 90 | """ 91 | 92 | param_values = deepcopy(self.default_param_values) 93 | brkga = BrkgaMpIpr(**param_values) 94 | self.assertRaises(NotImplementedError, brkga._direct_path_relink, 95 | None, None, None, None, 0, 0, 0.0) 96 | 97 | ########################################################################### 98 | 99 | def test__permutation_based_path_relink(self): 100 | """ 101 | Tests _permutation_based_path_relink() method. 102 | """ 103 | 104 | param_values = deepcopy(self.default_param_values) 105 | brkga = BrkgaMpIpr(**param_values) 106 | self.assertRaises(NotImplementedError, brkga._permutation_based_path_relink, 107 | None, None, None, None, 0, 0, 0.0) 108 | 109 | ########################################################################### 110 | 111 | def test_path_relink(self): 112 | """ 113 | Tests path_relink() method. 114 | """ 115 | 116 | param_values = deepcopy(self.default_param_values) 117 | brkga = BrkgaMpIpr(**param_values) 118 | self.assertRaises(NotImplementedError, brkga.path_relink, 119 | None, None, None, 0, 0.0) 120 | 121 | ############################################################################### 122 | 123 | if __name__ == "__main__": 124 | unittest.main() -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | ; tox.ini: Configurations for automatic testing of BRKGA-MP-IPR. 2 | ; 3 | ; (c) Copyright 2019, Carlos Eduardo de Andrade. All Rights Reserved. 4 | ; 5 | ; This code is released under LICENSE.md. 6 | ; 7 | ; Created on: Nov 18, 2019 by ceandrade 8 | ; Last update: Nov 26, 2019 by ceandrade 9 | ; 10 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 11 | ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12 | ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13 | ; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 14 | ; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 15 | ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 16 | ; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 17 | ; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 18 | ; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 19 | ; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 20 | ; POSSIBILITY OF SUCH DAMAGE. 21 | 22 | [tox] 23 | envlist = py37 24 | 25 | [testenv] 26 | passenv = 27 | TOXENV 28 | CI 29 | TRAVIS 30 | TRAVIS_* 31 | CODECOV_* 32 | 33 | deps = 34 | dill 35 | pytest 36 | pytest-cov 37 | coverage 38 | codecov>=1.4.0 39 | 40 | ;commands = codecov -e TOXENV 41 | ;commands = {posargs:pytest} 42 | commands = 43 | pytest 44 | ;coverage run --source=brkga_mp_ipr setup.py test 45 | ;coveralls 46 | 47 | [pytest] 48 | addopts = -v --show-capture all --cov-report=xml --cov=brkga_mp_ipr tests/ 49 | console_output_style = count 50 | --------------------------------------------------------------------------------