cspy

cspy: A Python package with a collection of algorithms for the (Resource) Constrained Shortest Path problem - Published in JOSS (2020)

https://github.com/torressa/cspy

Science Score: 95.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: researchgate.net, sciencedirect.com, joss.theoj.org
  • Committers with academic emails
    2 of 10 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

bidirectional-labeling-algorithm csp-problem operations-research optimization optimization-algorithms optimization-library resource-constrained-shortest-path

Keywords from Contributors

networkx evolutionary-algorithms

Scientific Fields

Sociology Social Sciences - 35% confidence
Last synced: 4 months ago · JSON representation

Repository

A collection of algorithms for the (Resource) Constrained Shortest Path problem in Python / C++ / C#

Basic Info
Statistics
  • Stars: 88
  • Watchers: 8
  • Forks: 26
  • Open Issues: 22
  • Releases: 19
Topics
bidirectional-labeling-algorithm csp-problem operations-research optimization optimization-algorithms optimization-library resource-constrained-shortest-path
Created over 6 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.md

| OS | C++ | Python | Dotnet | |:-------|-----|--------|--------| | Unix (linux + macos) | Status | Status| Status | | Windows | Status | Status |Status |

PyPI version Codacy Badge JOSS badge

cspy

A collection of algorithms for the (resource) Constrained Shortest Path (CSP) problem.

Documentation here.

The CSP problem was popularised by Inrich and Desaulniers (2005). It was initially introduced as a subproblem for the bus driver scheduling problem, and has since then widely studied in a variety of different settings including: the vehicle routing problem with time windows (VRPTW), the technician routing and scheduling problem, the capacitated arc-routing problem, on-demand transportation systems, and, airport ground movement; among others.

More generally, in the applied column generation framework, particularly in the scheduling related literature, the CSP problem is commonly employed to generate columns.

Therefore, this library is of interest to the operational research community, students and academics alike, that wish to solve an instance of the CSP problem.

Algorithms

Currently, the exact and metaheuristic algorithms implemented include:

  • [x] Bidirectional labeling algorithm with dynamic halfway point (exact) (also monodirectional) Tilk et al. (2017);
  • [x] Heuristic Tabu search (metaheuristic);
  • [x] Greedy elimination procedure (metaheuristic);
  • [x] Greedy Randomised Adaptive Search Procedure (GRASP) (metaheuristic). Adapted from Ferone et al. (2019);
  • [x] Particle Swarm Optimization with combined Local and Global Expanding Neighborhood Topology (PSOLGENT) (metaheuristic) Marinakis et al. (2017).

Please see the docs for individual algorithms Python or C++ API documentation, as well as some toy examples and further details.

Getting Started

Prerequisites

Conceptual background and input formatting is discussed in the docs.

Module dependencies are:

Note that requirements.txt contains modules for development purposes.

Installing

Installing the cspy package with pip should also install all the required packages. You can do this by running the following command in your terminal

none pip install cspy

or

none python3 -m pip install cspy

Quick start

Python

```python

Imports

from cspy import BiDirectional from networkx import DiGraph from numpy import array

maxres, minres = [4, 20], [1, 0]

Create a DiGraph

G = DiGraph(directed=True, nres=2) G.addedge("Source", "A", rescost=[1, 2], weight=0) G.addedge("A", "B", rescost=[1, 0.3], weight=0) G.addedge("A", "C", rescost=[1, 0.1], weight=0) G.addedge("B", "C", rescost=[1, 3], weight=-10) G.addedge("B", "Sink", rescost=[1, 2], weight=10) G.addedge("C", "Sink", res_cost=[1, 10], weight=0)

init algorithm

bidirec = BiDirectional(G, maxres, minres)

Call and query attributes

bidirec.run() print(bidirec.path) print(bidirec.totalcost) print(bidirec.consumedresources) ```

For more details see the Python API

Cpp

