├── .clang-format ├── .cmake-format ├── .github ├── dependabot.yml └── workflows │ └── wheels.yml ├── .gitignore ├── .readthedocs.yaml ├── CMakeLists.txt ├── CONTRIBUTING.md ├── README.md ├── bindings ├── CMakeLists.txt ├── cmake │ └── CPM.cmake ├── include │ └── routingblocks_bindings │ │ ├── Evaluation.h │ │ ├── Instance.hpp │ │ ├── Labeling.h │ │ ├── LocalSearch.h │ │ ├── Operators.h │ │ ├── Solution.h │ │ ├── binding_helpers.hpp │ │ ├── large_neighborhood.h │ │ ├── specializations │ │ ├── ADPTW.h │ │ └── NIFTW.h │ │ └── utility.h ├── src │ ├── Evaluation.cpp │ ├── Instance.cpp │ ├── Labeling.cpp │ ├── LocalSearch.cpp │ ├── Operators.cpp │ ├── Solution.cpp │ ├── bindings.cpp │ ├── large_neighborhood.cpp │ ├── specializations │ │ ├── ADPTW.cpp │ │ └── NIFTW.cpp │ └── utility.cpp └── stubs │ ├── _adptw.pyi │ ├── _alns.pyi │ ├── _alns_operators.pyi │ ├── _arc.pyi │ ├── _evaluation.pyi │ ├── _frvcp.pyi │ ├── _insertion_cache.pyi │ ├── _instance.pyi │ ├── _local_search.pyi │ ├── _niftw.pyi │ ├── _node.pyi │ ├── _node_location.pyi │ ├── _random.pyi │ ├── _removal_cache.pyi │ ├── _route.pyi │ ├── _solution.pyi │ ├── _types.pyi │ └── _vertex.pyi ├── docs ├── make.bat └── source │ ├── adptw.rst │ ├── alternatives.rst │ ├── auxilliary.rst │ ├── conf.py │ ├── contributing.rst │ ├── custom_operators.rst │ ├── custom_problem_settings.rst │ ├── development.rst │ ├── evaluation.rst │ ├── exact_facility_placement.rst │ ├── examples.rst │ ├── full_api.rst │ ├── getting_started.rst │ ├── img │ └── auxilliary_graph.png │ ├── index.rst │ ├── instance.rst │ ├── localsearch.rst │ ├── metaheuristic_components.rst │ ├── niftw.rst │ ├── references.bib │ ├── references.rst │ └── solution.rst ├── examples ├── README.md ├── alns │ ├── __init__.py │ ├── __main__.py │ ├── alns.py │ └── parsing.py ├── evrptw │ ├── README.md │ ├── __init__.py │ ├── __main__.py │ ├── alns.py │ ├── config.json │ ├── instance │ │ ├── __init__.py │ │ ├── interface.py │ │ ├── models.py │ │ └── parsing.py │ ├── instances │ │ └── evrptw │ │ │ ├── 5 │ │ │ ├── c101C5.txt │ │ │ ├── c103C5.txt │ │ │ ├── c206C5.txt │ │ │ ├── c208C5.txt │ │ │ ├── r104C5.txt │ │ │ ├── r105C5.txt │ │ │ ├── r202C5.txt │ │ │ ├── r203C5.txt │ │ │ ├── rc105C5.txt │ │ │ ├── rc108C5.txt │ │ │ ├── rc204C5.txt │ │ │ └── rc208C5.txt │ │ │ ├── 10 │ │ │ ├── c101C10.txt │ │ │ ├── c104C10.txt │ │ │ ├── c202C10.txt │ │ │ ├── c205C10.txt │ │ │ ├── r102C10.txt │ │ │ ├── r103C10.txt │ │ │ ├── r201C10.txt │ │ │ ├── r203C10.txt │ │ │ ├── rc102C10.txt │ │ │ ├── rc108C10.txt │ │ │ ├── rc201C10.txt │ │ │ └── rc205C10.txt │ │ │ ├── 15 │ │ │ ├── c103C15.txt │ │ │ ├── c106C15.txt │ │ │ ├── c202C15.txt │ │ │ ├── c208C15.txt │ │ │ ├── r102C15.txt │ │ │ ├── r105C15.txt │ │ │ ├── r202C15.txt │ │ │ ├── r209C15.txt │ │ │ ├── rc103C15.txt │ │ │ ├── rc108C15.txt │ │ │ ├── rc202C15.txt │ │ │ └── rc204C15.txt │ │ │ ├── 100 │ │ │ ├── c101_21.txt │ │ │ ├── c102_21.txt │ │ │ ├── c103_21.txt │ │ │ ├── c104_21.txt │ │ │ ├── c105_21.txt │ │ │ ├── c106_21.txt │ │ │ ├── c107_21.txt │ │ │ ├── c108_21.txt │ │ │ ├── c109_21.txt │ │ │ ├── c201_21.txt │ │ │ ├── c202_21.txt │ │ │ ├── c203_21.txt │ │ │ ├── c204_21.txt │ │ │ ├── c205_21.txt │ │ │ ├── c206_21.txt │ │ │ ├── c207_21.txt │ │ │ ├── c208_21.txt │ │ │ ├── r101_21.txt │ │ │ ├── r102_21.txt │ │ │ ├── r103_21.txt │ │ │ ├── r104_21.txt │ │ │ ├── r105_21.txt │ │ │ ├── r106_21.txt │ │ │ ├── r107_21.txt │ │ │ ├── r108_21.txt │ │ │ ├── r109_21.txt │ │ │ ├── r110_21.txt │ │ │ ├── r111_21.txt │ │ │ ├── r112_21.txt │ │ │ ├── r201_21.txt │ │ │ ├── r202_21.txt │ │ │ ├── r203_21.txt │ │ │ ├── r204_21.txt │ │ │ ├── r205_21.txt │ │ │ ├── r206_21.txt │ │ │ ├── r207_21.txt │ │ │ ├── r208_21.txt │ │ │ ├── r209_21.txt │ │ │ ├── r210_21.txt │ │ │ ├── r211_21.txt │ │ │ ├── rc101_21.txt │ │ │ ├── rc102_21.txt │ │ │ ├── rc103_21.txt │ │ │ ├── rc104_21.txt │ │ │ ├── rc105_21.txt │ │ │ ├── rc106_21.txt │ │ │ ├── rc107_21.txt │ │ │ ├── rc108_21.txt │ │ │ ├── rc201_21.txt │ │ │ ├── rc202_21.txt │ │ │ ├── rc203_21.txt │ │ │ ├── rc204_21.txt │ │ │ ├── rc205_21.txt │ │ │ ├── rc206_21.txt │ │ │ ├── rc207_21.txt │ │ │ └── rc208_21.txt │ │ │ └── README.txt │ ├── operators │ │ ├── ShawMoveSelector.py │ │ ├── ShawRelatedness.py │ │ ├── SpatioTemporalRelatedness.py │ │ └── __init__.py │ ├── parameters.py │ ├── requirements.txt │ └── utility │ │ ├── __init__.py │ │ └── algorithms.py └── ils │ ├── __init__.py │ ├── __main__.py │ ├── ils.py │ └── parsing.py ├── native ├── CMakeLists.txt ├── cmake │ ├── CPM.cmake │ └── tools.cmake ├── include │ └── routingblocks │ │ ├── ADPTWEvaluation.h │ │ ├── FRVCP.h │ │ ├── Instance.h │ │ ├── LocalSearch.h │ │ ├── NIFTWEvaluation.h │ │ ├── Solution.h │ │ ├── adaptive_large_neighborhood.hpp │ │ ├── arc.h │ │ ├── evaluation.h │ │ ├── insertion_cache.h │ │ ├── lns_operators.h │ │ ├── node.h │ │ ├── operators.h │ │ ├── operators │ │ ├── InsertStationOperator.h │ │ ├── InterRouteTwoOptOperator.h │ │ ├── RemoveStationOperator.h │ │ └── SwapOperator.h │ │ ├── removal_cache.h │ │ ├── types.h │ │ ├── utility │ │ ├── adaptive_priority_list.h │ │ ├── algorithms.h │ │ ├── arc_set.h │ │ ├── heap.h │ │ ├── iterator_pair.h │ │ └── random.h │ │ └── vertex.h ├── lib │ ├── CMakeLists.txt │ ├── dynamic_bitset │ │ ├── CMakeLists.txt │ │ ├── LICENSE.txt │ │ └── dynamic_bitset │ │ │ ├── dynamic_bitset.hpp │ │ │ └── libpopcnt.h │ ├── small_vector │ │ ├── CMakeLists.txt │ │ ├── LICENSE.txt │ │ └── small_vector │ │ │ └── small_vector.hpp │ └── xoshiro │ │ ├── CMakeLists.txt │ │ ├── LICENSE.txt │ │ └── xoshiro │ │ └── xoshiro.h ├── src │ ├── ADPTWEvaluation.cpp │ ├── FRVCP.cpp │ ├── Instance.cpp │ ├── LocalSearch.cpp │ ├── NIFTWEvaluation.cpp │ ├── Solution.cpp │ ├── adaptive_large_neighborbood.cpp │ ├── lns_operators.cpp │ ├── node.cpp │ └── operators │ │ ├── InsertStationOperator.cpp │ │ └── InterRouteTwoOptOperator.cpp └── test │ ├── CMakeLists.txt │ └── src │ └── dummy.cpp ├── pyproject.toml ├── routingblocks ├── __init__.py ├── adptw │ └── __init__.py ├── large_neighborhood.py ├── niftw │ └── __init__.py ├── operators │ ├── __init__.py │ ├── best_insert.py │ ├── cluster_removal.py │ ├── move_selectors.py │ ├── related_removal.py │ ├── route_removal.py │ ├── station_vicinity_removal.py │ └── worst_removal.py └── utility │ ├── __init__.py │ └── instance_builder.py └── test └── tests ├── benchmarks ├── __init__.py ├── reference │ ├── insertion_cache.py │ └── removal_cache.py ├── test_benchmark_frvcp.py ├── test_benchmark_local_search.py ├── test_benchmark_removal_cache.py └── test_benchmark_route_update.py ├── conftest.py ├── fixtures ├── __init__.py ├── data │ ├── c101C5.txt │ ├── c101_21.txt │ ├── r101_21.txt │ ├── r201_21.txt │ └── rc101_21.txt └── mock_evaluation.py ├── helpers ├── __init__.py ├── interface.py ├── models.py └── parsing.py ├── operators ├── __init__.py ├── test_cluster_removal.py ├── test_random_insertion.py ├── test_random_removal.py ├── test_related_removal.py ├── test_station_insertion.py ├── test_station_removal.py ├── test_station_vicinity_removal.py └── test_swap.py ├── test_evaluation.py ├── test_frvcp.py ├── test_insertion_cache.py ├── test_instance.py ├── test_instance_builder.py ├── test_large_neighborhood.py ├── test_lns_helpers.py ├── test_local_search.py ├── test_move_selectors.py ├── test_node.py ├── test_removal_cache.py ├── test_route.py └── test_solution.py /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | AccessModifierOffset: '-2' 4 | AlignTrailingComments: 'true' 5 | AllowAllParametersOfDeclarationOnNextLine: 'false' 6 | AlwaysBreakTemplateDeclarations: 'No' 7 | BreakBeforeBraces: Attach 8 | ColumnLimit: '100' 9 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' 10 | IncludeBlocks: Regroup 11 | IndentPPDirectives: AfterHash 12 | IndentWidth: '4' 13 | NamespaceIndentation: All 14 | BreakBeforeBinaryOperators: All 15 | BreakBeforeTernaryOperators: 'true' 16 | ... 17 | -------------------------------------------------------------------------------- /.cmake-format: -------------------------------------------------------------------------------- 1 | format: 2 | tab_size: 2 3 | line_width: 100 4 | dangle_parens: true 5 | 6 | parse: 7 | additional_commands: 8 | cpmaddpackage: 9 | pargs: 10 | nargs: '*' 11 | flags: [] 12 | spelling: CPMAddPackage 13 | kwargs: &cpmaddpackagekwargs 14 | NAME: 1 15 | FORCE: 1 16 | VERSION: 1 17 | GIT_TAG: 1 18 | DOWNLOAD_ONLY: 1 19 | GITHUB_REPOSITORY: 1 20 | GITLAB_REPOSITORY: 1 21 | GIT_REPOSITORY: 1 22 | SVN_REPOSITORY: 1 23 | SVN_REVISION: 1 24 | SOURCE_DIR: 1 25 | DOWNLOAD_COMMAND: 1 26 | FIND_PACKAGE_ARGUMENTS: 1 27 | NO_CACHE: 1 28 | GIT_SHALLOW: 1 29 | URL: 1 30 | URL_HASH: 1 31 | URL_MD5: 1 32 | DOWNLOAD_NAME: 1 33 | DOWNLOAD_NO_EXTRACT: 1 34 | HTTP_USERNAME: 1 35 | HTTP_PASSWORD: 1 36 | OPTIONS: + 37 | cpmfindpackage: 38 | pargs: 39 | nargs: '*' 40 | flags: [] 41 | spelling: CPMFindPackage 42 | kwargs: *cpmaddpackagekwargs 43 | packageproject: 44 | pargs: 45 | nargs: '*' 46 | flags: [] 47 | spelling: packageProject 48 | kwargs: 49 | NAME: 1 50 | VERSION: 1 51 | NAMESPACE: 1 52 | INCLUDE_DIR: 1 53 | INCLUDE_DESTINATION: 1 54 | BINARY_DIR: 1 55 | COMPATIBILITY: 1 56 | VERSION_HEADER: 1 57 | DEPENDENCIES: + 58 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Maintain dependencies for GitHub Actions 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "daily" 8 | -------------------------------------------------------------------------------- /.github/workflows/wheels.yml: -------------------------------------------------------------------------------- 1 | name: Wheels 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | push: 7 | branches: 8 | - master 9 | release: 10 | types: 11 | - published 12 | 13 | concurrency: 14 | group: ${{ github.workflow }}-${{ github.ref }} 15 | cancel-in-progress: true 16 | 17 | jobs: 18 | build_sdist: 19 | name: Build SDist 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v3 23 | with: 24 | submodules: true 25 | 26 | - name: Build SDist 27 | run: pipx run build --sdist 28 | 29 | - name: Check metadata 30 | run: pipx run twine check dist/* 31 | 32 | - uses: actions/upload-artifact@v3 33 | with: 34 | path: dist/*.tar.gz 35 | 36 | 37 | build_wheels: 38 | name: Wheels on ${{ matrix.os }} 39 | runs-on: ${{ matrix.os }} 40 | strategy: 41 | fail-fast: false 42 | matrix: 43 | os: [ubuntu-latest, macos-latest, windows-latest] 44 | 45 | steps: 46 | - uses: actions/checkout@v3 47 | with: 48 | submodules: true 49 | 50 | - uses: pypa/cibuildwheel@v2.12.1 51 | env: 52 | CIBW_ARCHS_MACOS: universal2 53 | CIBW_ARCHS_WINDOWS: auto ARM64 54 | 55 | - name: Verify clean directory 56 | run: git diff --exit-code 57 | shell: bash 58 | 59 | - uses: actions/upload-artifact@v3 60 | with: 61 | path: wheelhouse/*.whl 62 | 63 | 64 | upload_all: 65 | name: Upload if release 66 | needs: [build_wheels, build_sdist] 67 | runs-on: ubuntu-latest 68 | if: github.event_name == 'release' && github.event.action == 'published' 69 | 70 | steps: 71 | - uses: actions/setup-python@v4 72 | with: 73 | python-version: "3.x" 74 | 75 | - uses: actions/download-artifact@v3 76 | with: 77 | name: artifact 78 | path: dist 79 | 80 | - uses: pypa/gh-action-pypi-publish@v1.8.3 81 | with: 82 | password: ${{ secrets.pypi_password }} 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .venv 3 | hgs 4 | docs/build/ 5 | dist 6 | 7 | # Python tests 8 | .pytest_cache 9 | .benchmarks 10 | __pycache__/ 11 | 12 | ### C++ template 13 | # Prerequisites 14 | *.d 15 | 16 | # Compiled Object files 17 | *.slo 18 | *.lo 19 | *.o 20 | *.obj 21 | 22 | # Precompiled Headers 23 | *.gch 24 | *.pch 25 | 26 | # Compiled Dynamic libraries 27 | *.so 28 | *.dylib 29 | *.dll 30 | 31 | # Fortran module files 32 | *.mod 33 | *.smod 34 | 35 | # Compiled Static libraries 36 | *.lai 37 | *.la 38 | *.a 39 | *.lib 40 | 41 | # Executables 42 | *.exe 43 | *.out 44 | *.app 45 | 46 | ### JetBrains template 47 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 48 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 49 | 50 | # User-specific stuff 51 | .idea/**/workspace.xml 52 | .idea/**/tasks.xml 53 | .idea/**/usage.statistics.xml 54 | .idea/**/dictionaries 55 | .idea/**/shelf 56 | 57 | # Generated files 58 | .idea/**/contentModel.xml 59 | 60 | # Sensitive or high-churn files 61 | .idea/**/dataSources/ 62 | .idea/**/dataSources.ids 63 | .idea/**/dataSources.local.xml 64 | .idea/**/sqlDataSources.xml 65 | .idea/**/dynamic.xml 66 | .idea/**/uiDesigner.xml 67 | .idea/**/dbnavigator.xml 68 | 69 | # Gradle 70 | .idea/**/gradle.xml 71 | .idea/**/libraries 72 | 73 | # Gradle and Maven with auto-import 74 | # When using Gradle or Maven with auto-import, you should exclude module files, 75 | # since they will be recreated, and may cause churn. Uncomment if using 76 | # auto-import. 77 | # .idea/artifacts 78 | # .idea/compiler.xml 79 | # .idea/jarRepositories.xml 80 | # .idea/modules.xml 81 | # .idea/*.iml 82 | # .idea/modules 83 | # *.iml 84 | # *.ipr 85 | 86 | # CMake 87 | cmake-build-*/ 88 | 89 | # Mongo Explorer plugin 90 | .idea/**/mongoSettings.xml 91 | 92 | # File-based project format 93 | *.iws 94 | 95 | # IntelliJ 96 | out/ 97 | 98 | # mpeltonen/sbt-idea plugin 99 | .idea_modules/ 100 | 101 | # JIRA plugin 102 | atlassian-ide-plugin.xml 103 | 104 | # Cursive Clojure plugin 105 | .idea/replstate.xml 106 | 107 | # Crashlytics plugin (for Android Studio and IntelliJ) 108 | com_crashlytics_export_strings.xml 109 | crashlytics.properties 110 | crashlytics-build.properties 111 | fabric.properties 112 | 113 | # Editor-based Rest Client 114 | .idea/httpRequests 115 | 116 | # Android studio 3.1+ serialized cache file 117 | .idea/caches/build_file_checksums.ser 118 | 119 | ### CMake template 120 | CMakeLists.txt.user 121 | CMakeCache.txt 122 | CMakeFiles 123 | CMakeScripts 124 | Testing 125 | Makefile 126 | cmake_install.cmake 127 | install_manifest.txt 128 | compile_commands.json 129 | CTestTestfile.cmake 130 | _deps 131 | 132 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | python: 4 | install: 5 | - method: pip 6 | path: . 7 | extra_requirements: 8 | - docs 9 | 10 | build: 11 | os: ubuntu-22.04 12 | tools: 13 | python: "3.8" 14 | apt_packages: 15 | - cmake 16 | - gcc -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | cmake_minimum_required(VERSION 3.15) 21 | 22 | project(_${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION}) 23 | string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) 24 | 25 | # Build the native library 26 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/native) 27 | # Build the Python extension 28 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/bindings) 29 | 30 | install(TARGETS ${PROJECT_NAME} DESTINATION ${SKBUILD_PROJECT_NAME} LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Building from source 4 | 5 | `RoutingBlocks` uses [scikit-build](https://github.com/scikit-build/), so building is as simple as executing: 6 | 7 | ````bash 8 | pip install . 9 | ```` 10 | 11 | Add a `-v` flag to debug any compile-time errors. 12 | 13 | ## Running tests 14 | 15 | First, make sure to install all optional test dependencies: 16 | 17 | ```bash 18 | pip install '.[test]' 19 | ``` 20 | 21 | Then navigate to `test/` and run 22 | 23 | ```bash 24 | pytest tests -m "not benchmark" 25 | ``` 26 | 27 | ## Running benchmarks 28 | 29 | Follow the procedure from "Running tests", then execute: 30 | 31 | ```bash 32 | pytest tests -m "benchmark" 33 | ``` 34 | 35 | See the [pytest-benchmark docs](https://pytest-benchmark.readthedocs.io/en/latest/usage.html) for possible command line options. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RoutingBlocks 2 | 3 | `RoutingBlocks` is an open-source Python package for the implementation of algorithms for Vehicle Routing Problems with 4 | Intermediate Stops. 5 | 6 | It provides a set of modular algorithmic components and efficient data structures that can be used as building blocks 7 | for problem-specific metaheuristic algorithms. These components are tailored specifically to tackle the challenges of 8 | VRPIS, but can be used for other classes of vehicle routing problems as well. 9 | 10 | *This package is under active development. Expect potentially breaking changes.* 11 | 12 | ## Installation 13 | 14 | The package is available on PyPI and can be installed using `pip`: 15 | 16 | ```bash 17 | pip install routingblocks 18 | ``` 19 | 20 | To obtain the bleeding-edge development version, run 21 | 22 | ```bash 23 | pip install git+https://github.com/tumBAIS/RoutingBlocks 24 | ``` 25 | 26 | instead. 27 | 28 | ## Features 29 | 30 | * Efficient C++-based solution representation 31 | * Customizable Local Search Solver 32 | * Framework for ALNS-based metaheuristics 33 | * Efficient native implementations of numerous destroy, repair, and local search operators 34 | * Move caches implemented in native code to allow high-performance operator implementations in Python 35 | * Support for custom [native extensions](https://github.com/tumBAIS/routingblocks-native-extension-example) 36 | 37 | ## Usage 38 | 39 | We provide an [example implementation](https://github.com/tumBAIS/RoutingBlocks/tree/main/examples) of an ALNS-based 40 | algorithm for 41 | the [EVRPTW-PR](https://research.sabanciuniv.edu/id/eprint/26033/1/WP_EVRPTW-Partial_Recharge_KeskinCatay.pdf) as part 42 | of this repository. 43 | 44 | Further documentation is available 45 | at [readthedocs](https://routingblocks.readthedocs.io/en/latest/getting_started.html). 46 | 47 | ## Contributing 48 | 49 | Pull requests are welcome. For major changes, please open an issue first 50 | to discuss what you would like to change. 51 | 52 | See [CONTRIBUTING.md](CONTRIBUTING.md) for more information and documentation on setting up a development environment. 53 | 54 | ## License 55 | 56 | [MIT](https://choosealicense.com/licenses/mit/) 57 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/Evaluation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_EVALUATION_H 24 | #define routingblocks_EVALUATION_H 25 | 26 | #include 27 | #include 28 | 29 | PYBIND11_SMART_HOLDER_TYPE_CASTERS(routingblocks::Evaluation) 30 | 31 | namespace routingblocks::bindings { 32 | 33 | void bind_evaluation(pybind11::module& m); 34 | } 35 | 36 | #endif // routingblocks_EVALUATION_H 37 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/Instance.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | // this software and associated documentation files (the "Software"), to deal in 5 | // the Software without restriction, including without limitation the rights to 6 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | // the Software, and to permit persons to whom the Software is furnished to do so, 8 | // subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #ifndef routingblocks_routingblocksINSTANCE_HPP 22 | #define routingblocks_routingblocksINSTANCE_HPP 23 | 24 | #include 25 | 26 | namespace routingblocks::bindings { 27 | 28 | void bind_routingblocks_instance(pybind11::module& m); 29 | } 30 | 31 | #endif // routingblocks_routingblocksINSTANCE_HPP 32 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/Labeling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_BINDINGS_LABELING_H 24 | #define routingblocks_BINDINGS_LABELING_H 25 | 26 | #include 27 | 28 | namespace routingblocks::bindings { 29 | 30 | void bind_labeling(pybind11::module& m); 31 | } 32 | 33 | #endif // routingblocks_BINDINGS_LABELING_H 34 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/LocalSearch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_BINDINGS_LOCALSEARCH_H 24 | #define routingblocks_BINDINGS_LOCALSEARCH_H 25 | 26 | #include 27 | 28 | namespace routingblocks::bindings { 29 | 30 | void bind_local_search(pybind11::module& m); 31 | void bind_neighborhood_structures(pybind11::module& m); 32 | void bind_pivoting_rule(pybind11::module& m); 33 | } // namespace routingblocks::bindings 34 | 35 | #endif // routingblocks_BINDINGS_LOCALSEARCH_H 36 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/Operators.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_BINDINGS_OPERATORS_H 24 | #define routingblocks_BINDINGS_OPERATORS_H 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace routingblocks::bindings { 32 | 33 | void bind_operators(pybind11::module& m); 34 | } // namespace routingblocks::bindings 35 | 36 | #endif // routingblocks_BINDINGS_OPERATORS_H 37 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/Solution.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_BINDINGS_SOLUTION_H 24 | #define routingblocks_BINDINGS_SOLUTION_H 25 | 26 | #include 27 | 28 | namespace routingblocks::bindings { 29 | void bind_node(pybind11::module& m); 30 | void bind_route(pybind11::module& m); 31 | void bind_solution(pybind11::module& m); 32 | 33 | void bind_solution_functions(pybind11::module& m); 34 | } // namespace routingblocks::bindings 35 | 36 | #endif // routingblocks_BINDINGS_SOLUTION_H 37 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/large_neighborhood.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_BINDINGS_LARGE_NEIGHBORHOOD_H 24 | #define routingblocks_BINDINGS_LARGE_NEIGHBORHOOD_H 25 | 26 | #include 27 | 28 | namespace routingblocks::bindings { 29 | 30 | void bind_large_neighborhood(pybind11::module& m); 31 | } 32 | 33 | #endif // routingblocks_BINDINGS_LARGE_NEIGHBORHOOD_H 34 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/specializations/ADPTW.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | #ifndef _ROUTINGBLOCKS_ADPTW_H 24 | # define _ROUTINGBLOCKS_ADPTW_H 25 | 26 | namespace routingblocks::bindings { 27 | void bind_adptw(pybind11::module& m); 28 | } 29 | 30 | #endif //_ROUTINGBLOCKS_ADPTW_H 31 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/specializations/NIFTW.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | 24 | #ifndef _ROUTINGBLOCKS_NIFTW_H 25 | # define _ROUTINGBLOCKS_NIFTW_H 26 | 27 | namespace routingblocks::bindings { 28 | void bind_niftw(pybind11::module& m); 29 | } 30 | 31 | #endif //_ROUTINGBLOCKS_NIFTW_H 32 | -------------------------------------------------------------------------------- /bindings/include/routingblocks_bindings/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_BINDINGS_UTILITY_H 24 | #define routingblocks_BINDINGS_UTILITY_H 25 | 26 | #include 27 | 28 | namespace routingblocks::bindings { 29 | void bind_utility(pybind11::module& m); 30 | } // namespace routingblocks::bindings 31 | 32 | #endif // routingblocks_BINDINGS_UTILITY_H 33 | -------------------------------------------------------------------------------- /bindings/src/bindings.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | // this software and associated documentation files (the "Software"), to deal in 5 | // the Software without restriction, including without limitation the rights to 6 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | // the Software, and to permit persons to whom the Software is furnished to do so, 8 | // subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "routingblocks_bindings/specializations/ADPTW.h" 32 | #include "routingblocks_bindings/specializations/NIFTW.h" 33 | 34 | using namespace routingblocks::bindings; 35 | 36 | #define STRINGIFY(x) #x 37 | #define PREPROCESSOR_TO_STRING(x) STRINGIFY(x) 38 | 39 | #ifndef routingblocks_VERSION 40 | # define routingblocks_VERSION "dev" 41 | #endif 42 | 43 | PYBIND11_MODULE(routingblocks_MODULE_NAME, m) { 44 | m.attr("__version__") = PREPROCESSOR_TO_STRING(routingblocks_VERSION); 45 | 46 | bind_utility(m); 47 | // Bind classes 48 | bind_routingblocks_instance(m); 49 | 50 | // Evaluation 51 | bind_evaluation(m); 52 | 53 | // Local search 54 | bind_neighborhood_structures(m); 55 | bind_local_search(m); 56 | bind_pivoting_rule(m); 57 | // LS Operators 58 | bind_operators(m); 59 | 60 | // Solution 61 | bind_node(m); 62 | bind_route(m); 63 | bind_solution(m); 64 | bind_solution_functions(m); 65 | 66 | // Labeling 67 | bind_labeling(m); 68 | 69 | // ALNS 70 | bind_large_neighborhood(m); 71 | 72 | // Specializations 73 | bind_adptw(m); 74 | bind_niftw(m); 75 | } -------------------------------------------------------------------------------- /bindings/stubs/_alns_operators.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | class _RandomRemovalOperator(DestroyOperator): 21 | """ 22 | Removes random vertices from the solution. Note that the same vertex may apppear several times, i.e., if two 23 | visits to the same vertex are removed. 24 | """ 25 | 26 | def __init__(self, random: Random) -> None: 27 | """ 28 | :param Random random: The random number generator used. 29 | """ 30 | 31 | 32 | class _RandomInsertionOperator(RepairOperator): 33 | """ 34 | Inserts vertices at random positions in the solution. 35 | """ 36 | 37 | def __init__(self, random: Random) -> None: 38 | """ 39 | :param random: The :py:class:`routingblocks.Random` instance to use. 40 | """ 41 | -------------------------------------------------------------------------------- /bindings/stubs/_arc.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from typing import Any 21 | 22 | 23 | class Arc: 24 | """ 25 | A simple arc object that represents a connection between two vertices in a graph. The arc stores additional data 26 | transparent to the RoutingBlocks package. This data can be used to store additional information about the arc, such as 27 | distances, durations, or any other attributes relevant to the problem being modeled. 28 | """ 29 | 30 | def __init__(self, data: Any) -> None: 31 | """ 32 | :param data: Additional data associated with the arc. 33 | """ 34 | ... 35 | 36 | @property 37 | def data(self) -> Any: 38 | """ 39 | Retrieves the arc data. 40 | 41 | :return: The data associated with the arc. 42 | :rtype: Any 43 | """ 44 | 45 | def __str__(self) -> str: 46 | """ 47 | Generates a human-readable string representation of the arc. 48 | 49 | :return: A string representation of the arc. 50 | :rtype: str 51 | """ 52 | ... 53 | -------------------------------------------------------------------------------- /bindings/stubs/_insertion_cache.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | class InsertionMove: 21 | vertex_id: VertexID 22 | after_node: NodeLocation 23 | delta_cost: float 24 | 25 | def __init__(self, vertex_id: VertexID, after_node_location: NodeLocation, delta_cost: float) -> None: 26 | """ 27 | :param vertex_id: The vertex to be inserted. 28 | :param after_node: The node after which the vertex should be inserted. 29 | :param delta_cost: The change in cost incurred from inserting the vertex at the specified position. 30 | """ 31 | ... 32 | 33 | def __eq__(self, other: InsertionMove) -> bool: ... 34 | 35 | 36 | class InsertionCache: 37 | def __init__(self, instance: Instance) -> None: ... 38 | 39 | def clear(self) -> None: ... 40 | 41 | def get_best_insertions_for_vertex(self, vertex_id: VertexID) -> List[InsertionMove]: ... 42 | 43 | def invalidate_route(self, route: Route, route_index: int) -> None: ... 44 | 45 | def rebuild(self, evaluation: Evaluation, solution: Solution, vertex_ids: List[VertexID]) -> None: ... 46 | 47 | def stop_tracking(self, vertex_id: VertexID) -> None: ... 48 | 49 | def tracks_vertex(self, vertex_id: VertexID) -> bool: ... 50 | 51 | @property 52 | def moves_in_order(self) -> List[InsertionMove]: ... 53 | 54 | @property 55 | def tracked_vertices(self) -> List[VertexID]: ... 56 | -------------------------------------------------------------------------------- /bindings/stubs/_node_location.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | class NodeLocation: 21 | """ 22 | A class representing the location of a node within a solution. Stores the route index and the position of the node within that route. 23 | """ 24 | route: int 25 | position: int 26 | 27 | def __init__(self, route: int, position: int) -> None: 28 | """ 29 | :param int route: The index of the route in which the node is located. 30 | :param int position: The position of the node within the route. 31 | """ 32 | ... 33 | 34 | def __eq__(self, other: NodeLocation) -> bool: ... 35 | 36 | def __getitem__(self, i: int) -> int: ... 37 | 38 | def __len__(self) -> int: ... 39 | 40 | def __lt__(self, other: NodeLocation) -> bool: ... 41 | 42 | def __ne__(self, other: NodeLocation) -> bool: ... 43 | -------------------------------------------------------------------------------- /bindings/stubs/_random.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | class Random: 21 | @overload 22 | def __init__(self) -> None: 23 | """ 24 | Initializes a new instance of the Random class without a seed. 25 | 26 | If no seed value is provided, it uses the current system time or another 27 | system-specific source of randomness to generate random numbers. 28 | """ 29 | 30 | @overload 31 | def __init__(self, seed: int) -> None: 32 | """ 33 | Initializes a new instance of the Random class with a provided seed. 34 | 35 | The seed is a number used to initialize the underlying pseudo-random 36 | number generator. 37 | 38 | :param int seed: The seed value for the random number generator. Providing the 39 | same seed will generate the same sequence of random numbers. 40 | """ 41 | 42 | def randint(self, min: int, max: int) -> int: 43 | """ 44 | Returns a random integer from the specified range [min, max], including 45 | both endpoints. 46 | 47 | :param int min: The lower bound of the range. 48 | :param int max: The upper bound of the range. 49 | 50 | :return: A random integer value from the specified range [min, max]. 51 | """ 52 | 53 | def uniform(self, min: float, max: float) -> float: 54 | """ 55 | Returns a random floating-point number between the specified min and max values, 56 | including min and potentially up to max. 57 | 58 | :param float min: The lower bound of the range. 59 | :param float max: The upper bound of the range. 60 | :return: A random floating-point number within the specified range [min, max). 61 | """ 62 | -------------------------------------------------------------------------------- /bindings/stubs/_removal_cache.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | class RemovalMove: 21 | vertex_id: VertexID 22 | node_location: NodeLocation 23 | delta_cost: float 24 | 25 | def __init__(self, vertex_id: VertexID, node_location: NodeLocation, delta_cost: float) -> None: 26 | """ 27 | :param vertex_id: The vertex ID of the node to be removed. 28 | :param node_location: The location of the node to be removed. 29 | :param delta_cost: The change in cost of the solution if the node is removed. 30 | """ 31 | ... 32 | 33 | def __eq__(self, other: RemovalMove) -> bool: ... 34 | 35 | 36 | class RemovalCache: 37 | def __init__(self, instance: Instance) -> None: ... 38 | 39 | def clear(self) -> None: ... 40 | 41 | def invalidate_route(self, route: Route, route_index: int) -> None: ... 42 | 43 | def rebuild(self, evaluation: Evaluation, solution: Solution) -> None: ... 44 | 45 | @property 46 | def moves_in_order(self) -> List[RemovalMove]: ... 47 | -------------------------------------------------------------------------------- /bindings/stubs/_types.pyi: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from typing import Any 21 | 22 | AnyForwardLabel = Any 23 | AnyBackwardLabel = Any 24 | VertexID = int 25 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/adptw.rst: -------------------------------------------------------------------------------- 1 | .. _ADPTW: 2 | 3 | ADPTW 4 | ========================================== 5 | 6 | This module provides efficient implementations to solve ADPTW problems. 7 | 8 | Classification 9 | ------------------------------------------ 10 | 11 | The A-D-P-TW class of vehicle routing routing problems with intermediate stops encompassed problems with the following attributes (cf. :cite:t:`SchifferSchneiderEtAl2019`): 12 | 13 | - **Arc-based (A):** The consumption of operational resources, e.g. fuel, is continuous and occurs when travelling between nodes. 14 | 15 | - **Dependent (D):** The replenishment time is dependent on the quantity of the operational resource being replenished, meaning more time is needed for larger quantities. 16 | 17 | - **Partial Replenishment (P):** The operational resources can be partially restocked, implying that the replenishment process can be interrupted at any time, i.e., does not need to fully replenish the resource in question. 18 | 19 | - **Time Windows (TW):** The scheduled stops need to be visited within node-specific periods. 20 | 21 | In this setting, the routing strategy must consider continuous resource consumption, variable replenishment times, the option for partial replenishment, and adherence to designated time windows. 22 | This combination of factors is one of the most challenging routing problems, and is often encountered in real-world applications, e.g., the Electric Vehicle Routing Problem with Time Windows and Partial Replenishment (EVRP-TW-PR). 23 | 24 | 25 | API 26 | ------------------------------------------ 27 | 28 | .. autoapimodule:: routingblocks.adptw 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | -------------------------------------------------------------------------------- /docs/source/alternatives.rst: -------------------------------------------------------------------------------- 1 | Alternatives 2 | ================ 3 | 4 | There exist a variety of libraries that deal with solving combinatorial optimization problems in general, and vehicle routing problems in particular. 5 | The following flowchart gives an example of how to choose the right library for your problem. 6 | We have limited ourselves to libraries that base on native implementations and expose a Python interface. We do not include any commercial libraries or software. 7 | 8 | .. note:: 9 | 10 | Our recommendation bases on the contributors' personal opinions. It is not meant to be a comprehensive list of all available libraries, nor is it meant to be a complete list of all features of the libraries mentioned. 11 | 12 | .. mermaid:: 13 | :align: center 14 | 15 | graph TD; 16 | A{Exact solution
desired} 17 | B{"CVRP(-TW)"} 18 | C("PyVRPEasy") 19 | D("PyVRP") 20 | E("RoutingBlocks") 21 | 22 | A -->|yes| B 23 | A -->|no| C 24 | B -->|yes| D 25 | B -->|no| E 26 | 27 | The main difference between RoutingBlocks and `https://pyvrp.readthedocs.io/en/latest/ `_ relates to the level of control offered by the library. PyVRP is a wrapper around `https://github.com/vidalt/HGS-CVRP/ `_, a monolithic algorithm implemented in C++. As such, it is limited to a select set of problems, i.e., CVRP, CVRP-TW, and Prize-collecting variants. 28 | It does not allow to implement custom evaluation functions, operators, or other components of the algorithm. RoutingBlocks, on the other hand, is a framework that is built with this very use-case in mind. This of course comes with a price: RoutingBlocks is not as fast as PyVRP, and it requires more effort to implement a (custom) solution algorithm. 29 | 30 | We note that RoutingBlocks can technically utilize any other library in it's components. This requires converting the solution and instance representations of the other library to the one used by RoutingBlocks and vice versa. 31 | A potential use-case could be a matheuristic that (repeatably) decomposes a large vehicle routing problem into several subproblems solvable exactly by a library like `https://pyvrp.readthedocs.io/en/latest/ `_. -------------------------------------------------------------------------------- /docs/source/auxilliary.rst: -------------------------------------------------------------------------------- 1 | Auxiliary algorithms and data structures 2 | ========================================== 3 | 4 | Algorithms 5 | ---------- 6 | 7 | .. autoapifunction:: routingblocks.utility.sample_positions 8 | 9 | InsertionCache 10 | -------------- 11 | 12 | .. autoapiclass:: routingblocks.InsertionMove 13 | :members: 14 | :undoc-members: 15 | 16 | .. autoapiclass:: routingblocks.InsertionCache 17 | :members: 18 | :undoc-members: 19 | 20 | RemovalCache 21 | ------------ 22 | 23 | .. autoapiclass:: routingblocks.RemovalMove 24 | :members: 25 | :undoc-members: 26 | 27 | .. autoapiclass:: routingblocks.RemovalCache 28 | :members: 29 | :undoc-members: 30 | 31 | Miscellaneous 32 | ------------- 33 | 34 | .. autoapiclass:: routingblocks.Random 35 | :members: 36 | :undoc-members: 37 | :class-doc-from: class 38 | 39 | .. py:method:: __init__(self): 40 | 41 | Initializes a new instance of the Random class without a seed. 42 | 43 | If no seed value is provided, it uses the current system time or another 44 | system-specific source of randomness to generate random numbers. 45 | 46 | .. py:method:: __init__(self, seed: int): 47 | 48 | Initializes a new instance of the Random class with a provided seed. 49 | 50 | The seed is a number used to initialize the underlying pseudo-random 51 | number generator. 52 | 53 | :param int seed: The seed value for the random number generator. Providing the 54 | same seed will generate the same sequence of random numbers. 55 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | import datetime 6 | import sys 7 | from pathlib import Path 8 | 9 | import routingblocks 10 | 11 | # -- Project information ----------------------------------------------------- 12 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 13 | 14 | project = 'RoutingBlocks' 15 | authors = 'Patrick Sean Klein' 16 | copyright = f'2023 - {datetime.date.today().year}, {authors}' 17 | release = '01.04.2023' 18 | 19 | # -- General configuration --------------------------------------------------- 20 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 21 | 22 | # routingblocks_import_path = Path(routingblocks.__file__).parent 23 | for path in map(Path, sys.path): 24 | if (rb_path := path / 'routingblocks').exists(): 25 | routingblocks_import_path = rb_path 26 | break 27 | 28 | extensions = [ 29 | 'sphinx_rtd_theme', 30 | 'autoapi.extension', 31 | 'sphinx.ext.autodoc', 32 | 'sphinx.ext.autodoc.typehints', 33 | 'sphinx.ext.autosummary', 34 | 'sphinx.ext.duration', 35 | 'sphinx.ext.doctest', 36 | 'sphinx.ext.mathjax', 37 | 'sphinxcontrib.bibtex', 38 | 'sphinxcontrib.mermaid', 39 | ] 40 | 41 | # AutoAPI 42 | 43 | autosummary_generate = True 44 | autoapi_type = "python" 45 | autoapi_dirs = [str(routingblocks_import_path)] 46 | autoapi_options = ["undoc-members", "members", "special-members"] 47 | 48 | autoapi_generate_api_docs = False 49 | autoapi_add_toctree_entry = False 50 | autoapi_add_objects_to_toctree = False 51 | 52 | autoapi_python_class_content = "both" 53 | autoapi_member_order = "bysource" 54 | autodoc_member_order = "bysource" 55 | 56 | autodoc_typehints = "both" 57 | 58 | # Bibtex 59 | bibtex_bibfiles = ['references.bib'] 60 | 61 | templates_path = ['_templates'] 62 | exclude_patterns = [] 63 | 64 | # -- Options for HTML output ------------------------------------------------- 65 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 66 | 67 | html_theme = 'sphinx_rtd_theme' 68 | html_static_path = ['_static'] 69 | html_theme_options = { 70 | 'navigation_depth': -1 71 | } 72 | -------------------------------------------------------------------------------- /docs/source/contributing.rst: -------------------------------------------------------------------------------- 1 | Contribution opportunities 2 | ========================== 3 | 4 | We welcome and appreciate contributions from the community, researchers, and practitioners alike to enhance the functionality, usability, and documentation of our package. 5 | For instructions on how to set up a development environment, see :ref:`development`. 6 | Here are some key areas where your contributions can add significant value: 7 | 8 | Methodological enhancements 9 | ---------------------------- 10 | 11 | Custom evaluation classes 12 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | 14 | We are eager to provide more evaluation classes for problem variants into our package. 15 | Contributions that introduce custom evaluation classes, especially those that cater to niche or emerging areas in routing problems, are highly valuable. 16 | 17 | Operators and algorithms 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | 20 | The performance of most metaheuristic algorithms is heavily reliant on the strength of the local search component, which again relies on innovative operators and algorithms. 21 | By contributing novel or improved operators and algorithms, you aid in enhancing the package’s efficiency and accuracy. 22 | 23 | Documentation improvements 24 | ----------------------------- 25 | 26 | Improving conciseness and clarity 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 | 29 | While we strive to provide comprehensive documentation, there is always room for enhancement. 30 | Contributions that focus on making the documentation more concise and clear are essential. 31 | Your insights and revisions can make the content more accessible and user-friendly, aiding users to grasp concepts and utilize the package effectively. 32 | 33 | Examples 34 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 35 | 36 | Practical examples play a pivotal role in bridging the gap between theoretical concepts and real-world application. 37 | Contributions that add well-documented and diverse examples enrich the learning experience for users, offering them tangible insights into how the package can be applied to solve actual routing problems. 38 | 39 | Join us 40 | ------------------------- 41 | 42 | We believe in the collective effort of the community to push the boundaries of what this package can achieve. Your contributions in these areas, and others, will not only enrich the package but also foster a vibrant ecosystem where knowledge, innovation, and solutions are shared and multiplied. We look forward to collaborating with you! -------------------------------------------------------------------------------- /docs/source/custom_operators.rst: -------------------------------------------------------------------------------- 1 | .. _custom_operators: 2 | 3 | Custom operators 4 | ============================= 5 | 6 | .. _custom_destroy_operator: 7 | 8 | The example developed in the previous section so far uses only the standard operators RoutingBlocks provides out of the box. However, it is also possible to implement custom local search, destroy, and repair operators. We'll implement a simple RouteRemoval destroy operator as an example: 9 | 10 | .. code-block:: python 11 | 12 | # Custom destory, repair, and local serach operators inherit from the DestroyOperator, RepairOperator, and Operator base classe, respectively, respectively. 13 | class RouteRemoveOperator(routingblocks.DestroyOperator): 14 | def __init__(self, rng: routingblocks.Random): 15 | # Important: Do not use super()! 16 | routingblocks.DestroyOperator.__init__(self) 17 | self._rng = rng 18 | 19 | # Returns true if the operator can be applied to the current solution 20 | def can_apply_to(self, _solution: routingblocks.Solution) -> bool: 21 | return len(_solution) > 0 22 | 23 | # Applies the operator to the current solution 24 | def apply(self, evaluation: routingblocks.Evaluation, solution: routingblocks.Solution, number_of_removed_vertices: int) -> List[ 25 | int]: 26 | # Try to remove random routes 27 | removed_customers = [] 28 | while len(solution) > 0 and len(removed_customers) < number_of_removed_vertices: 29 | random_route_index = self._rng.randint(0, len(solution) - 1) 30 | removed_customers.extend(x.vertex_id for x in solution[random_route_index] if not x.vertex.is_depot) 31 | del solution[random_route_index] 32 | return removed_customers 33 | 34 | # Returns the operator's name 35 | def name(self) -> str: 36 | return "RouteRemoveOperator" 37 | 38 | The operator removes random routes from the solution until the desired number of vertices has been removed. Destroy operators implement the DestroyOperator interface. The interface requires implementation of the following methods: 39 | 40 | * can_apply_to: Returns true if the operator can be applied to the current solution 41 | * apply: Applies the operator to the current solution, returning the ids of the removed vertices 42 | * name: Returns the operator's name 43 | 44 | The operator can be registered with the ALNS solver in the same way as the standard operators: 45 | 46 | .. code-block:: python 47 | 48 | alns.add_destroy_operator(RouteRemoveOperator(randgen)) 49 | 50 | The same approach can be used to implement custom repair and local search operators. See :ref:`here ` for further details on implementing destroy and repair operators, and :ref:`here ` for a comprehensive example of a custom local search operator. -------------------------------------------------------------------------------- /docs/source/development.rst: -------------------------------------------------------------------------------- 1 | .. _development: 2 | 3 | Development 4 | ==================== 5 | 6 | Setting up a development environment 7 | ------------------------------------ 8 | 9 | Make sure to install the development dependencies. This includes testing and (optionally) documentation dependencies. 10 | 11 | .. code-block:: bash 12 | 13 | pip install .[test] 14 | pip install .[docs] 15 | 16 | Running the tests 17 | ----------------- 18 | 19 | Then run the tests: 20 | 21 | .. code-block:: bash 22 | 23 | cd test 24 | pytest tests 25 | 26 | Building documentation 27 | ---------------------- 28 | 29 | .. code-block:: bash 30 | 31 | cd docs 32 | make html 33 | 34 | We recommend `sphinx-autobuild `_ for live-reloading the documentation: 35 | 36 | .. code-block:: bash 37 | 38 | pip install sphinx-autobuild 39 | sphinx-autobuild docs/source docs/build/html -------------------------------------------------------------------------------- /docs/source/evaluation.rst: -------------------------------------------------------------------------------- 1 | .. _Evaluation: 2 | 3 | Evaluation 4 | ========== 5 | 6 | The evaluation class implements problem-specific cost and move evaluation functions. It's design bases on the 7 | concepts introduced in :cite:t:`VidalCrainicEtAl2014`. 8 | 9 | Note that this class is an interface: it's not meant to be instantiated or used directly. Please use the concrete 10 | implementations of this interface and helper functions instead. See e.g. :ref:`ADPTW` or :ref:`NIFTW` for examples of 11 | concrete implementations. 12 | 13 | .. warning:: 14 | 15 | We recommend implementing a custom Evaluation class by extending the native RoutingBlocks library instead of providing a python implementation for code used beyond prototyping. See `native extensions `_ for an example. 16 | 17 | .. autoapiclass:: routingblocks.PyConcatenationBasedEvaluation 18 | :members: 19 | :undoc-members: 20 | :inherited-members: 21 | 22 | .. autoapiclass:: routingblocks.PyEvaluation 23 | :members: 24 | :undoc-members: 25 | :inherited-members: 26 | 27 | 28 | .. py:function:: evaluate_insertion(evaluation: Evaluation, instance: Instance, route: Route, after_position: int, vertex_id: VertexID) -> float 29 | 30 | Evaluates inserting a vertex into a route after the specified position. 31 | 32 | :param Evaluation evaluation: The evaluation function 33 | :param Instance instance: The instance 34 | :param Route route: The route 35 | :param int after_position: The position after which the vertex is inserted 36 | :param VertexID vertex_id: The id of the vertex to insert 37 | :return: The cost of the route with the vertex inserted 38 | :rtype: float 39 | 40 | .. py:function:: evaluate_insertion(evaluation: Evaluation, instance: Instance, route: Route, after_position: int, vertex: Vertex) -> float 41 | 42 | Evaluates inserting a vertex into a route after the specified position. 43 | 44 | :param Evaluation evaluation: The evaluation function 45 | :param Instance instance: The instance 46 | :param Route route: The route 47 | :param int after_position: The position after which the vertex is inserted 48 | :param Vertex vertex: The vertex to insert 49 | :return: The cost of the route with the vertex inserted 50 | :rtype: float 51 | 52 | .. py:function:: evaluate_insertion(evaluation: Evaluation, instance: Instance, route: Route, after_position: int, node: Node) -> float 53 | 54 | Evaluates inserting a node into a route after the specified position. 55 | 56 | :param Evaluation evaluation: The evaluation function 57 | :param Instance instance: The instance 58 | :param Route route: The route 59 | :param int after_position: The position after which the vertex is inserted 60 | :param Node node: The node to insert 61 | :return: The cost of the route with the vertex inserted 62 | :rtype: float 63 | 64 | 65 | .. autoapifunction:: routingblocks.evaluate_splice 66 | -------------------------------------------------------------------------------- /docs/source/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ==================== 3 | 4 | * `ils `_: A simple ILS for the EVRP-TW-PR. 5 | * `alns `_: A simple ALNS for the EVRP-TW-PR. 6 | * `evrptw `_: An example implementation of a more sophisticated ALNS-based algorithm for the EVRP-TW-PR problem. 7 | * `cvrp `_: Example of a native extension to solve the CVRP. 8 | -------------------------------------------------------------------------------- /docs/source/full_api.rst: -------------------------------------------------------------------------------- 1 | Routingblocks class index 2 | ------------------------- 3 | 4 | .. autoapimodule:: routingblocks 5 | :noindex: 6 | :undoc-members: 7 | :members: 8 | 9 | .. autoapimodule:: routingblocks.operators 10 | :noindex: 11 | :undoc-members: 12 | :members: 13 | 14 | .. autoapimodule:: routingblocks.utility 15 | :noindex: 16 | :undoc-members: 17 | :members: 18 | -------------------------------------------------------------------------------- /docs/source/img/auxilliary_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tumBAIS/RoutingBlocks/2d2ee06c79b5d458b1aeeafd95a2b42b5441079a/docs/source/img/auxilliary_graph.png -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to RoutingBlock's documentation! 2 | ========================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | :caption: Basics 7 | 8 | getting_started 9 | custom_operators 10 | custom_problem_settings 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | :caption: Components 15 | 16 | instance 17 | solution 18 | evaluation 19 | localsearch 20 | exact_facility_placement 21 | metaheuristic_components 22 | auxilliary 23 | 24 | .. toctree:: 25 | :maxdepth: 1 26 | :caption: Problem settings 27 | 28 | adptw 29 | niftw 30 | 31 | .. toctree:: 32 | :maxdepth: 1 33 | :caption: Further Reading 34 | 35 | examples 36 | alternatives 37 | contributing 38 | development 39 | full_api 40 | references 41 | 42 | 43 | Indices and tables 44 | ================== 45 | 46 | * :ref:`genindex` 47 | * :ref:`modindex` 48 | * :ref:`search` -------------------------------------------------------------------------------- /docs/source/niftw.rst: -------------------------------------------------------------------------------- 1 | .. _NIFTW: 2 | 3 | NIFTW 4 | ====== 5 | 6 | This module provides efficient implementations to solve NIFTW problems. 7 | 8 | Classification 9 | -------------- 10 | 11 | The N-I-F-TW class of vehicle routing routing problems with intermediate stops encompassed problems with the following attributes (cf. :cite:t:`SchifferSchneiderEtAl2019`): 12 | 13 | - **Node-based (N):** The consumption of operational resources, e.g., goods or materials, occurs at stops or nodes. 14 | 15 | - **Independent (I):** The replenishment time is fixed and not dependent on the quantity of the operational resource being replenished, ensuring consistent replenishment durations. 16 | 17 | - **Full Replenishment (F):** The operational resources are always fully restocked. 18 | 19 | - **Time Windows (TW):** The scheduled stops need to be visited within node-specific periods. 20 | 21 | In the N-I-F-TW setting, the routing considerations are centred around node-specific resource consumption, constant replenishment times, the necessity for full replenishment, and strict adherence to time windows. 22 | This scenario is typical in various real-world applications where resources are consumed at stops, replenishment times are consistent, and routes are strictly governed by time constraints, such as in certain types of delivery or service routing problems. 23 | 24 | 25 | API 26 | --- 27 | 28 | .. autoapimodule:: routingblocks.niftw 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | -------------------------------------------------------------------------------- /docs/source/references.rst: -------------------------------------------------------------------------------- 1 | References 2 | ========== 3 | 4 | .. bibliography:: 5 | -------------------------------------------------------------------------------- /docs/source/solution.rst: -------------------------------------------------------------------------------- 1 | Solution representation 2 | ======================== 3 | 4 | .. autoapiclass:: routingblocks.Node 5 | :members: 6 | :undoc-members: 7 | 8 | .. autoapifunction:: routingblocks.create_route 9 | 10 | .. autoapiclass:: routingblocks.Route 11 | :members: 12 | :undoc-members: 13 | 14 | .. autoapiclass:: routingblocks.Solution 15 | :members: 16 | :undoc-members: 17 | :class-doc-from: class 18 | :special-members: __len__, __iter__, __getitem__, __delitem__ 19 | 20 | .. py:method:: __init__(self, evaluation: Evaluation, instance: Instance, number_of_routes: int) 21 | 22 | Creates a new Solution object with the specified number of empty routes. 23 | 24 | :param Evaluation evaluation: The evaluation object for cost and feasibility calculations. 25 | :param Instance instance: The Instance object representing the problem instance. 26 | :param int number_of_routes: The number of empty routes the solution should contain. 27 | 28 | .. py:method:: __init__(self, evaluation: Evaluation, instance: Instance, routes: List[Route]) 29 | 30 | Creates a new Solution object with the specified list of routes. 31 | 32 | :param Evaluation evaluation: The evaluation object for cost and feasibility calculations. 33 | :param Instance instance: The Instance object representing the problem instance. 34 | :param List[Route] routes: The list of routes to include in the solution. 35 | 36 | .. autoapiclass:: routingblocks.NodeLocation 37 | :members: 38 | :undoc-members: 39 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | This directory contains examples of how to use `routingblocks`: 4 | 5 | * ils: A simple ILS for the EVRP-TW-PR. 6 | * alns: A simple ALNS for the EVRP-TW-PR. 7 | * evrptw: An example implementation of a more sophisticated ALNS-based algorithm for the EVRP-TW-PR problem. 8 | 9 | ## Running 10 | 11 | Before running any of the examples, make sure that you've installed the example's requirements. 12 | Then, to run any of the python examples: 13 | 14 | ```bash 15 | python -m -h 16 | ``` 17 | 18 | You can find further information in the respective example's README. -------------------------------------------------------------------------------- /examples/alns/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /examples/alns/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from pathlib import Path 21 | import argparse 22 | 23 | from .parsing import parse_instance, create_instance 24 | from .alns import alns 25 | 26 | 27 | def solve(instance_path: Path, number_of_iterations: int = 100): 28 | vertices, arcs, params = parse_instance(instance_path) 29 | instance = create_instance(vertices, arcs) 30 | vehicle_storage_capacity = params['C'] 31 | # Vehicle battery capacity in units of time: 32 | # battery capacity * inverse refueling rate = battery capacity / refueling rate 33 | vehicle_battery_capacity_time = params['Q'] * params['g'] 34 | 35 | solution = alns(instance=instance, vehicle_storage_capacity=vehicle_storage_capacity, 36 | vehicle_battery_capacity_time=vehicle_battery_capacity_time, 37 | number_of_iterations=number_of_iterations 38 | ) 39 | 40 | print("Best solution:") 41 | print(solution) 42 | 43 | 44 | def main(): 45 | parser = argparse.ArgumentParser(description="Solve a EVRP-TW-PR instance with ALNS.") 46 | 47 | parser.add_argument( 48 | "instance_path", 49 | type=Path, 50 | help="Path to the instance file." 51 | ) 52 | 53 | parser.add_argument( 54 | "-n", "--number_of_iterations", 55 | type=int, 56 | default=100, 57 | help="Number of ALNS iterations to perform (default: 100)." 58 | ) 59 | 60 | args = parser.parse_args() 61 | 62 | solve(Path(args.instance_path), args.number_of_iterations) 63 | 64 | 65 | if __name__ == '__main__': 66 | main() 67 | -------------------------------------------------------------------------------- /examples/evrptw/README.md: -------------------------------------------------------------------------------- 1 | # EVRPTW-PR 2 | 3 | This directory contains an example implementation of an ALNS-based algorithm for the EVRPTW-PR problem. 4 | To run the example, first install the requirements: 5 | 6 | ```bash 7 | pip install -r requirements.txt 8 | ``` 9 | 10 | Then, cd to the parent directory and run the example with 11 | 12 | ```bash 13 | python -m evrptw instances/evrptw/100/c101_21.txt evrptw/config.json --max-iterations=5000 --max-iterations-since-last-improvement=1100 14 | ``` 15 | 16 | Run 17 | 18 | ```bash 19 | python -m evrptw -h 20 | ``` 21 | 22 | for a list of supported command line arguments. -------------------------------------------------------------------------------- /examples/evrptw/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /examples/evrptw/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "adaptive_smoothing_factor": 0.2, 3 | "min_removed_customer_percentage": 0.1, 4 | "max_removed_customer_percentage": 0.5, 5 | "new_best_feasible_score": 9, 6 | "new_best_score": 4, 7 | "new_improvement_score": 1, 8 | "num_starting_solutions": 10, 9 | "adaptive_period_length": 50, 10 | "penalty_period_length": 50, 11 | "delta_local_search": 0.5, 12 | "delta_fpo": 0.25, 13 | "target_feasibility_ratios": [ 14 | 0.9, 15 | 0.9, 16 | 0.9 17 | ], 18 | "penalty_increase_factor": 1.2, 19 | "penalty_decrease_factor": 0.8, 20 | "use_best_improvement": true, 21 | "shuffle_operators": false, 22 | "distance_weight": 0.75, 23 | "demand_weight": 0.1, 24 | "time_weight": 0.1, 25 | "shaw_exponent": 4, 26 | "tw_shift_weight": 1, 27 | "slack_weight": 1, 28 | "vehicle_decrease_period_length": 250, 29 | "worst_removal_blink_probability": 0.01, 30 | "best_insertion_blink_probability": 0.15, 31 | "granularity": 30 32 | } 33 | -------------------------------------------------------------------------------- /examples/evrptw/instance/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .interface import parse_evrptw_instance, create_cpp_vertex, create_cpp_instance, create_cpp_arc 21 | from .models import Instance, Vertex, Arc 22 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/c101C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S1 f 77.0 52.0 0.0 0.0 1236.0 0.0 5 | S3 f 57.0 82.0 0.0 0.0 1236.0 0.0 6 | S16 f 48.0 8.0 0.0 0.0 1236.0 0.0 7 | S20 f 93.0 43.0 0.0 0.0 1236.0 0.0 8 | C98 c 58.0 75.0 20.0 181.0 247.0 90.0 9 | C78 c 88.0 35.0 20.0 667.0 731.0 90.0 10 | C4 c 42.0 68.0 10.0 584.0 656.0 90.0 11 | C13 c 22.0 75.0 30.0 1042.0 1106.0 90.0 12 | C95 c 62.0 80.0 30.0 274.0 330.0 90.0 13 | C100 c 55.0 85.0 20.0 744.0 798.0 90.0 14 | C54 c 42.0 10.0 40.0 810.0 868.0 90.0 15 | C27 c 23.0 52.0 10.0 263.0 311.0 90.0 16 | C89 c 63.0 58.0 10.0 929.0 989.0 90.0 17 | C96 c 60.0 80.0 10.0 177.0 243.0 90.0 18 | 19 | Q Vehicle fuel tank capacity /77.75/ 20 | C Vehicle load capacity /200.0/ 21 | r fuel consumption rate /1.0/ 22 | g inverse refueling rate /3.47/ 23 | v average Velocity /1.0/ 24 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/c104C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 1236.0 0.0 5 | S13 f 22.0 34.0 0.0 0.0 1236.0 0.0 6 | S18 f 76.0 21.0 0.0 0.0 1236.0 0.0 7 | C72 c 53.0 30.0 10.0 0.0 1122.0 90.0 8 | C34 c 8.0 45.0 20.0 0.0 1113.0 90.0 9 | C80 c 85.0 25.0 10.0 0.0 1094.0 90.0 10 | C3 c 42.0 66.0 10.0 0.0 1129.0 90.0 11 | C88 c 65.0 60.0 30.0 0.0 1119.0 90.0 12 | C96 c 60.0 80.0 10.0 177.0 243.0 90.0 13 | C42 c 33.0 32.0 20.0 0.0 1126.0 90.0 14 | C22 c 28.0 52.0 20.0 0.0 1133.0 90.0 15 | C57 c 40.0 15.0 40.0 0.0 1111.0 90.0 16 | C48 c 28.0 30.0 10.0 0.0 1122.0 90.0 17 | 18 | Q Vehicle fuel tank capacity /77.75/ 19 | C Vehicle load capacity /200.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /3.47/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/c202C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 3390.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 3390.0 0.0 4 | S1 f 77.0 52.0 0.0 0.0 3390.0 0.0 5 | S7 f 21.0 83.0 0.0 0.0 3390.0 0.0 6 | S13 f 22.0 34.0 0.0 0.0 3390.0 0.0 7 | S15 f 39.0 26.0 0.0 0.0 3390.0 0.0 8 | C96 c 62.0 40.0 10.0 1808.0 1968.0 90.0 9 | C30 c 20.0 55.0 10.0 2737.0 2897.0 90.0 10 | C84 c 70.0 58.0 20.0 321.0 481.0 90.0 11 | C16 c 20.0 85.0 40.0 693.0 853.0 90.0 12 | C57 c 38.0 15.0 40.0 0.0 3264.0 90.0 13 | C8 c 34.0 60.0 20.0 12.0 172.0 90.0 14 | C24 c 25.0 50.0 10.0 2925.0 3085.0 90.0 15 | C25 c 22.0 66.0 40.0 1078.0 1238.0 90.0 16 | C10 c 35.0 66.0 10.0 28.0 188.0 90.0 17 | C6 c 16.0 42.0 20.0 2544.0 2704.0 90.0 18 | 19 | Q Vehicle fuel tank capacity /77.75/ 20 | C Vehicle load capacity /700.0/ 21 | r fuel consumption rate /1.0/ 22 | g inverse refueling rate /3.47/ 23 | v average Velocity /1.0/ 24 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/c205C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 3390.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 3390.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 3390.0 0.0 5 | S15 f 39.0 26.0 0.0 0.0 3390.0 0.0 6 | C8 c 34.0 60.0 20.0 12.0 332.0 90.0 7 | C9 c 28.0 70.0 10.0 138.0 458.0 90.0 8 | C47 c 30.0 35.0 10.0 227.0 547.0 90.0 9 | C60 c 35.0 5.0 20.0 1312.0 1632.0 90.0 10 | C94 c 65.0 82.0 10.0 429.0 749.0 90.0 11 | C75 c 45.0 65.0 20.0 1099.0 1419.0 90.0 12 | C66 c 47.0 35.0 10.0 2633.0 2953.0 90.0 13 | C99 c 55.0 80.0 10.0 810.0 1130.0 90.0 14 | C56 c 40.0 5.0 30.0 1497.0 1817.0 90.0 15 | C15 c 20.0 80.0 40.0 331.0 651.0 90.0 16 | 17 | Q Vehicle fuel tank capacity /77.75/ 18 | C Vehicle load capacity /700.0/ 19 | r fuel consumption rate /1.0/ 20 | g inverse refueling rate /3.47/ 21 | v average Velocity /1.0/ 22 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/r102C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 230.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 230.0 0.0 4 | S5 f 28.0 62.0 0.0 0.0 230.0 0.0 5 | S17 f 51.0 7.0 0.0 0.0 230.0 0.0 6 | S18 f 63.0 12.0 0.0 0.0 230.0 0.0 7 | C31 c 31.0 52.0 27.0 25.0 35.0 10.0 8 | C23 c 55.0 5.0 29.0 97.0 107.0 10.0 9 | C67 c 67.0 5.0 25.0 0.0 176.0 10.0 10 | C60 c 17.0 34.0 3.0 0.0 201.0 10.0 11 | C88 c 26.0 52.0 9.0 166.0 176.0 10.0 12 | C77 c 53.0 43.0 14.0 150.0 160.0 10.0 13 | C20 c 45.0 65.0 9.0 77.0 87.0 10.0 14 | C99 c 20.0 26.0 9.0 138.0 148.0 10.0 15 | C12 c 50.0 35.0 19.0 177.0 187.0 10.0 16 | C21 c 45.0 20.0 11.0 0.0 201.0 10.0 17 | 18 | Q Vehicle fuel tank capacity /60.63/ 19 | C Vehicle load capacity /200.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /0.49/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/r103C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 230.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 230.0 0.0 4 | S9 f 15.0 42.0 0.0 0.0 230.0 0.0 5 | S13 f 21.0 22.0 0.0 0.0 230.0 0.0 6 | C91 c 15.0 19.0 1.0 87.0 97.0 10.0 7 | C84 c 11.0 31.0 7.0 96.0 106.0 10.0 8 | C53 c 37.0 31.0 14.0 0.0 215.0 10.0 9 | C18 c 20.0 40.0 12.0 0.0 204.0 10.0 10 | C27 c 35.0 40.0 16.0 173.0 183.0 10.0 11 | C81 c 55.0 54.0 26.0 0.0 192.0 10.0 12 | C83 c 14.0 37.0 11.0 0.0 198.0 10.0 13 | C45 c 6.0 38.0 16.0 0.0 190.0 10.0 14 | C26 c 45.0 30.0 17.0 0.0 208.0 10.0 15 | C16 c 10.0 20.0 19.0 71.0 81.0 10.0 16 | 17 | Q Vehicle fuel tank capacity /60.63/ 18 | C Vehicle load capacity /200.0/ 19 | r fuel consumption rate /1.0/ 20 | g inverse refueling rate /0.49/ 21 | v average Velocity /1.0/ 22 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/r201C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 1000.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 1000.0 0.0 4 | S5 f 28.0 62.0 0.0 0.0 1000.0 0.0 5 | S13 f 21.0 22.0 0.0 0.0 1000.0 0.0 6 | S15 f 34.0 16.0 0.0 0.0 1000.0 0.0 7 | C77 c 53.0 43.0 14.0 86.0 224.0 10.0 8 | C50 c 47.0 47.0 13.0 507.0 599.0 10.0 9 | C18 c 20.0 40.0 12.0 403.0 513.0 10.0 10 | C28 c 41.0 37.0 16.0 357.0 495.0 10.0 11 | C32 c 35.0 69.0 23.0 501.0 621.0 10.0 12 | C31 c 31.0 52.0 27.0 591.0 809.0 10.0 13 | C84 c 11.0 31.0 7.0 314.0 448.0 10.0 14 | C72 c 47.0 16.0 25.0 104.0 252.0 10.0 15 | C94 c 26.0 27.0 27.0 534.0 642.0 10.0 16 | C100 c 18.0 18.0 17.0 118.0 148.0 10.0 17 | 18 | Q Vehicle fuel tank capacity /60.63/ 19 | C Vehicle load capacity /1000.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /0.49/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/r203C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 1000.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 1000.0 0.0 4 | S4 f 59.0 67.0 0.0 0.0 1000.0 0.0 5 | S7 f 20.0 61.0 0.0 0.0 1000.0 0.0 6 | S9 f 15.0 42.0 0.0 0.0 1000.0 0.0 7 | S13 f 21.0 22.0 0.0 0.0 1000.0 0.0 8 | C84 c 11.0 31.0 7.0 0.0 965.0 10.0 9 | C11 c 20.0 65.0 12.0 0.0 956.0 10.0 10 | C57 c 32.0 12.0 7.0 0.0 966.0 10.0 11 | C78 c 61.0 52.0 3.0 648.0 826.0 10.0 12 | C69 c 37.0 47.0 6.0 0.0 977.0 10.0 13 | C5 c 15.0 30.0 26.0 21.0 182.0 10.0 14 | C61 c 12.0 24.0 13.0 329.0 551.0 10.0 15 | C75 c 49.0 11.0 18.0 0.0 962.0 10.0 16 | C71 c 57.0 68.0 15.0 0.0 950.0 10.0 17 | C17 c 5.0 30.0 2.0 0.0 959.0 10.0 18 | 19 | Q Vehicle fuel tank capacity /60.63/ 20 | C Vehicle load capacity /1000.0/ 21 | r fuel consumption rate /1.0/ 22 | g inverse refueling rate /0.49/ 23 | v average Velocity /1.0/ 24 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/rc102C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 240.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 240.0 0.0 4 | S1 f 77.0 52.0 0.0 0.0 240.0 0.0 5 | S15 f 39.0 26.0 0.0 0.0 240.0 0.0 6 | S19 f 77.0 30.0 0.0 0.0 240.0 0.0 7 | C70 c 35.0 69.0 23.0 83.0 113.0 10.0 8 | C57 c 30.0 25.0 23.0 27.0 57.0 10.0 9 | C49 c 42.0 12.0 10.0 85.0 115.0 10.0 10 | C45 c 20.0 82.0 10.0 53.0 83.0 10.0 11 | C54 c 55.0 60.0 16.0 170.0 200.0 10.0 12 | C92 c 53.0 43.0 14.0 140.0 170.0 10.0 13 | C26 c 95.0 30.0 30.0 121.0 151.0 10.0 14 | C11 c 8.0 40.0 40.0 86.0 116.0 10.0 15 | C53 c 20.0 50.0 5.0 0.0 210.0 10.0 16 | C44 c 55.0 82.0 10.0 36.0 66.0 10.0 17 | 18 | Q Vehicle fuel tank capacity /77.75/ 19 | C Vehicle load capacity /200.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /0.39/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/rc108C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 240.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 240.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 240.0 0.0 5 | S5 f 31.0 84.0 0.0 0.0 240.0 0.0 6 | S19 f 77.0 30.0 0.0 0.0 240.0 0.0 7 | C83 c 37.0 31.0 14.0 74.0 192.0 10.0 8 | C45 c 20.0 82.0 10.0 38.0 192.0 10.0 9 | C35 c 67.0 85.0 20.0 61.0 185.0 10.0 10 | C28 c 92.0 30.0 10.0 74.0 174.0 10.0 11 | C79 c 6.0 68.0 30.0 39.0 151.0 10.0 12 | C65 c 35.0 40.0 16.0 12.0 109.0 10.0 13 | C93 c 61.0 52.0 3.0 22.0 101.0 10.0 14 | C85 c 63.0 23.0 2.0 36.0 194.0 10.0 15 | C80 c 47.0 47.0 13.0 8.0 150.0 10.0 16 | C86 c 21.0 24.0 28.0 125.0 197.0 10.0 17 | 18 | Q Vehicle fuel tank capacity /77.75/ 19 | C Vehicle load capacity /200.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /0.39/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/rc201C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 960.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 960.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 960.0 0.0 5 | S9 f 14.0 59.0 0.0 0.0 960.0 0.0 6 | S15 f 39.0 26.0 0.0 0.0 960.0 0.0 7 | C98 c 26.0 52.0 9.0 218.0 338.0 10.0 8 | C14 c 5.0 45.0 10.0 198.0 318.0 10.0 9 | C81 c 49.0 58.0 10.0 784.0 904.0 10.0 10 | C88 c 24.0 58.0 19.0 561.0 681.0 10.0 11 | C62 c 65.0 35.0 3.0 138.0 258.0 10.0 12 | C43 c 55.0 85.0 20.0 102.0 222.0 10.0 13 | C93 c 61.0 52.0 3.0 317.0 437.0 10.0 14 | C22 c 40.0 15.0 40.0 621.0 741.0 10.0 15 | C54 c 55.0 60.0 16.0 557.0 677.0 10.0 16 | C79 c 6.0 68.0 30.0 39.0 159.0 10.0 17 | 18 | Q Vehicle fuel tank capacity /77.75/ 19 | C Vehicle load capacity /1000.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /0.39/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/10/rc205C10.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 960.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 960.0 0.0 4 | S1 f 77.0 52.0 0.0 0.0 960.0 0.0 5 | S3 f 57.0 82.0 0.0 0.0 960.0 0.0 6 | S11 f 10.0 28.0 0.0 0.0 960.0 0.0 7 | C96 c 55.0 54.0 26.0 319.0 355.0 10.0 8 | C43 c 55.0 85.0 20.0 39.0 490.0 10.0 9 | C87 c 12.0 24.0 13.0 441.0 441.0 10.0 10 | C100 c 31.0 67.0 3.0 528.0 528.0 10.0 11 | C15 c 2.0 40.0 20.0 607.0 739.0 10.0 12 | C58 c 15.0 10.0 20.0 198.0 406.0 10.0 13 | C31 c 88.0 35.0 20.0 71.0 689.0 10.0 14 | C82 c 27.0 43.0 9.0 488.0 650.0 10.0 15 | C93 c 61.0 52.0 3.0 350.0 404.0 10.0 16 | C6 c 18.0 75.0 20.0 142.0 494.0 10.0 17 | 18 | Q Vehicle fuel tank capacity /77.75/ 19 | C Vehicle load capacity /1000.0/ 20 | r fuel consumption rate /1.0/ 21 | g inverse refueling rate /0.39/ 22 | v average Velocity /1.0/ 23 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/c103C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 1236.0 0.0 5 | S7 f 21.0 83.0 0.0 0.0 1236.0 0.0 6 | S13 f 22.0 34.0 0.0 0.0 1236.0 0.0 7 | S15 f 39.0 26.0 0.0 0.0 1236.0 0.0 8 | C61 c 50.0 30.0 10.0 980.0 1064.0 90.0 9 | C30 c 20.0 55.0 10.0 0.0 1125.0 90.0 10 | C98 c 58.0 75.0 20.0 0.0 1115.0 90.0 11 | C59 c 38.0 15.0 10.0 66.0 124.0 90.0 12 | C35 c 5.0 35.0 10.0 655.0 725.0 90.0 13 | C13 c 22.0 75.0 30.0 1042.0 1106.0 90.0 14 | C10 c 35.0 66.0 10.0 779.0 845.0 90.0 15 | C44 c 32.0 30.0 10.0 0.0 1124.0 90.0 16 | C50 c 26.0 32.0 10.0 0.0 1123.0 90.0 17 | C95 c 62.0 80.0 30.0 0.0 1108.0 90.0 18 | C18 c 15.0 75.0 20.0 0.0 1110.0 90.0 19 | C33 c 8.0 40.0 40.0 355.0 437.0 90.0 20 | C85 c 68.0 60.0 30.0 0.0 1116.0 90.0 21 | C19 c 15.0 80.0 10.0 455.0 513.0 90.0 22 | C40 c 35.0 30.0 10.0 143.0 199.0 90.0 23 | 24 | Q Vehicle fuel tank capacity /77.75/ 25 | C Vehicle load capacity /200.0/ 26 | r fuel consumption rate /1.0/ 27 | g inverse refueling rate /3.47/ 28 | v average Velocity /1.0/ 29 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/c106C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S15 f 39.0 26.0 0.0 0.0 1236.0 0.0 5 | S19 f 77.0 30.0 0.0 0.0 1236.0 0.0 6 | C44 c 32.0 30.0 10.0 264.0 448.0 90.0 7 | C89 c 63.0 58.0 10.0 877.0 1041.0 90.0 8 | C91 c 60.0 60.0 10.0 733.0 1123.0 90.0 9 | C9 c 38.0 70.0 10.0 760.0 1125.0 90.0 10 | C64 c 48.0 30.0 10.0 204.0 384.0 90.0 11 | C27 c 23.0 52.0 10.0 263.0 311.0 90.0 12 | C20 c 30.0 50.0 10.0 10.0 168.0 90.0 13 | C51 c 25.0 30.0 10.0 747.0 965.0 90.0 14 | C45 c 30.0 30.0 10.0 393.0 503.0 90.0 15 | C68 c 45.0 30.0 10.0 277.0 497.0 90.0 16 | C66 c 47.0 35.0 10.0 957.0 1129.0 90.0 17 | C1 c 45.0 68.0 10.0 19.0 206.0 90.0 18 | C78 c 88.0 35.0 20.0 597.0 801.0 90.0 19 | C84 c 70.0 58.0 20.0 599.0 761.0 90.0 20 | C47 c 30.0 35.0 10.0 664.0 788.0 90.0 21 | 22 | Q Vehicle fuel tank capacity /77.75/ 23 | C Vehicle load capacity /200.0/ 24 | r fuel consumption rate /1.0/ 25 | g inverse refueling rate /3.47/ 26 | v average Velocity /1.0/ 27 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/c202C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 3390.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 3390.0 0.0 4 | S1 f 77.0 52.0 0.0 0.0 3390.0 0.0 5 | S5 f 31.0 84.0 0.0 0.0 3390.0 0.0 6 | S15 f 39.0 26.0 0.0 0.0 3390.0 0.0 7 | S19 f 77.0 30.0 0.0 0.0 3390.0 0.0 8 | C17 c 18.0 75.0 20.0 0.0 3266.0 90.0 9 | C82 c 75.0 55.0 20.0 508.0 668.0 90.0 10 | C43 c 33.0 35.0 10.0 27.0 187.0 90.0 11 | C41 c 35.0 32.0 10.0 0.0 3281.0 90.0 12 | C27 c 23.0 52.0 10.0 2832.0 2992.0 90.0 13 | C99 c 55.0 80.0 10.0 890.0 1050.0 90.0 14 | C3 c 62.0 69.0 10.0 130.0 290.0 90.0 15 | C63 c 50.0 40.0 50.0 1910.0 2070.0 90.0 16 | C58 c 38.0 5.0 30.0 0.0 3254.0 90.0 17 | C73 c 92.0 30.0 10.0 0.0 3244.0 90.0 18 | C87 c 64.0 46.0 20.0 0.0 3275.0 90.0 19 | C10 c 35.0 66.0 10.0 28.0 188.0 90.0 20 | C51 c 25.0 30.0 10.0 587.0 747.0 90.0 21 | C23 c 14.0 66.0 10.0 1176.0 1336.0 90.0 22 | C76 c 90.0 35.0 10.0 845.0 1005.0 90.0 23 | 24 | Q Vehicle fuel tank capacity /77.75/ 25 | C Vehicle load capacity /700.0/ 26 | r fuel consumption rate /1.0/ 27 | g inverse refueling rate /3.47/ 28 | v average Velocity /1.0/ 29 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/c208C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 3390.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 3390.0 0.0 4 | S1 f 77.0 52.0 0.0 0.0 3390.0 0.0 5 | S14 f 27.0 10.0 0.0 0.0 3390.0 0.0 6 | S19 f 77.0 30.0 0.0 0.0 3390.0 0.0 7 | C24 c 25.0 50.0 10.0 2645.0 3285.0 90.0 8 | C20 c 30.0 50.0 10.0 2650.0 3290.0 90.0 9 | C98 c 58.0 75.0 20.0 79.0 719.0 90.0 10 | C75 c 45.0 65.0 20.0 939.0 1579.0 90.0 11 | C79 c 87.0 30.0 10.0 1082.0 1722.0 90.0 12 | C88 c 65.0 60.0 30.0 27.0 667.0 90.0 13 | C31 c 10.0 35.0 20.0 2020.0 2660.0 90.0 14 | C82 c 75.0 55.0 20.0 268.0 908.0 90.0 15 | C59 c 38.0 10.0 10.0 1056.0 1696.0 90.0 16 | C22 c 28.0 52.0 20.0 2647.0 3287.0 90.0 17 | C52 c 25.0 35.0 10.0 162.0 802.0 90.0 18 | C73 c 92.0 30.0 10.0 888.0 1528.0 90.0 19 | C43 c 33.0 35.0 10.0 17.0 657.0 90.0 20 | C85 c 86.0 46.0 30.0 503.0 1143.0 90.0 21 | C7 c 58.0 70.0 20.0 27.0 667.0 90.0 22 | 23 | Q Vehicle fuel tank capacity /77.75/ 24 | C Vehicle load capacity /700.0/ 25 | r fuel consumption rate /1.0/ 26 | g inverse refueling rate /3.47/ 27 | v average Velocity /1.0/ 28 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/r102C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 230.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 230.0 0.0 4 | S1 f 64.0 37.0 0.0 0.0 230.0 0.0 5 | S5 f 28.0 62.0 0.0 0.0 230.0 0.0 6 | S7 f 20.0 61.0 0.0 0.0 230.0 0.0 7 | S9 f 15.0 42.0 0.0 0.0 230.0 0.0 8 | S11 f 11.0 18.0 0.0 0.0 230.0 0.0 9 | S12 f -2.0 25.0 0.0 0.0 230.0 0.0 10 | S14 f 25.0 4.0 0.0 0.0 230.0 0.0 11 | C38 c 5.0 5.0 16.0 113.0 123.0 10.0 12 | C11 c 20.0 65.0 12.0 55.0 65.0 10.0 13 | C45 c 6.0 38.0 16.0 125.0 135.0 10.0 14 | C2 c 35.0 17.0 7.0 0.0 202.0 10.0 15 | C7 c 20.0 50.0 5.0 88.0 98.0 10.0 16 | C59 c 21.0 24.0 28.0 101.0 111.0 10.0 17 | C75 c 49.0 11.0 18.0 0.0 192.0 10.0 18 | C48 c 13.0 52.0 36.0 147.0 157.0 10.0 19 | C17 c 5.0 30.0 2.0 87.0 97.0 10.0 20 | C1 c 41.0 49.0 10.0 36.0 46.0 10.0 21 | C70 c 37.0 56.0 5.0 49.0 59.0 10.0 22 | C91 c 15.0 19.0 1.0 87.0 97.0 10.0 23 | C52 c 27.0 43.0 9.0 111.0 121.0 10.0 24 | C95 c 25.0 24.0 20.0 140.0 150.0 10.0 25 | C80 c 56.0 37.0 6.0 108.0 118.0 10.0 26 | 27 | Q Vehicle fuel tank capacity /60.63/ 28 | C Vehicle load capacity /200.0/ 29 | r fuel consumption rate /1.0/ 30 | g inverse refueling rate /0.49/ 31 | v average Velocity /1.0/ 32 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/r105C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 230.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 230.0 0.0 4 | S1 f 64.0 37.0 0.0 0.0 230.0 0.0 5 | S3 f 48.0 60.0 0.0 0.0 230.0 0.0 6 | S13 f 21.0 22.0 0.0 0.0 230.0 0.0 7 | S17 f 51.0 7.0 0.0 0.0 230.0 0.0 8 | S19 f 64.0 19.0 0.0 0.0 230.0 0.0 9 | C23 c 55.0 5.0 29.0 87.0 117.0 10.0 10 | C57 c 32.0 12.0 7.0 166.0 196.0 10.0 11 | C50 c 47.0 47.0 13.0 108.0 138.0 10.0 12 | C69 c 37.0 47.0 6.0 141.0 171.0 10.0 13 | C85 c 16.0 22.0 41.0 83.0 113.0 10.0 14 | C25 c 65.0 20.0 6.0 156.0 186.0 10.0 15 | C56 c 53.0 12.0 6.0 48.0 78.0 10.0 16 | C5 c 15.0 30.0 26.0 153.0 183.0 10.0 17 | C70 c 37.0 56.0 5.0 39.0 69.0 10.0 18 | C28 c 41.0 37.0 16.0 183.0 213.0 10.0 19 | C29 c 64.0 42.0 9.0 107.0 137.0 10.0 20 | C8 c 10.0 43.0 9.0 27.0 57.0 10.0 21 | C9 c 55.0 60.0 16.0 72.0 102.0 10.0 22 | C95 c 25.0 24.0 20.0 130.0 160.0 10.0 23 | C17 c 5.0 30.0 2.0 77.0 107.0 10.0 24 | 25 | Q Vehicle fuel tank capacity /60.63/ 26 | C Vehicle load capacity /200.0/ 27 | r fuel consumption rate /1.0/ 28 | g inverse refueling rate /0.49/ 29 | v average Velocity /1.0/ 30 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/r202C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 1000.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 1000.0 0.0 4 | S5 f 28.0 62.0 0.0 0.0 1000.0 0.0 5 | S9 f 15.0 42.0 0.0 0.0 1000.0 0.0 6 | S13 f 21.0 22.0 0.0 0.0 1000.0 0.0 7 | S15 f 34.0 16.0 0.0 0.0 1000.0 0.0 8 | S19 f 64.0 19.0 0.0 0.0 1000.0 0.0 9 | C79 c 57.0 48.0 23.0 0.0 964.0 10.0 10 | C44 c 11.0 14.0 18.0 42.0 178.0 10.0 11 | C23 c 55.0 5.0 29.0 53.0 233.0 10.0 12 | C38 c 5.0 5.0 16.0 0.0 947.0 10.0 13 | C25 c 65.0 20.0 6.0 418.0 532.0 10.0 14 | C41 c 42.0 7.0 5.0 782.0 912.0 10.0 15 | C70 c 37.0 56.0 5.0 0.0 968.0 10.0 16 | C85 c 16.0 22.0 41.0 552.0 744.0 10.0 17 | C87 c 28.0 18.0 26.0 530.0 568.0 10.0 18 | C46 c 2.0 48.0 1.0 46.0 182.0 10.0 19 | C61 c 12.0 24.0 13.0 329.0 551.0 10.0 20 | C48 c 13.0 52.0 36.0 418.0 558.0 10.0 21 | C42 c 24.0 12.0 5.0 0.0 964.0 10.0 22 | C72 c 47.0 16.0 25.0 104.0 252.0 10.0 23 | C11 c 20.0 65.0 12.0 0.0 956.0 10.0 24 | 25 | Q Vehicle fuel tank capacity /60.63/ 26 | C Vehicle load capacity /1000.0/ 27 | r fuel consumption rate /1.0/ 28 | g inverse refueling rate /0.49/ 29 | v average Velocity /1.0/ 30 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/r209C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 1000.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 1000.0 0.0 4 | S1 f 64.0 37.0 0.0 0.0 1000.0 0.0 5 | S3 f 48.0 60.0 0.0 0.0 1000.0 0.0 6 | S7 f 20.0 61.0 0.0 0.0 1000.0 0.0 7 | S13 f 21.0 22.0 0.0 0.0 1000.0 0.0 8 | C47 c 8.0 56.0 27.0 371.0 819.0 10.0 9 | C87 c 28.0 18.0 26.0 535.0 563.0 10.0 10 | C9 c 55.0 60.0 16.0 395.0 835.0 10.0 11 | C88 c 26.0 52.0 9.0 165.0 617.0 10.0 12 | C46 c 2.0 48.0 1.0 46.0 460.0 10.0 13 | C27 c 35.0 40.0 16.0 97.0 679.0 10.0 14 | C10 c 30.0 60.0 16.0 489.0 787.0 10.0 15 | C70 c 37.0 56.0 5.0 22.0 286.0 10.0 16 | C30 c 40.0 60.0 21.0 422.0 726.0 10.0 17 | C5 c 15.0 30.0 26.0 21.0 535.0 10.0 18 | C22 c 45.0 10.0 18.0 607.0 963.0 10.0 19 | C79 c 57.0 48.0 23.0 26.0 389.0 10.0 20 | C4 c 55.0 20.0 19.0 701.0 883.0 10.0 21 | C63 c 27.0 69.0 10.0 360.0 890.0 10.0 22 | C34 c 65.0 55.0 14.0 116.0 502.0 10.0 23 | 24 | Q Vehicle fuel tank capacity /60.63/ 25 | C Vehicle load capacity /1000.0/ 26 | r fuel consumption rate /1.0/ 27 | g inverse refueling rate /0.49/ 28 | v average Velocity /1.0/ 29 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/rc103C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 240.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 240.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 240.0 0.0 5 | S7 f 21.0 83.0 0.0 0.0 240.0 0.0 6 | S11 f 10.0 28.0 0.0 0.0 240.0 0.0 7 | S19 f 77.0 30.0 0.0 0.0 240.0 0.0 8 | C33 c 85.0 25.0 10.0 0.0 178.0 10.0 9 | C84 c 57.0 29.0 18.0 73.0 103.0 10.0 10 | C15 c 2.0 40.0 20.0 160.0 190.0 10.0 11 | C6 c 18.0 75.0 20.0 0.0 196.0 10.0 12 | C90 c 37.0 47.0 6.0 145.0 175.0 10.0 13 | C62 c 65.0 35.0 3.0 0.0 200.0 10.0 14 | C8 c 15.0 80.0 10.0 125.0 155.0 10.0 15 | C39 c 60.0 80.0 10.0 100.0 130.0 10.0 16 | C34 c 85.0 35.0 30.0 0.0 182.0 10.0 17 | C65 c 35.0 40.0 16.0 31.0 61.0 10.0 18 | C70 c 35.0 69.0 23.0 0.0 210.0 10.0 19 | C72 c 63.0 65.0 8.0 106.0 136.0 10.0 20 | C87 c 12.0 24.0 13.0 58.0 88.0 10.0 21 | C100 c 31.0 67.0 3.0 0.0 210.0 10.0 22 | C83 c 37.0 31.0 14.0 0.0 210.0 10.0 23 | 24 | Q Vehicle fuel tank capacity /77.75/ 25 | C Vehicle load capacity /200.0/ 26 | r fuel consumption rate /1.0/ 27 | g inverse refueling rate /0.39/ 28 | v average Velocity /1.0/ 29 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/rc108C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 240.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 240.0 0.0 4 | S5 f 31.0 84.0 0.0 0.0 240.0 0.0 5 | S15 f 39.0 26.0 0.0 0.0 240.0 0.0 6 | S17 f 61.0 14.0 0.0 0.0 240.0 0.0 7 | S19 f 77.0 30.0 0.0 0.0 240.0 0.0 8 | C6 c 18.0 75.0 20.0 53.0 187.0 10.0 9 | C10 c 10.0 40.0 30.0 54.0 154.0 10.0 10 | C41 c 58.0 75.0 20.0 66.0 184.0 10.0 11 | C54 c 55.0 60.0 16.0 100.0 211.0 10.0 12 | C45 c 20.0 82.0 10.0 38.0 192.0 10.0 13 | C46 c 18.0 80.0 10.0 70.0 192.0 10.0 14 | C19 c 42.0 10.0 40.0 64.0 182.0 10.0 15 | C25 c 35.0 5.0 20.0 79.0 184.0 10.0 16 | C23 c 38.0 5.0 30.0 55.0 184.0 10.0 17 | C83 c 37.0 31.0 14.0 74.0 192.0 10.0 18 | C53 c 20.0 50.0 5.0 20.0 136.0 10.0 19 | C40 c 60.0 85.0 30.0 96.0 189.0 10.0 20 | C33 c 85.0 25.0 10.0 68.0 178.0 10.0 21 | C63 c 65.0 20.0 6.0 60.0 190.0 10.0 22 | C66 c 41.0 37.0 16.0 14.0 146.0 10.0 23 | 24 | Q Vehicle fuel tank capacity /77.75/ 25 | C Vehicle load capacity /200.0/ 26 | r fuel consumption rate /1.0/ 27 | g inverse refueling rate /0.39/ 28 | v average Velocity /1.0/ 29 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/rc202C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 960.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 960.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 960.0 0.0 5 | S7 f 21.0 83.0 0.0 0.0 960.0 0.0 6 | S13 f 22.0 34.0 0.0 0.0 960.0 0.0 7 | S16 f 48.0 8.0 0.0 0.0 960.0 0.0 8 | C95 c 56.0 37.0 6.0 529.0 649.0 10.0 9 | C11 c 8.0 40.0 40.0 401.0 521.0 10.0 10 | C50 c 72.0 35.0 30.0 736.0 856.0 10.0 11 | C90 c 37.0 47.0 6.0 80.0 200.0 10.0 12 | C18 c 44.0 5.0 20.0 0.0 904.0 10.0 13 | C72 c 63.0 65.0 8.0 331.0 451.0 10.0 14 | C45 c 20.0 82.0 10.0 646.0 766.0 10.0 15 | C43 c 55.0 85.0 20.0 102.0 222.0 10.0 16 | C1 c 25.0 85.0 20.0 300.0 420.0 10.0 17 | C47 c 2.0 45.0 10.0 0.0 911.0 10.0 18 | C37 c 65.0 82.0 10.0 280.0 400.0 10.0 19 | C57 c 30.0 25.0 23.0 226.0 346.0 10.0 20 | C64 c 45.0 30.0 17.0 628.0 748.0 10.0 21 | C52 c 25.0 30.0 3.0 553.0 673.0 10.0 22 | C46 c 18.0 80.0 10.0 792.0 912.0 10.0 23 | 24 | Q Vehicle fuel tank capacity /77.75/ 25 | C Vehicle load capacity /1000.0/ 26 | r fuel consumption rate /1.0/ 27 | g inverse refueling rate /0.39/ 28 | v average Velocity /1.0/ 29 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/15/rc204C15.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 960.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 960.0 0.0 4 | S7 f 21.0 83.0 0.0 0.0 960.0 0.0 5 | S9 f 14.0 59.0 0.0 0.0 960.0 0.0 6 | S11 f 10.0 28.0 0.0 0.0 960.0 0.0 7 | S13 f 22.0 34.0 0.0 0.0 960.0 0.0 8 | S14 f 27.0 10.0 0.0 0.0 960.0 0.0 9 | S17 f 61.0 14.0 0.0 0.0 960.0 0.0 10 | C79 c 6.0 68.0 30.0 39.0 159.0 10.0 11 | C10 c 10.0 40.0 30.0 0.0 918.0 10.0 12 | C61 c 45.0 65.0 9.0 618.0 738.0 10.0 13 | C2 c 22.0 75.0 30.0 0.0 919.0 10.0 14 | C98 c 26.0 52.0 9.0 0.0 935.0 10.0 15 | C49 c 42.0 12.0 10.0 0.0 911.0 10.0 16 | C1 c 25.0 85.0 20.0 300.0 420.0 10.0 17 | C63 c 65.0 20.0 6.0 0.0 910.0 10.0 18 | C74 c 20.0 20.0 8.0 0.0 913.0 10.0 19 | C75 c 5.0 5.0 16.0 0.0 879.0 10.0 20 | C22 c 40.0 15.0 40.0 0.0 915.0 10.0 21 | C20 c 42.0 15.0 10.0 208.0 328.0 10.0 22 | C76 c 60.0 12.0 31.0 0.0 907.0 10.0 23 | C48 c 42.0 5.0 10.0 0.0 904.0 10.0 24 | C86 c 21.0 24.0 28.0 0.0 917.0 10.0 25 | 26 | Q Vehicle fuel tank capacity /77.75/ 27 | C Vehicle load capacity /1000.0/ 28 | r fuel consumption rate /1.0/ 29 | g inverse refueling rate /0.39/ 30 | v average Velocity /1.0/ 31 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/c101C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S5 f 31.0 84.0 0.0 0.0 1236.0 0.0 5 | S15 f 39.0 26.0 0.0 0.0 1236.0 0.0 6 | C30 c 20.0 55.0 10.0 355.0 407.0 90.0 7 | C12 c 25.0 85.0 20.0 176.0 228.0 90.0 8 | C100 c 55.0 85.0 20.0 744.0 798.0 90.0 9 | C85 c 68.0 60.0 30.0 737.0 809.0 90.0 10 | C64 c 48.0 30.0 10.0 263.0 325.0 90.0 11 | 12 | Q Vehicle fuel tank capacity /77.75/ 13 | C Vehicle load capacity /200.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /3.47/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/c103C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S15 f 39.0 26.0 0.0 0.0 1236.0 0.0 5 | C20 c 30.0 50.0 10.0 0.0 1136.0 90.0 6 | C98 c 58.0 75.0 20.0 0.0 1115.0 90.0 7 | C65 c 48.0 40.0 10.0 67.0 139.0 90.0 8 | C57 c 40.0 15.0 40.0 989.0 1063.0 90.0 9 | C24 c 25.0 50.0 10.0 0.0 1131.0 90.0 10 | 11 | Q Vehicle fuel tank capacity /77.75/ 12 | C Vehicle load capacity /200.0/ 13 | r fuel consumption rate /1.0/ 14 | g inverse refueling rate /3.47/ 15 | v average Velocity /1.0/ 16 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/c206C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 3390.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 3390.0 0.0 4 | S11 f 10.0 28.0 0.0 0.0 3390.0 0.0 5 | S15 f 39.0 26.0 0.0 0.0 3390.0 0.0 6 | S17 f 61.0 14.0 0.0 0.0 3390.0 0.0 7 | C35 c 5.0 35.0 10.0 1954.0 2536.0 90.0 8 | C53 c 44.0 5.0 20.0 1442.0 2060.0 90.0 9 | C44 c 32.0 20.0 10.0 693.0 1215.0 90.0 10 | C77 c 72.0 45.0 10.0 1419.0 1969.0 90.0 11 | C75 c 45.0 65.0 20.0 948.0 1570.0 90.0 12 | 13 | Q Vehicle fuel tank capacity /77.75/ 14 | C Vehicle load capacity /700.0/ 15 | r fuel consumption rate /1.0/ 16 | g inverse refueling rate /3.47/ 17 | v average Velocity /1.0/ 18 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/c208C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 3390.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 3390.0 0.0 4 | S11 f 10.0 28.0 0.0 0.0 3390.0 0.0 5 | S14 f 27.0 10.0 0.0 0.0 3390.0 0.0 6 | C39 c 0.0 45.0 20.0 1642.0 2282.0 90.0 7 | C50 c 26.0 32.0 10.0 255.0 895.0 90.0 8 | C60 c 35.0 5.0 20.0 1152.0 1792.0 90.0 9 | C58 c 38.0 5.0 30.0 1245.0 1885.0 90.0 10 | C53 c 44.0 5.0 20.0 1431.0 2071.0 90.0 11 | 12 | Q Vehicle fuel tank capacity /77.75/ 13 | C Vehicle load capacity /700.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /3.47/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/r104C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 230.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 230.0 0.0 4 | S3 f 48.0 60.0 0.0 0.0 230.0 0.0 5 | S9 f 15.0 42.0 0.0 0.0 230.0 0.0 6 | C71 c 57.0 68.0 15.0 0.0 180.0 10.0 7 | C1 c 41.0 49.0 10.0 36.0 46.0 10.0 8 | C5 c 15.0 30.0 26.0 0.0 199.0 10.0 9 | C87 c 28.0 18.0 26.0 166.0 176.0 10.0 10 | C99 c 20.0 26.0 9.0 0.0 202.0 10.0 11 | 12 | Q Vehicle fuel tank capacity /60.63/ 13 | C Vehicle load capacity /200.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /0.49/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/r105C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 230.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 230.0 0.0 4 | S1 f 64.0 37.0 0.0 0.0 230.0 0.0 5 | S13 f 21.0 22.0 0.0 0.0 230.0 0.0 6 | C91 c 15.0 19.0 1.0 77.0 107.0 10.0 7 | C28 c 41.0 37.0 16.0 183.0 213.0 10.0 8 | C75 c 49.0 11.0 18.0 49.0 79.0 10.0 9 | C78 c 61.0 52.0 3.0 158.0 188.0 10.0 10 | C95 c 25.0 24.0 20.0 130.0 160.0 10.0 11 | 12 | Q Vehicle fuel tank capacity /60.63/ 13 | C Vehicle load capacity /200.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /0.49/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/r202C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 1000.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 1000.0 0.0 4 | S13 f 21.0 22.0 0.0 0.0 1000.0 0.0 5 | S15 f 34.0 16.0 0.0 0.0 1000.0 0.0 6 | C77 c 53.0 43.0 14.0 86.0 224.0 10.0 7 | C17 c 5.0 30.0 2.0 0.0 959.0 10.0 8 | C37 c 20.0 20.0 8.0 0.0 968.0 10.0 9 | C18 c 20.0 40.0 12.0 403.0 513.0 10.0 10 | C72 c 47.0 16.0 25.0 104.0 252.0 10.0 11 | 12 | Q Vehicle fuel tank capacity /60.63/ 13 | C Vehicle load capacity /1000.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /0.49/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/r203C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 35.0 35.0 0.0 0.0 1000.0 0.0 3 | S0 f 35.0 35.0 0.0 0.0 1000.0 0.0 4 | S1 f 64.0 37.0 0.0 0.0 1000.0 0.0 5 | S7 f 20.0 61.0 0.0 0.0 1000.0 0.0 6 | S9 f 15.0 42.0 0.0 0.0 1000.0 0.0 7 | C50 c 47.0 47.0 13.0 507.0 599.0 10.0 8 | C96 c 22.0 27.0 11.0 0.0 974.0 10.0 9 | C79 c 57.0 48.0 23.0 0.0 964.0 10.0 10 | C25 c 65.0 20.0 6.0 418.0 532.0 10.0 11 | C49 c 6.0 68.0 30.0 0.0 946.0 10.0 12 | 13 | Q Vehicle fuel tank capacity /60.63/ 14 | C Vehicle load capacity /1000.0/ 15 | r fuel consumption rate /1.0/ 16 | g inverse refueling rate /0.49/ 17 | v average Velocity /1.0/ 18 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/rc105C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 240.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 240.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 240.0 0.0 5 | S9 f 14.0 59.0 0.0 0.0 240.0 0.0 6 | S15 f 39.0 26.0 0.0 0.0 240.0 0.0 7 | C11 c 8.0 40.0 40.0 76.0 126.0 10.0 8 | C22 c 40.0 15.0 40.0 96.0 146.0 10.0 9 | C55 c 30.0 60.0 16.0 15.0 116.0 10.0 10 | C82 c 27.0 43.0 9.0 111.0 147.0 10.0 11 | C36 c 65.0 85.0 40.0 59.0 114.0 10.0 12 | 13 | Q Vehicle fuel tank capacity /77.75/ 14 | C Vehicle load capacity /200.0/ 15 | r fuel consumption rate /1.0/ 16 | g inverse refueling rate /0.39/ 17 | v average Velocity /1.0/ 18 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/rc108C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 240.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 240.0 0.0 4 | S11 f 10.0 28.0 0.0 0.0 240.0 0.0 5 | S14 f 27.0 10.0 0.0 0.0 240.0 0.0 6 | S19 f 77.0 30.0 0.0 0.0 240.0 0.0 7 | C34 c 85.0 35.0 30.0 68.0 182.0 10.0 8 | C21 c 40.0 5.0 10.0 55.0 185.0 10.0 9 | C97 c 4.0 18.0 35.0 58.0 131.0 10.0 10 | C71 c 65.0 55.0 14.0 26.0 111.0 10.0 11 | C15 c 2.0 40.0 20.0 96.0 190.0 10.0 12 | 13 | Q Vehicle fuel tank capacity /77.75/ 14 | C Vehicle load capacity /200.0/ 15 | r fuel consumption rate /1.0/ 16 | g inverse refueling rate /0.39/ 17 | v average Velocity /1.0/ 18 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/rc204C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 960.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 960.0 0.0 4 | S9 f 14.0 59.0 0.0 0.0 960.0 0.0 5 | S13 f 22.0 34.0 0.0 0.0 960.0 0.0 6 | S15 f 39.0 26.0 0.0 0.0 960.0 0.0 7 | C23 c 38.0 5.0 30.0 0.0 904.0 10.0 8 | C19 c 42.0 10.0 40.0 0.0 909.0 10.0 9 | C49 c 42.0 12.0 10.0 0.0 911.0 10.0 10 | C4 c 20.0 80.0 40.0 712.0 832.0 10.0 11 | C81 c 49.0 58.0 10.0 0.0 937.0 10.0 12 | 13 | Q Vehicle fuel tank capacity /77.75/ 14 | C Vehicle load capacity /1000.0/ 15 | r fuel consumption rate /1.0/ 16 | g inverse refueling rate /0.39/ 17 | v average Velocity /1.0/ 18 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/5/rc208C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 960.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 960.0 0.0 4 | S3 f 57.0 82.0 0.0 0.0 960.0 0.0 5 | S19 f 77.0 30.0 0.0 0.0 960.0 0.0 6 | C66 c 41.0 37.0 16.0 383.0 905.0 10.0 7 | C37 c 65.0 82.0 10.0 59.0 632.0 10.0 8 | C96 c 55.0 54.0 26.0 142.0 532.0 10.0 9 | C41 c 58.0 75.0 20.0 73.0 561.0 10.0 10 | C32 c 87.0 30.0 10.0 69.0 539.0 10.0 11 | 12 | Q Vehicle fuel tank capacity /77.75/ 13 | C Vehicle load capacity /1000.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /0.39/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /examples/evrptw/instances/evrptw/README.txt: -------------------------------------------------------------------------------- 1 | The instances are formatted as follows: 2 | 3 | ###For each location the instance provides: 4 | -StringId as a unique identifier 5 | -Type indicates the function of the location, i.e, 6 | ---d: depot 7 | ---f: recharging station 8 | ---c: customer location 9 | -x, y are coordinates (distances are assumed to be euclidean) 10 | -demand specifies the quantity of freight capacity required 11 | -ReadyTime and DueDate are the beginning and the end of the time window (waiting is allowed) 12 | -ServiceTime denotes the entire time spend at customer for loading operations 13 | 14 | ###For the electric vehicles (all identical): 15 | -"Q Vehicle fuel tank capacity": units of energy available 16 | -"C Vehicle load capacity": units available for cargo 17 | -"r fuel consumption rate": reduction of battery capacity when traveling one unit of distance 18 | -"g inverse refueling rate": units of time required to recharge one unit of energy 19 | -"v average Velocity": assumed to be constant on all arcs, required to calculate the travel time from distance -------------------------------------------------------------------------------- /examples/evrptw/operators/ShawMoveSelector.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from typing import Iterable 21 | 22 | import routingblocks 23 | from routingblocks.operators.related_removal import RelatedVertexRemovalMove 24 | from evrptw.instance import Instance 25 | 26 | 27 | class ShawMoveSelector: 28 | def __init__(self, instance: Instance, cpp_instance: routingblocks.Instance, randgen: routingblocks.Random, shaw_exponent: float): 29 | self._instance = instance 30 | self._cpp_id_to_vertex = [self._instance.vertices[x.str_id] for x in cpp_instance] 31 | self._shaw_exponent = shaw_exponent 32 | self._randgen = randgen 33 | 34 | def __call__(self, move_iter: Iterable[RelatedVertexRemovalMove]) -> RelatedVertexRemovalMove: 35 | # Ignore stations 36 | non_station_nodes = [x for x in move_iter if not self._cpp_id_to_vertex[x.vertex_id].is_station] 37 | # Pick nth 38 | pos = int(len(non_station_nodes) * (self._randgen.uniform(0., 1.) ** self._shaw_exponent)) 39 | return non_station_nodes[pos] 40 | -------------------------------------------------------------------------------- /examples/evrptw/operators/ShawRelatedness.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | import routingblocks 21 | from sys import float_info 22 | from evrptw.instance import Instance 23 | 24 | 25 | class ShawRelatedness: 26 | def __init__(self, py_instance: Instance, cpp_instance: routingblocks.Instance, distance_weight: float, 27 | demand_weight: float, 28 | time_weight: float): 29 | self._py_instance = py_instance 30 | self._cpp_id_to_vertex = [self._py_instance.vertices[x.str_id] for x in cpp_instance] 31 | 32 | self._distance_weight = distance_weight 33 | self._demand_weight = demand_weight 34 | self._time_weight = time_weight 35 | 36 | self._max_distance = max(x.cost for x in self._py_instance.arcs.values()) 37 | self._max_demand = max(x.demand for x in self._py_instance.vertices.values()) 38 | self._min_demand = min(x.demand for x in self._py_instance.vertices.values()) 39 | self._max_earliest_arrival_time = max(x.ready_time for x in self._py_instance.vertices.values()) 40 | self._min_earliest_arrival_time = min(x.ready_time for x in self._py_instance.vertices.values()) 41 | 42 | def __call__(self, i: int, j: int) -> float: 43 | vertex_i, vertex_j = self._cpp_id_to_vertex[i], self._cpp_id_to_vertex[j] 44 | d_ij = self._py_instance.arcs[vertex_i.vertex_id, vertex_j.vertex_id].cost 45 | relatedness = ( 46 | self._distance_weight * (d_ij / self._max_distance) + 47 | self._demand_weight * (abs(vertex_i.demand - vertex_j.demand) / (self._max_demand - self._min_demand)) + 48 | self._time_weight * (abs(vertex_i.ready_time - vertex_j.ready_time) 49 | / (self._max_earliest_arrival_time - self._min_earliest_arrival_time)) 50 | ) 51 | return 1.0 / relatedness if relatedness != 0. else float_info.max 52 | -------------------------------------------------------------------------------- /examples/evrptw/operators/SpatioTemporalRelatedness.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | import routingblocks 21 | from sys import float_info 22 | from evrptw.instance import Instance 23 | 24 | 25 | class SpatioTemporalRelatedness: 26 | def __init__(self, py_instance: Instance, cpp_instance: routingblocks.Instance, slack_weight: float, 27 | tw_shift_weight: float): 28 | self._py_instance = py_instance 29 | self._cpp_id_to_vertex = [self._py_instance.vertices[x.str_id] for x in cpp_instance] 30 | self._slack_weight = slack_weight 31 | self._tw_shift_weight = tw_shift_weight 32 | 33 | def __call__(self, i: int, j: int) -> float: 34 | vertex_i, vertex_j = self._cpp_id_to_vertex[i], self._cpp_id_to_vertex[j] 35 | t_ij = self._py_instance.arcs[vertex_i.vertex_id, vertex_j.vertex_id].travel_time 36 | inverse_relatedness = (t_ij \ 37 | + max(0, 38 | vertex_j.ready_time - vertex_i.service_time - t_ij - vertex_i.ready_time) * self._slack_weight \ 39 | + max(0, 40 | vertex_i.ready_time + vertex_i.service_time + t_ij - vertex_j.due_time) * self._tw_shift_weight) 41 | return 1.0 / inverse_relatedness if inverse_relatedness != 0. else float_info.max 42 | -------------------------------------------------------------------------------- /examples/evrptw/parameters.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from dataclasses import dataclass 21 | from typing import Tuple 22 | 23 | 24 | @dataclass 25 | class ALNSParams: 26 | adaptive_smoothing_factor: float = 0.2 27 | min_removed_customer_percentage: float = 0.1 28 | max_removed_customer_percentage: float = 0.5 29 | new_best_feasible_score: float = 9 30 | new_best_score: float = 4 31 | new_improvement_score: float = 1 32 | 33 | num_starting_solutions: int = 1 34 | 35 | delta_local_search: float = 0.3 36 | delta_fpo: float = 0.05 37 | 38 | adaptive_period_length: int = 50 39 | penalty_period_length: int = 50 40 | 41 | target_feasibility_ratios: Tuple[float] = (0.9, 0.9, 0.9) 42 | penalty_increase_factor: float = 1.2 43 | penalty_decrease_factor: float = 0.8 44 | initial_penalties: Tuple[float] = (100., 100., 100.) 45 | 46 | use_best_improvement: bool = True 47 | shuffle_operators: bool = False 48 | 49 | # Shaw removal operator 50 | distance_weight: float = 0.75 51 | demand_weight: float = 0.1 52 | time_weight: float = 0.1 53 | shaw_exponent: float = 4. 54 | 55 | # Related Removal Operator 56 | tw_shift_weight: float = 1.0 57 | slack_weight: float = 1.0 58 | 59 | vehicle_decrease_period_length: int = 250 60 | vehicle_decreased_search_period_length: int = 150 61 | 62 | worst_removal_blink_probability: float = 0.01 63 | best_insertion_blink_probability: float = 0.15 64 | granularity: int = 30 65 | -------------------------------------------------------------------------------- /examples/evrptw/requirements.txt: -------------------------------------------------------------------------------- 1 | pydantic~=1.10 2 | click 3 | -------------------------------------------------------------------------------- /examples/evrptw/utility/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .algorithms import distribute_randomly 21 | -------------------------------------------------------------------------------- /examples/evrptw/utility/algorithms.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from typing import TypeVar, List 21 | import random 22 | 23 | T = TypeVar('T') 24 | 25 | 26 | def distribute_randomly(sequence: List[T], num_subsequences: int, randgen=random.Random()) -> List[List[T]]: 27 | subsequences = [[] for _ in range(num_subsequences)] 28 | for item in sequence: 29 | subsequences[randgen.randint(0, len(subsequences) - 1)].append(item) 30 | return subsequences 31 | -------------------------------------------------------------------------------- /examples/ils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /examples/ils/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from pathlib import Path 21 | import argparse 22 | 23 | from .parsing import parse_instance, create_instance 24 | from .ils import iterated_local_search 25 | 26 | 27 | def solve(instance_path: Path, number_of_iterations: int = 100): 28 | vertices, arcs, params = parse_instance(instance_path) 29 | instance = create_instance(vertices, arcs) 30 | vehicle_storage_capacity = params['C'] 31 | # Vehicle battery capacity in units of time: 32 | # battery capacity * inverse refueling rate = battery capacity / refueling rate 33 | vehicle_battery_capacity_time = params['Q'] * params['g'] 34 | 35 | solution = iterated_local_search(instance=instance, vehicle_storage_capacity=vehicle_storage_capacity, 36 | vehicle_battery_capacity_time=vehicle_battery_capacity_time, 37 | number_of_iterations=number_of_iterations 38 | ) 39 | 40 | print("Best solution:") 41 | print(solution) 42 | 43 | 44 | def main(): 45 | parser = argparse.ArgumentParser(description="Solve a EVRP-TW-PR instance with ILS.") 46 | 47 | parser.add_argument( 48 | "instance_path", 49 | type=Path, 50 | help="Path to the instance file." 51 | ) 52 | 53 | parser.add_argument( 54 | "-n", "--number_of_iterations", 55 | type=int, 56 | default=100, 57 | help="Number of ILS iterations to perform (default: 100)." 58 | ) 59 | 60 | args = parser.parse_args() 61 | 62 | solve(Path(args.instance_path), args.number_of_iterations) 63 | 64 | 65 | if __name__ == '__main__': 66 | main() 67 | -------------------------------------------------------------------------------- /native/cmake/tools.cmake: -------------------------------------------------------------------------------- 1 | # this file contains a list of tools that can be activated and downloaded on-demand each tool is 2 | # enabled during configuration by passing an additional `-DUSE_=` argument to CMake 3 | 4 | # only activate tools for top level project 5 | if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 6 | return() 7 | endif() 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) 10 | 11 | # enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address, 12 | # Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined' 13 | if(USE_SANITIZER OR USE_STATIC_ANALYZER) 14 | CPMAddPackage("gh:StableCoder/cmake-scripts#1f822d1fc87c8d7720c074cde8a278b44963c354") 15 | 16 | if(USE_SANITIZER) 17 | include(${cmake-scripts_SOURCE_DIR}/sanitizers.cmake) 18 | endif() 19 | 20 | if(USE_STATIC_ANALYZER) 21 | if("clang-tidy" IN_LIST USE_STATIC_ANALYZER) 22 | set(CLANG_TIDY 23 | ON 24 | CACHE INTERNAL "" 25 | ) 26 | else() 27 | set(CLANG_TIDY 28 | OFF 29 | CACHE INTERNAL "" 30 | ) 31 | endif() 32 | if("iwyu" IN_LIST USE_STATIC_ANALYZER) 33 | set(IWYU 34 | ON 35 | CACHE INTERNAL "" 36 | ) 37 | else() 38 | set(IWYU 39 | OFF 40 | CACHE INTERNAL "" 41 | ) 42 | endif() 43 | if("cppcheck" IN_LIST USE_STATIC_ANALYZER) 44 | set(CPPCHECK 45 | ON 46 | CACHE INTERNAL "" 47 | ) 48 | else() 49 | set(CPPCHECK 50 | OFF 51 | CACHE INTERNAL "" 52 | ) 53 | endif() 54 | 55 | include(${cmake-scripts_SOURCE_DIR}/tools.cmake) 56 | 57 | clang_tidy(${CLANG_TIDY_ARGS}) 58 | include_what_you_use(${IWYU_ARGS}) 59 | cppcheck(${CPPCHECK_ARGS}) 60 | endif() 61 | endif() 62 | 63 | # enables CCACHE support through the USE_CCACHE flag possible values are: YES, NO or equivalent 64 | if(USE_CCACHE) 65 | CPMAddPackage("gh:TheLartians/Ccache.cmake@1.2.3") 66 | endif() 67 | -------------------------------------------------------------------------------- /native/include/routingblocks/arc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef _routingblocks_ARC_H 24 | #define _routingblocks_ARC_H 25 | 26 | #include 27 | 28 | namespace routingblocks { 29 | struct Arc { 30 | using data_t = std::shared_ptr; 31 | // Pointer to type-erased (arbitrary) data 32 | data_t data; 33 | 34 | explicit Arc(data_t data); 35 | 36 | template T& get_data() { return *static_cast(data.get()); } 37 | template const T& get_data() const { return *static_cast(data.get()); } 38 | }; 39 | } // namespace routingblocks 40 | 41 | #endif //_routingblocks_ARC_H 42 | -------------------------------------------------------------------------------- /native/include/routingblocks/operators/InterRouteTwoOptOperator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef routingblocks_INTERROUTETWOOPT_H 24 | #define routingblocks_INTERROUTETWOOPT_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace routingblocks { 32 | class InterRouteTwoOptMove : public GeneratorArcMove { 33 | public: 34 | using GeneratorArcMove::GeneratorArcMove; 35 | 36 | void apply_to(const Instance& instance, Solution& solution) const; 37 | 38 | [[nodiscard]] cost_t evaluate(Evaluation& evaluation, const Instance& instance, 39 | const Solution& solution) const; 40 | }; 41 | 42 | class InterRouteTwoOptOperator : public GeneratorArcOperator { 43 | public: 44 | using GeneratorArcOperator::GeneratorArcOperator; 45 | }; 46 | } // namespace routingblocks 47 | 48 | #endif // routingblocks_INTERROUTETWOOPT_H 49 | -------------------------------------------------------------------------------- /native/include/routingblocks/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef routingblocks_TYPES_H 23 | #define routingblocks_TYPES_H 24 | 25 | using resource_t = float; 26 | using cost_t = float; 27 | 28 | #endif // routingblocks_TYPES_H 29 | -------------------------------------------------------------------------------- /native/include/routingblocks/utility/algorithms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | // 23 | // Created by patrick on 3/10/23. 24 | // 25 | 26 | #ifndef routingblocks_ALGORITHMS_H 27 | #define routingblocks_ALGORITHMS_H 28 | 29 | namespace routingblocks::utility { 30 | 31 | template 32 | void apply_permutation(std::vector& vec, const std::vector& permutation) { 33 | std::vector done(vec.size()); 34 | for (size_t i = 0; i < vec.size(); ++i) { 35 | if (done[i]) { 36 | continue; 37 | } 38 | done[i] = true; 39 | size_t prev_j = i; 40 | size_t j = permutation[i]; 41 | while (i != j) { 42 | std::swap(vec[prev_j], vec[j]); 43 | done[j] = true; 44 | prev_j = j; 45 | j = permutation[j]; 46 | } 47 | } 48 | } 49 | 50 | } // namespace routingblocks::utility 51 | 52 | #endif // routingblocks_ALGORITHMS_H 53 | -------------------------------------------------------------------------------- /native/include/routingblocks/utility/arc_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef _routingblocks_ARC_SET_H 24 | #define _routingblocks_ARC_SET_H 25 | 26 | #include 27 | 28 | namespace routingblocks::utility { 29 | class arc_set { 30 | using bitset_t = sul::dynamic_bitset<>; 31 | bitset_t _bitset; 32 | size_t _number_of_vertices; 33 | 34 | public: 35 | explicit arc_set(size_t number_of_vertices) 36 | : _bitset(number_of_vertices * number_of_vertices), 37 | _number_of_vertices(number_of_vertices) { 38 | _bitset.set(); 39 | } 40 | 41 | void forbid_arc(VertexID from, VertexID to) { 42 | _bitset[from * _number_of_vertices + to] = false; 43 | } 44 | 45 | void include_arc(VertexID from, VertexID to) { 46 | _bitset[from * _number_of_vertices + to] = true; 47 | } 48 | 49 | [[nodiscard]] bool includes_arc(VertexID from, VertexID to) const { 50 | return _bitset.test(from * _number_of_vertices + to); 51 | } 52 | }; 53 | } // namespace routingblocks::utility 54 | 55 | #endif //_routingblocks_ARC_SET_H 56 | -------------------------------------------------------------------------------- /native/include/routingblocks/utility/heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef UTIL_HEAP_H 24 | #define UTIL_HEAP_H 25 | 26 | #include 27 | 28 | namespace util { 29 | template > class Heap { 30 | private: 31 | using heap_impl_t = std::priority_queue, Comp>; 32 | 33 | public: 34 | using size_t = typename heap_impl_t::size_type; 35 | 36 | private: 37 | Comp _comp; 38 | heap_impl_t _heap_impl; 39 | 40 | public: 41 | Heap() = default; 42 | explicit Heap(const Comp& comp) : _comp(comp), _heap_impl(_comp){}; 43 | 44 | T pop() { 45 | assert(!empty()); 46 | T moved_from_top = std::move(const_cast(_heap_impl.top())); 47 | _heap_impl.pop(); 48 | return moved_from_top; 49 | }; 50 | const T& top() const { return _heap_impl.top(); }; 51 | 52 | void push(T value) { _heap_impl.push(std::move(value)); } 53 | 54 | [[nodiscard]] bool empty() const { return _heap_impl.empty(); } 55 | 56 | [[nodiscard]] size_t size() const { return _heap_impl.size(); } 57 | 58 | void clear() { 59 | decltype(_heap_impl) empty_heap(_comp); 60 | _heap_impl.swap(empty_heap); 61 | } 62 | }; 63 | } // namespace util 64 | 65 | #endif // UTIL_HEAP_H 66 | -------------------------------------------------------------------------------- /native/include/routingblocks/utility/iterator_pair.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef _routingblocks_ITERATOR_PAIR_H 24 | #define _routingblocks_ITERATOR_PAIR_H 25 | 26 | namespace routingblocks::utility { 27 | /*** 28 | * Provides a simple iterator helper class that allows to use range-based for loops with 29 | * std::pair objects. 30 | */ 31 | template class iterator_pair { 32 | Iterator _begin; 33 | Iterator _end; 34 | 35 | public: 36 | iterator_pair(Iterator begin, Iterator end) : _begin(begin), _end(end) {} 37 | Iterator begin() const { return _begin; } 38 | Iterator end() const { return _end; } 39 | }; 40 | 41 | template 42 | iterator_pair make_iterator_pair(Iterator begin, Iterator end) { 43 | return iterator_pair(begin, end); 44 | } 45 | } // namespace routingblocks::utility 46 | 47 | #endif //_routingblocks_ITERATOR_PAIR_H 48 | -------------------------------------------------------------------------------- /native/include/routingblocks/vertex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Patrick S. Klein (@libklein) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | 23 | #ifndef _routingblocks_VERTEX_H 24 | #define _routingblocks_VERTEX_H 25 | 26 | #include 27 | #include 28 | 29 | namespace routingblocks { 30 | using VertexID = size_t; 31 | 32 | struct Vertex { 33 | using data_t = std::shared_ptr; 34 | // Pointer to type-erased (arbitrary) data 35 | data_t data; 36 | VertexID id; 37 | std::string str_id; 38 | bool is_station; 39 | bool is_depot; 40 | 41 | friend std::ostream& operator<<(std::ostream& os, const Vertex& vertex); 42 | template T& get_data() { return *static_cast(data.get()); } 43 | template const T& get_data() const { return *static_cast(data.get()); } 44 | 45 | [[nodiscard]] bool customer() const { return !is_station && !is_depot; } 46 | [[nodiscard]] bool station() const { return is_station; } 47 | [[nodiscard]] bool depot() const { return is_depot; } 48 | 49 | Vertex(VertexID id, std::string str_id, bool is_station, bool is_depot, data_t data) 50 | : data(std::move(data)), 51 | id(id), 52 | str_id(std::move(str_id)), 53 | is_station(is_station), 54 | is_depot(is_depot){}; 55 | }; 56 | 57 | inline std::ostream& operator<<(std::ostream& os, const routingblocks::Vertex& vertex) { 58 | os << vertex.str_id; 59 | return os; 60 | } 61 | } // namespace routingblocks 62 | 63 | #endif //_routingblocks_VERTEX_H 64 | -------------------------------------------------------------------------------- /native/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | cmake_minimum_required(VERSION 3.15 FATAL_ERROR) 21 | add_subdirectory(xoshiro) 22 | add_subdirectory(dynamic_bitset) 23 | add_subdirectory(small_vector) 24 | -------------------------------------------------------------------------------- /native/lib/dynamic_bitset/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | cmake_minimum_required(VERSION 3.15 FATAL_ERROR) 21 | 22 | project(DYNAMIC_BITSET VERSION 1.0 LANGUAGES CXX) 23 | 24 | add_library(DYNAMIC_BITSET INTERFACE) 25 | target_include_directories(DYNAMIC_BITSET INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 26 | 27 | INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_bitset DESTINATION routingblocks/include/) -------------------------------------------------------------------------------- /native/lib/dynamic_bitset/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Maxime Pinard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /native/lib/small_vector/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | cmake_minimum_required(VERSION 3.15 FATAL_ERROR) 21 | 22 | project(SMALL_VECTOR VERSION 1.0 LANGUAGES CXX) 23 | 24 | 25 | add_library(SMALL_VECTOR INTERFACE) 26 | target_include_directories(SMALL_VECTOR INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 27 | 28 | INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/small_vector DESTINATION routingblocks/include) 29 | -------------------------------------------------------------------------------- /native/lib/small_vector/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Gene Harvey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /native/lib/xoshiro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | cmake_minimum_required(VERSION 3.15 FATAL_ERROR) 21 | 22 | project(XOSHIRO VERSION 1.0 LANGUAGES CXX) 23 | 24 | 25 | add_library(XOSHIRO INTERFACE) 26 | target_include_directories(XOSHIRO INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 27 | 28 | INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/xoshiro DESTINATION routingblocks/include) 29 | -------------------------------------------------------------------------------- /native/lib/xoshiro/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ryo Suzuki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /native/src/FRVCP.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | // this software and associated documentation files (the "Software"), to deal in 5 | // the Software without restriction, including without limitation the rights to 6 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | // the Software, and to permit persons to whom the Software is furnished to do so, 8 | // subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | -------------------------------------------------------------------------------- /native/src/adaptive_large_neighborbood.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | // this software and associated documentation files (the "Software"), to deal in 5 | // the Software without restriction, including without limitation the rights to 6 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | // the Software, and to permit persons to whom the Software is furnished to do so, 8 | // subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | // 21 | // Created by patrick on 3/9/23. 22 | // 23 | #include 24 | 25 | namespace routingblocks {} -------------------------------------------------------------------------------- /native/src/node.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | // this software and associated documentation files (the "Software"), to deal in 5 | // the Software without restriction, including without limitation the rights to 6 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | // the Software, and to permit persons to whom the Software is furnished to do so, 8 | // subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #include 21 | #include 22 | 23 | namespace routingblocks { 24 | 25 | void Node::update_forward(Evaluation& evaluation, const Node& pred_node, const Arc& arc) { 26 | _forward_label = evaluation.propagate_forward(pred_node._forward_label, *pred_node._vertex, 27 | *_vertex, arc); 28 | } 29 | void Node::update_backward(Evaluation& evaluation, const Node& succ_node, const Arc& arc) { 30 | _backward_label = evaluation.propagate_backward(succ_node._backward_label, 31 | *succ_node._vertex, *_vertex, arc); 32 | } 33 | cost_t Node::cost(Evaluation& evaluation) const { 34 | return evaluation.compute_cost(_forward_label); 35 | } 36 | std::vector Node::cost_components(Evaluation& evaluation) const { 37 | return evaluation.get_cost_components(_forward_label); 38 | } 39 | bool Node::feasible(Evaluation& evaluation) const { 40 | return evaluation.is_feasible(_forward_label); 41 | } 42 | } // namespace routingblocks -------------------------------------------------------------------------------- /native/test/src/dummy.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | // this software and associated documentation files (the "Software"), to deal in 5 | // the Software without restriction, including without limitation the rights to 6 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | // the Software, and to permit persons to whom the Software is furnished to do so, 8 | // subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #include 21 | 22 | SCENARIO("Future test", "[DUMMY]") { 23 | WHEN("Testing") { 24 | THEN("Tests should execute") { assert(true); } 25 | } 26 | } -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["scikit-build-core>=0.2.1"] 3 | build-backend = "scikit_build_core.build" 4 | 5 | 6 | [project] 7 | name = "routingblocks" 8 | version = "0.2.1" 9 | description = "A package for the implementation of vehicle routing problems with intermediate stops" 10 | readme = "README.md" 11 | authors = [ 12 | { name = "Patrick Sean Klein", email = "patrick.sean.klein@tum.de" }, 13 | ] 14 | requires-python = ">=3.8" 15 | classifiers = [ 16 | "Development Status :: 4 - Beta", 17 | "License :: OSI Approved :: MIT License", 18 | "Programming Language :: Python :: 3 :: Only", 19 | "Programming Language :: Python :: 3.8", 20 | "Programming Language :: Python :: 3.9", 21 | "Programming Language :: Python :: 3.10", 22 | "Programming Language :: Python :: 3.11", 23 | ] 24 | 25 | [project.optional-dependencies] 26 | test = ["pytest", "pytest-benchmark", "pytest-randomly", "pytest-cov", "pydantic"] 27 | docs = ["sphinx", "sphinx-rtd-theme", "sphinx-autodoc-typehints", "sphinx-autoapi", "sphinxcontrib-bibtex", 28 | "sphinxcontrib-mermaid"] 29 | examples = ["click", "pydantic"] 30 | 31 | 32 | [tool.scikit-build] 33 | wheel.expand-macos-universal-tags = true 34 | cmake.minimum-version = "3.18.0" 35 | 36 | [tool.pytest.ini_options] 37 | testpaths = [ 38 | "test/tests/", 39 | ] 40 | 41 | [tool.cibuildwheel] 42 | test-command = [ 43 | 'python -m pytest {project}/test/tests -m "not benchmark" --randomly-dont-reorganize', 44 | 'cd {project}/examples && python -m ils -n 10 evrptw/instances/evrptw/100/c101_21.txt', 45 | 'cd {project}/examples && python -m alns -n 10 evrptw/instances/evrptw/100/c101_21.txt', 46 | 'cd {project}/examples && python -m evrptw --time-limit 120 --config-path evrptw/config.json evrptw/instances/evrptw/100/c101_21.txt', 47 | ] 48 | test-extras = ["test", "examples"] 49 | test-skip = ["*universal2:arm64"] 50 | build = ["cp*-manylinux_x86_64", "cp*-win32", "cp*-win_amd64", "cp*-macosx_*"] 51 | build-verbosity = 3 52 | 53 | [[tool.cibuildwheel.overrides]] 54 | select = '*-win*' 55 | test-command = [ 56 | 'python -m pytest {project}/test/tests -m "not benchmark" --randomly-dont-reorganize' 57 | ] 58 | -------------------------------------------------------------------------------- /routingblocks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from ._routingblocks import * 21 | 22 | # TODO This is just a quick fix to avoid overwriting the operators module 23 | del globals()['operators'] 24 | from . import operators 25 | from . import utility 26 | # Specializations 27 | from . import adptw 28 | from . import niftw 29 | from .large_neighborhood import LargeNeighborhood 30 | -------------------------------------------------------------------------------- /routingblocks/adptw/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .._routingblocks import ADPTWEvaluation as Evaluation, ADPTWArcData as ArcData, ADPTWVertexData as VertexData, \ 21 | create_adptw_arc, create_adptw_vertex, ADPTWFacilityPlacementOptimizer as FacilityPlacementOptimizer 22 | -------------------------------------------------------------------------------- /routingblocks/niftw/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .._routingblocks import NIFTWEvaluation as Evaluation, NIFTWArcData as ArcData, NIFTWVertexData as VertexData, \ 21 | NIFTWFacilityPlacementOptimizer as FacilityPlacementOptimizer, create_niftw_arc, create_niftw_vertex 22 | -------------------------------------------------------------------------------- /routingblocks/operators/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .move_selectors import first_move_selector, nth_move_selector_factory, blink_selector_factory, MoveSelector, \ 21 | last_move_selector, random_selector_factory 22 | from .worst_removal import WorstRemovalOperator 23 | from .best_insert import BestInsertionOperator 24 | from .route_removal import RouteRemovalOperator 25 | from .cluster_removal import ClusterRemovalOperator, DistanceBasedClusterMemberSelector, ClusterMemberSelector, \ 26 | SeedSelector 27 | from .station_vicinity_removal import StationVicinityRemovalOperator, StationSeedSelector 28 | from .related_removal import RelatedRemovalOperator, MoveSelector, RelatedVertexRemovalMove, \ 29 | build_relatedness_matrix 30 | from .._routingblocks import _RandomRemovalOperator as RandomRemovalOperator, \ 31 | _RandomInsertionOperator as RandomInsertionOperator 32 | from .._routingblocks.operators import * 33 | -------------------------------------------------------------------------------- /routingblocks/operators/route_removal.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from typing import List 21 | 22 | import routingblocks 23 | 24 | 25 | class RouteRemovalOperator(routingblocks.DestroyOperator): 26 | """ 27 | Removes random routes from the solution. May remove more than the requested number of vertices. 28 | """ 29 | 30 | def __init__(self, rng: routingblocks.Random): 31 | """ 32 | :param rng: The :py:class:`routingblocks.Random` instance to use. 33 | """ 34 | # Important: Do not use super()! 35 | routingblocks.DestroyOperator.__init__(self) 36 | self._rng = rng 37 | 38 | def can_apply_to(self, _solution: routingblocks.Solution) -> bool: 39 | return len(_solution) > 0 40 | 41 | def apply(self, evaluation: routingblocks.Evaluation, _solution: routingblocks.Solution, 42 | number_of_removed_vertices: int) -> List[ 43 | int]: 44 | # Try to remove random routes 45 | removed_customers = [] 46 | while len(_solution) > 0 and len(removed_customers) < number_of_removed_vertices: 47 | random_route_index = self._rng.randint(0, len(_solution) - 1) 48 | removed_customers.extend(x.vertex_id for x in _solution[random_route_index] if not x.vertex.is_depot) 49 | del _solution[random_route_index] 50 | return removed_customers 51 | 52 | def name(self) -> str: 53 | return "RouteRemoveOperator" 54 | -------------------------------------------------------------------------------- /routingblocks/utility/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .instance_builder import InstanceBuilder 21 | -------------------------------------------------------------------------------- /test/tests/benchmarks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /test/tests/benchmarks/test_benchmark_frvcp.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from __future__ import annotations 21 | 22 | import random 23 | from typing import List 24 | 25 | import pytest 26 | 27 | from fixtures import * 28 | 29 | try: 30 | from routingblocks import adptw 31 | except ModuleNotFoundError: 32 | pass 33 | 34 | 35 | def run_frvcp_on_routes(routes: List[List[int]], frvcp_factory): 36 | frvcp = frvcp_factory() 37 | for route in routes: 38 | frvcp.optimize(route) 39 | 40 | 41 | @pytest.mark.benchmark(group="facility-placement-optimizer") 42 | @pytest.mark.parametrize("propagator", ['adptw-cpp']) 43 | def test_frvcp_benchmark_propagators(instance_parser, 44 | random_raw_route_factory, propagator, benchmark): 45 | py_instance, instance = instance_parser('r101_21.txt') 46 | factories = { 47 | 'adptw-cpp': lambda: adptw.FacilityPlacementOptimizer(instance, py_instance.parameters.battery_capacity_time) 48 | } 49 | 50 | # Create routes 51 | randgen = random.Random(0) 52 | routes = [random_raw_route_factory(instance, randgen, include_depot=True) for _ in range(10)] 53 | 54 | benchmark(run_frvcp_on_routes, routes=routes, frvcp_factory=factories[propagator]) 55 | -------------------------------------------------------------------------------- /test/tests/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | pytest_plugins = [ 21 | "fixtures.mock_evaluation", 22 | ] 23 | -------------------------------------------------------------------------------- /test/tests/fixtures/data/c101C5.txt: -------------------------------------------------------------------------------- 1 | StringID Type x y demand ReadyTime DueDate ServiceTime 2 | D0 d 40.0 50.0 0.0 0.0 1236.0 0.0 3 | S0 f 40.0 50.0 0.0 0.0 1236.0 0.0 4 | S5 f 31.0 84.0 0.0 0.0 1236.0 0.0 5 | S15 f 39.0 26.0 0.0 0.0 1236.0 0.0 6 | C30 c 20.0 55.0 10.0 355.0 407.0 90.0 7 | C12 c 25.0 85.0 20.0 176.0 228.0 90.0 8 | C100 c 55.0 85.0 20.0 744.0 798.0 90.0 9 | C85 c 68.0 60.0 30.0 737.0 809.0 90.0 10 | C64 c 48.0 30.0 10.0 263.0 325.0 90.0 11 | 12 | Q Vehicle fuel tank capacity /77.75/ 13 | C Vehicle load capacity /200.0/ 14 | r fuel consumption rate /1.0/ 15 | g inverse refueling rate /3.47/ 16 | v average Velocity /1.0/ 17 | -------------------------------------------------------------------------------- /test/tests/helpers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from .interface import parse_evrptw_instance, create_cpp_vertex, create_cpp_instance, create_cpp_arc 21 | from .models import Instance, Vertex, Arc 22 | -------------------------------------------------------------------------------- /test/tests/operators/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /test/tests/operators/test_random_insertion.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from __future__ import annotations 21 | 22 | import itertools 23 | import random 24 | from collections import defaultdict 25 | from dataclasses import dataclass 26 | from pathlib import Path 27 | from typing import Tuple, Callable, Dict, List, TypeVar, Union 28 | 29 | import pytest 30 | 31 | import helpers 32 | 33 | from fixtures import * 34 | 35 | try: 36 | import routingblocks as alns 37 | except ModuleNotFoundError: 38 | pass 39 | 40 | 41 | def test_random_insertion_apply(adptw_instance, mock_evaluation, randgen): 42 | instance: evrptw.Instance = adptw_instance 43 | evaluation = mock_evaluation 44 | operator = alns.operators.RandomInsertionOperator(randgen) 45 | # Inserts customers at random positions 46 | customers = list(instance.customers) 47 | missing_customers = customers[1:] 48 | solutions = [] 49 | for _ in range(10): 50 | sol = alns.Solution(evaluation, instance, [alns.create_route(evaluation, instance, [customers[0].vertex_id]), 51 | alns.Route(evaluation, instance)]) 52 | assert operator.can_apply_to(sol) 53 | operator.apply(evaluation, sol, [x.vertex_id for x in missing_customers]) 54 | for i in customers: 55 | assert sol.find(i.vertex_id) != [] 56 | solutions.append(sol) 57 | 58 | # Ensure that at least two solutions do not match 59 | # And at least one should 60 | found_missmatch = False 61 | found_inserted_route_2 = False 62 | for sol_a, sol_b in itertools.product(solutions, repeat=2): 63 | if sol_a != sol_b: 64 | found_missmatch = True 65 | if not sol_a[1].empty: 66 | found_inserted_route_2 = True 67 | if not found_missmatch or not found_inserted_route_2: 68 | pytest.fail("Random insertion does not behave randomly") 69 | -------------------------------------------------------------------------------- /test/tests/operators/test_station_removal.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Patrick S. Klein (@libklein) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | # this software and associated documentation files (the "Software"), to deal in 5 | # the Software without restriction, including without limitation the rights to 6 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | # the Software, and to permit persons to whom the Software is furnished to do so, 8 | # subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in all 11 | # copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | from itertools import islice 21 | 22 | import pytest 23 | from fixtures import * 24 | import routingblocks 25 | from routingblocks import niftw 26 | 27 | 28 | def test_station_removal_search(large_instance): 29 | py_instance, instance = large_instance 30 | evaluation = niftw.Evaluation(py_instance.parameters.battery_capacity_time, 31 | py_instance.parameters.capacity, 0.) 32 | 33 | # Make sure that there is no penalty for removing stations. 34 | evaluation.resource_penalty_factor = 0. 35 | evaluation.overload_penalty_factor = 0. 36 | evaluation.time_shift_penalty_factor = 0. 37 | 38 | solution = create_solution(instance, evaluation, [ 39 | [station.vertex_id for station in islice(instance.stations, 1, 3)], 40 | [1, 2, 3, *(station.vertex_id for station in islice(instance.stations, 1, 3))] 41 | ]) 42 | 43 | station_removal_operator = routingblocks.operators.RemoveStationOperator(instance) 44 | ls = routingblocks.LocalSearch(instance, evaluation, None, routingblocks.FirstImprovementPivotingRule()) 45 | ls.optimize(solution, [station_removal_operator]) 46 | 47 | # All stations should be removed. 48 | assert sum(1 for route in solution for x in route if x.vertex.is_station) == 0 49 | --------------------------------------------------------------------------------