{"id":16730747,"url":"https://github.com/chkwon/pyhygese","last_synced_at":"2025-03-17T01:31:39.335Z","repository":{"id":40416285,"uuid":"470432351","full_name":"chkwon/PyHygese","owner":"chkwon","description":"A Python wrapper for the Hybrid Genetic Search algorithm for Capacitated Vehicle Routing Problems (HGS-CVRP)","archived":false,"fork":false,"pushed_at":"2023-03-10T18:09:20.000Z","size":110,"stargazers_count":87,"open_issues_count":7,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-10T23:02:28.328Z","etag":null,"topics":["capacitated-vehicle-routing-problem","hybrid-genetic-search","operations-research","optimization","python","traveling-salesman-problem"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chkwon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-16T04:32:59.000Z","updated_at":"2025-02-20T10:38:40.000Z","dependencies_parsed_at":"2024-10-27T11:51:43.903Z","dependency_job_id":"55ddc572-0b24-4a12-a275-33960278e620","html_url":"https://github.com/chkwon/PyHygese","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chkwon%2FPyHygese","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chkwon%2FPyHygese/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chkwon%2FPyHygese/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chkwon%2FPyHygese/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chkwon","download_url":"https://codeload.github.com/chkwon/PyHygese/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836015,"owners_count":20355615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capacitated-vehicle-routing-problem","hybrid-genetic-search","operations-research","optimization","python","traveling-salesman-problem"],"created_at":"2024-10-12T23:34:38.197Z","updated_at":"2025-03-17T01:31:39.016Z","avatar_url":"https://github.com/chkwon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyHygese\n\n[![Build Status](https://github.com/chkwon/PyHygese/workflows/CI/badge.svg?branch=master)](https://github.com/chkwon/PyHygese/actions/workflows/ci.yml?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/chkwon/PyHygese/branch/master/graph/badge.svg)](https://codecov.io/gh/chkwon/PyHygese)\n[![PyPI version](https://badge.fury.io/py/hygese.svg)](https://badge.fury.io/py/hygese)\n\n*This package is under active development. It can introduce breaking changes anytime. Please use it at your own risk.*\n\n**A solver for the Capacitated Vehicle Routing Problem (CVRP)**\n\nThis package provides a simple Python wrapper for the Hybrid Genetic Search solver for Capacitated Vehicle Routing Problems [(HGS-CVRP)](https://github.com/vidalt/HGS-CVRP).\n\nThe installation requires `gcc`, `make`, and `cmake` to build.\nOn Windows, for example, you can install them by `scoop install gcc make cmake` using [Scoop](scoop.sh).\nThen, install the PyHygese package:\n```\npip install hygese\n```\n\u003c!-- ```\npython3 -m pip install git+https://github.com/chkwon/PyHygese\n``` --\u003e\n\n\n## CVRP Example (random)\n```python\nimport numpy as np \nimport hygese as hgs\n\nn = 20\nx = (np.random.rand(n) * 1000)\ny = (np.random.rand(n) * 1000)\n\n# Solver initialization\nap = hgs.AlgorithmParameters(timeLimit=3.2)  # seconds\nhgs_solver = hgs.Solver(parameters=ap, verbose=True)\n\n# data preparation\ndata = dict()\ndata['x_coordinates'] = x\ndata['y_coordinates'] = y\n\n# You may also supply distance_matrix instead of coordinates, or in addition to coordinates\n# If you supply distance_matrix, it will be used for cost calculation.\n# The additional coordinates will be helpful in speeding up the algorithm.\n# data['distance_matrix'] = dist_mtx\n\ndata['service_times'] = np.zeros(n)\ndemands = np.ones(n)\ndemands[0] = 0 # depot demand = 0\ndata['demands'] = demands\ndata['vehicle_capacity'] = np.ceil(n/3).astype(int)\ndata['num_vehicles'] = 3\ndata['depot'] = 0\n\nresult = hgs_solver.solve_cvrp(data)\nprint(result.cost)\nprint(result.routes)\n\n```\n\n**NOTE:** The `result.routes` above does not include the depot. All vehicles start from the depot and return to the depot.\n\n\n## another CVRP example\n\n```python\n# A CVRP from https://developers.google.com/optimization/routing/cvrp\nimport numpy as np \nimport hygese as hgs \n\ndata = dict()\ndata['distance_matrix'] = [\n    [0, 548, 776, 696, 582, 274, 502, 194, 308, 194, 536, 502, 388, 354, 468, 776, 662],\n    [548, 0, 684, 308, 194, 502, 730, 354, 696, 742, 1084, 594, 480, 674, 1016, 868, 1210],\n    [776, 684, 0, 992, 878, 502, 274, 810, 468, 742, 400, 1278, 1164, 1130, 788, 1552, 754],\n    [696, 308, 992, 0, 114, 650, 878, 502, 844, 890, 1232, 514, 628, 822, 1164, 560, 1358],\n    [582, 194, 878, 114, 0, 536, 764, 388, 730, 776, 1118, 400, 514, 708, 1050, 674, 1244],\n    [274, 502, 502, 650, 536, 0, 228, 308, 194, 240, 582, 776, 662, 628, 514, 1050, 708],\n    [502, 730, 274, 878, 764, 228, 0, 536, 194, 468, 354, 1004, 890, 856, 514, 1278, 480],\n    [194, 354, 810, 502, 388, 308, 536, 0, 342, 388, 730, 468, 354, 320, 662, 742, 856],\n    [308, 696, 468, 844, 730, 194, 194, 342, 0, 274, 388, 810, 696, 662, 320, 1084, 514],\n    [194, 742, 742, 890, 776, 240, 468, 388, 274, 0, 342, 536, 422, 388, 274, 810, 468],\n    [536, 1084, 400, 1232, 1118, 582, 354, 730, 388, 342, 0, 878, 764, 730, 388, 1152, 354],\n    [502, 594, 1278, 514, 400, 776, 1004, 468, 810, 536, 878, 0, 114, 308, 650, 274, 844],\n    [388, 480, 1164, 628, 514, 662, 890, 354, 696, 422, 764, 114, 0, 194, 536, 388, 730],\n    [354, 674, 1130, 822, 708, 628, 856, 320, 662, 388, 730, 308, 194, 0, 342, 422, 536],\n    [468, 1016, 788, 1164, 1050, 514, 514, 662, 320, 274, 388, 650, 536, 342, 0, 764, 194],\n    [776, 868, 1552, 560, 674, 1050, 1278, 742, 1084, 810, 1152, 274, 388, 422, 764, 0, 798],\n    [662, 1210, 754, 1358, 1244, 708, 480, 856, 514, 468, 354, 844, 730, 536, 194, 798, 0]\n]\ndata['num_vehicles'] = 4\ndata['depot'] = 0\ndata['demands'] = [0, 1, 1, 2, 4, 2, 4, 8, 8, 1, 2, 1, 2, 4, 4, 8, 8]\ndata['vehicle_capacity'] = 15  # different from OR-Tools: homogeneous capacity\ndata['service_times'] = np.zeros(len(data['demands']))\n\n# Solver initialization\nap = hgs.AlgorithmParameters(timeLimit=3.2)  # seconds\nhgs_solver = hgs.Solver(parameters=ap, verbose=True)\n\n# Solve\nresult = hgs_solver.solve_cvrp(data)\nprint(result.cost)\nprint(result.routes)\n```\n\n\n## TSP example\n\n```python\n# A TSP example from https://developers.google.com/optimization/routing/tsp\nimport hygese as hgs \n\ndata = dict()\ndata['distance_matrix'] = [\n    [0, 2451, 713, 1018, 1631, 1374, 2408, 213, 2571, 875, 1420, 2145, 1972],\n    [2451, 0, 1745, 1524, 831, 1240, 959, 2596, 403, 1589, 1374, 357, 579],\n    [713, 1745, 0, 355, 920, 803, 1737, 851, 1858, 262, 940, 1453, 1260],\n    [1018, 1524, 355, 0, 700, 862, 1395, 1123, 1584, 466, 1056, 1280, 987],\n    [1631, 831, 920, 700, 0, 663, 1021, 1769, 949, 796, 879, 586, 371],\n    [1374, 1240, 803, 862, 663, 0, 1681, 1551, 1765, 547, 225, 887, 999],\n    [2408, 959, 1737, 1395, 1021, 1681, 0, 2493, 678, 1724, 1891, 1114, 701],\n    [213, 2596, 851, 1123, 1769, 1551, 2493, 0, 2699, 1038, 1605, 2300, 2099],\n    [2571, 403, 1858, 1584, 949, 1765, 678, 2699, 0, 1744, 1645, 653, 600],\n    [875, 1589, 262, 466, 796, 547, 1724, 1038, 1744, 0, 679, 1272, 1162],\n    [1420, 1374, 940, 1056, 879, 225, 1891, 1605, 1645, 679, 0, 1017, 1200],\n    [2145, 357, 1453, 1280, 586, 887, 1114, 2300, 653, 1272, 1017, 0, 504],\n    [1972, 579, 1260, 987, 371, 999, 701, 2099, 600, 1162, 1200, 504, 0],\n] \n\n# Solver initialization\nap = hgs.AlgorithmParameters(timeLimit=0.8)  # seconds\nhgs_solver = hgs.Solver(parameters=ap, verbose=True)\n\n# Solve\nresult = hgs_solver.solve_tsp(data)\nprint(result.cost)\nprint(result.routes)\n```\n\n## Algorithm Parameters\nConfigurable algorithm parameters are defined in the `AlgorithmParameters` dataclass with default values:\n```python\n@dataclass\nclass AlgorithmParameters:\n    nbGranular: int = 20\n    mu: int = 25\n    lambda_: int = 40\n    nbElite: int = 4\n    nbClose: int = 5\n    targetFeasible: float = 0.2\n    seed: int = 1\n    nbIter: int = 20000\n    timeLimit: float = 0.0\n    useSwapStar: bool = True\n```\n\n## Others\nA Julia wrapper is available: [Hygese.jl](https://github.com/chkwon/Hygese.jl)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchkwon%2Fpyhygese","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchkwon%2Fpyhygese","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchkwon%2Fpyhygese/lists"}