```cpp

include "bidirectional.h"

namespace bidirectional {

void wrap() { // Init const std::vector maxres = {4.0, 20.0}; const std::vector minres = {1.0, 0.0}; const int numbervertices = 5; const int numberedges = 5; auto bidirectional = std::makeunique( numbervertices, numberedges, 0, 4, maxres, min_res);

// Populate graph bidirectional->addNodes({0, 1, 2, 3, 4}); bidirectional->addEdge(0, 1, 0.0, {1, 2}); bidirectional->addEdge(1, 2, 0.0, {1, 0.3}); bidirectional->addEdge(2, 3, -10.0, {1, 3}); bidirectional->addEdge(2, 4, 10.0, {1, 2}); bidirectional->addEdge(3, 4, 0.0, {1, 10});

// Run and query attributes bidirectional->run();

auto path = bidirectional->getPath(); auto res = bidirectional->getConsumedResources(); auto cost = bidirectional->getTotalCost(); }

} // namespace bidirectional ```

C

```csharp DoubleVector maxres = new DoubleVector(new List() {4.0, 20.0}); DoubleVector minres = new DoubleVector(new List() {0.0, 0.0}); int numbervertices = 5; int numberedges = 5; BiDirectionalCpp alg = new BiDirectionalCpp(numbervertices, numberedges, 0, 4, maxres, minres);

// Populate graph alg.addNodes(new IntVector(new List() {0, 1, 2, 3, 4})); alg.addEdge(0, 1, -1.0, new DoubleVector(new List() {1, 2})); alg.addEdge(1, 2, -1.0, new DoubleVector(new List() {1, 0.3})); alg.addEdge(2, 3, -10.0, new DoubleVector(new List() {1, 3})); alg.addEdge(2, 4, 10.0, new DoubleVector(new List() {1, 2})); alg.addEdge(3, 4, -1.0, new DoubleVector(new List() {1, 10})); alg.setDirection("forward");

// Run and query attributes alg.run();

IntVector path = alg.getPath(); DoubleVector res = alg.getConsumedResources(); double cost = alg.getTotalCost(); ```

Examples

  • vrpy : External vehicle routing framework which uses cspy to solve different variants of the vehicle routing problem using column generation. Particulatly, see subproblem_cspy.py.
  • jpath : Simple example showing the necessary graph adptations and the use of custom resource extension functions.

Building

Docker

Using docker, docker-compose is the easiest way.

To run the tests first, clone the repository into a path in your machine ~/path/newfolder by running

none git clone https://github.com/torressa/cspy.git ~/path/newfolder

Running the Cpp tests

cd ~/path/newfolder/tools/dev ./build

Running the Python tests

cd ~/path/newfolder/tools/dev ./build -c -p

Locally

Requirements:

  • CMake (>=v3.14)
  • Standard C++ toolchain
  • Python (>=3.6)

Then use the wrapper Makefile e.g. make in the root dir runs the unit tests

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Contributing

Issues

If you find a bug or there are some improvements you'd like to see (e.g. more algorithms), please raise a new issue with a clear explanation.

Contributing to the Software

When contributing to this repository, please first discuss the change you wish to make via an issue or email. After that feel free to send a pull request.

Pull Request Process

  • If necessary, please perform documentation updates where appropriate (e.g. README.md, docs and CHANGELOG.md).
  • Increase the version numbers and reference the changes appropriately. Note that the versioning scheme used is based on Semantic Versioning.
  • Wait for approval for merging.

Seeking Support

If you have a question or need help, feel free to raise an issue explaining it.

Alternatively, email me at torressa at tutanota.com.

Citing

If you'd like to cite this package, please use the following bib format:

none @article{torressa2020, doi = {10.21105/joss.01655}, url = {https://doi.org/10.21105/joss.01655}, year = {2020}, publisher = {The Open Journal}, volume = {5}, number = {49}, pages = {1655}, author = {{Torres Sanchez}, David}, title = {cspy: A Python package with a collection of algorithms for the (Resource) Constrained Shortest Path problem}, journal = {Journal of Open Source Software} }

Owner

  • Name: David Torres
  • Login: torressa
  • Kind: user
  • Location: Lancaster
  • Company: Gurobi Optimization

Optimization Engineer @ Gurobi

JOSS Publication

cspy: A Python package with a collection of algorithms for the (Resource) Constrained Shortest Path problem
Published
May 21, 2020
Volume 5, Issue 49, Page 1655
Authors
David Torres Sanchez ORCID
STOR-i, Lancaster University, UK., SINTEF Digital, Mathematics and Cybernetics
Editor
Jack Poulson ORCID
Tags
Resource Constrained Shortest Path Networks Graph Theory

GitHub Events

Total
  • Issues event: 3
  • Watch event: 5
  • Issue comment event: 2
  • Fork event: 2
Last Year
  • Issues event: 3
  • Watch event: 5
  • Issue comment event: 2
  • Fork event: 2

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 386
  • Total Committers: 10
  • Avg Commits per committer: 38.6
  • Development Distribution Score (DDS): 0.482
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
torressa 2****a 200
kermit-z d****z@l****k 155
torressa d****z@s****o 20
Sourcery AI 3
David Torres Sánchez d****z@s****o 3
sourcery-ai[bot] 5****] 1
felicze 7****e 1
Daniel S. Katz d****z@i****g 1
Dan Van Boxel t****b@g****m 1
David Torres Sánches d****s@s****o 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 74
  • Total pull requests: 35
  • Average time to close issues: 3 months
  • Average time to close pull requests: 6 days
  • Total issue authors: 31
  • Total pull request authors: 4
  • Average comments per issue: 3.42
  • Average comments per pull request: 0.97
  • Merged pull requests: 26
  • Bot issues: 0
  • Bot pull requests: 8
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • torressa (26)
  • Kuifje02 (5)
  • dvbuntu (4)
  • mgalati13 (3)
  • the-soomin-woo (3)
  • steveharenberg (3)
  • saahaand (3)
  • glanch (2)
  • tomatoes-prog (2)
  • andrea-cassioli-maersk (2)
  • ericburrell-23-1 (1)
  • MariaSKAF (1)
  • jujaramillo (1)
  • malokesnila (1)
  • ransari74 (1)
Pull Request Authors
  • torressa (24)
  • sourcery-ai[bot] (8)
  • dvbuntu (2)
  • felicze (1)
Top Labels
Issue Labels
bug (22) BiDirectional (22) help wanted (22) feature-request (16) waiting (9) joss-review (3) good first issue (2) examples (2) wontfix (2) question (1) duplicate (1)
Pull Request Labels
BiDirectional (1) feature-request (1)

Packages

  • Total packages: 6
  • Total downloads:
    • nuget 1,787 total
    • pypi 5,629 last-month
  • Total dependent packages: 3
    (may contain duplicates)
  • Total dependent repositories: 8
    (may contain duplicates)
  • Total versions: 24
  • Total maintainers: 2
pypi.org: cspy

(Resource) Constrained Shortest Path algorithms in Python

  • Versions: 19
  • Dependent Packages: 1
  • Dependent Repositories: 8
  • Downloads: 5,629 Last month
Rankings
Downloads: 4.2%
Dependent packages count: 4.8%
Dependent repos count: 5.2%
Average: 6.0%
Forks count: 8.0%
Stargazers count: 8.0%
Maintainers (1)
Last synced: 4 months ago
nuget.org: cspy.dotnet

.NET wrapper for the cspy BiDirection algorithm

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 10.2%
Average: 12.0%
Dependent packages count: 13.9%
Last synced: 4 months ago
nuget.org: cspy.dotnet.runtime.linux-x64

.NET native wrapper for the cspy BiDirectional algorithm

  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 10.2%
Average: 12.0%
Dependent packages count: 13.9%
Last synced: 4 months ago
nuget.org: cspy.dn

.NET wrapper for the cspy BiDirection algorithm

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 13.8%
Average: 16.3%
Dependent packages count: 18.8%
Last synced: 4 months ago
nuget.org: cspy.dn.runtime.osx-x64

.NET native wrapper for the cspy BiDirectional algorithm

  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 13.8%
Average: 16.3%
Dependent packages count: 18.8%
Last synced: 4 months ago
nuget.org: cspy.dotnet.runtime.osx-arm64

.NET native wrapper for the cspy BiDirectional algorithm

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,787 Total
Rankings
Dependent repos count: 13.8%
Dependent packages count: 18.8%
Average: 24.0%
Downloads: 39.3%
Maintainers (1)
Last synced: 4 months ago

Dependencies

docs/requirements.txt pypi
  • breathe *
  • cspy *
  • nbsphinx *
  • recommonmark *
  • sphinx *
  • sphinx_copybutton *
  • sphinx_material *
examples/jpath/requirements.txt pypi
  • osmnx *
python/requirements.dev.txt pypi
  • networkx * development
  • numpy * development
  • pandas * development
  • parameterized * development
python/requirements.txt pypi
  • networkx >=2.2
  • numpy >=1.13.3