All Projects → torressa → cspy

torressa / cspy

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

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
CMake
9771 projects
TeX
3793 projects
SWIG
194 projects
C#
18002 projects

Projects that are alternatives of or similar to cspy

optaplanner-quickstarts
OptaPlanner quick starts for AI optimization: many use cases shown in many different technologies.
Stars: ✭ 226 (+253.13%)
Mutual labels:  operations-research, optimization-algorithms
GurobiLink
Wolfram Language interface to the Gurobi numerical optimization library
Stars: ✭ 16 (-75%)
Mutual labels:  optimization-algorithms, optimization-library
Operations-Research
Some lecture notes of Operations Research (usually taught in Junior year of BS) can be found in this repository along with some Python programming codes to solve numerous problems of Optimization including Travelling Salesman, Minimum Spanning Tree and so on.
Stars: ✭ 92 (+43.75%)
Mutual labels:  operations-research, optimization-algorithms
Nmflibrary
MATLAB library for non-negative matrix factorization (NMF): Version 1.8.1
Stars: ✭ 153 (+139.06%)
Mutual labels:  optimization-algorithms
Sporco
Sparse Optimisation Research Code
Stars: ✭ 164 (+156.25%)
Mutual labels:  optimization-algorithms
lectures-notes
My latex notes on whatever I'm studying. All are available to the public, but please take them with a grain of salt and notify me in case of errors :)
Stars: ✭ 62 (-3.12%)
Mutual labels:  operations-research
pybnb
A parallel branch-and-bound engine for Python. (https://pybnb.readthedocs.io/)
Stars: ✭ 53 (-17.19%)
Mutual labels:  optimization-algorithms
Proxtv
Matlab and Python toolbox for fast Total Variation proximity operators
Stars: ✭ 140 (+118.75%)
Mutual labels:  optimization-algorithms
cplex-example
Solving a TSP with the CPLEX C++ API.
Stars: ✭ 40 (-37.5%)
Mutual labels:  operations-research
Argmin
Mathematical optimization in pure Rust
Stars: ✭ 234 (+265.63%)
Mutual labels:  optimization-algorithms
Abagail
The library contains a number of interconnected Java packages that implement machine learning and artificial intelligence algorithms. These are artificial intelligence algorithms implemented for the kind of people that like to implement algorithms themselves.
Stars: ✭ 225 (+251.56%)
Mutual labels:  optimization-algorithms
Optimizer Visualization
Visualize Tensorflow's optimizers.
Stars: ✭ 178 (+178.13%)
Mutual labels:  optimization-algorithms
monolith
A C++ monorepo for discrete and continuous optimization. Batteries included!
Stars: ✭ 84 (+31.25%)
Mutual labels:  operations-research
Fewshotlearning
Pytorch implementation of the paper "Optimization as a Model for Few-Shot Learning"
Stars: ✭ 223 (+248.44%)
Mutual labels:  optimization-algorithms
Bads
Bayesian Adaptive Direct Search (BADS) optimization algorithm for model fitting in MATLAB
Stars: ✭ 159 (+148.44%)
Mutual labels:  optimization-algorithms
adaptive-large-neighbourhood-search
ALNS header-only library (loosely) based on the original implementation by Stefan Ropke.
Stars: ✭ 28 (-56.25%)
Mutual labels:  operations-research
Niapy
Python microframework for building nature-inspired algorithms. Official docs: http://niapy.readthedocs.io/en/stable/
Stars: ✭ 148 (+131.25%)
Mutual labels:  optimization-algorithms
Aleph star
Reinforcement learning with A* and a deep heuristic
Stars: ✭ 235 (+267.19%)
Mutual labels:  optimization-algorithms
sdaopt
Simulated Dual Annealing for python and benchmarks
Stars: ✭ 15 (-76.56%)
Mutual labels:  optimization-algorithms
pallas-solver
Global optimization algorithms written in C++
Stars: ✭ 43 (-32.81%)
Mutual labels:  optimization-algorithms
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:

  • Bidirectional labeling algorithm with dynamic halfway point (exact) (also monodirectional) Tilk et al. (2017);
  • Heuristic Tabu search (metaheuristic);
  • Greedy elimination procedure (metaheuristic);
  • Greedy Randomised Adaptive Search Procedure (GRASP) (metaheuristic). Adapted from Ferone et al. (2019);
  • 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

pip install cspy

or

python3 -m pip install cspy

Quick start

Python

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

max_res, min_res = [4, 20], [1, 0]
# Create a DiGraph
G = DiGraph(directed=True, n_res=2)
G.add_edge("Source", "A", res_cost=[1, 2], weight=0)
G.add_edge("A", "B", res_cost=[1, 0.3], weight=0)
G.add_edge("A", "C", res_cost=[1, 0.1], weight=0)
G.add_edge("B", "C", res_cost=[1, 3], weight=-10)
G.add_edge("B", "Sink", res_cost=[1, 2], weight=10)
G.add_edge("C", "Sink", res_cost=[1, 10], weight=0)

# init algorithm
bidirec = BiDirectional(G, max_res, min_res)

# Call and query attributes
bidirec.run()
print(bidirec.path)
print(bidirec.total_cost)
print(bidirec.consumed_resources)

For more details see the Python API

Cpp

#include "bidirectional.h"

namespace bidirectional {

void wrap() {
  // Init
  const std::vector<double> max_res         = {4.0, 20.0};
  const std::vector<double> min_res         = {1.0, 0.0};
  const int                 number_vertices = 5;
  const int                 number_edges    = 5;
  auto                      bidirectional   = std::make_unique<BiDirectional>(
      number_vertices, number_edges, 0, 4, max_res, 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#

DoubleVector max_res = new DoubleVector(new List<double>() {4.0, 20.0});
DoubleVector min_res = new DoubleVector(new List<double>() {0.0, 0.0});
int number_vertices = 5;
int number_edges = 5;
BiDirectionalCpp alg = new BiDirectionalCpp(number_vertices, number_edges, 0, 4, max_res, min_res);

// Populate graph
alg.addNodes(new IntVector(new List<int>() {0, 1, 2, 3, 4}));
alg.addEdge(0, 1, -1.0, new DoubleVector(new List<double>() {1, 2}));
alg.addEdge(1, 2, -1.0, new DoubleVector(new List<double>() {1, 0.3}));
alg.addEdge(2, 3, -10.0, new DoubleVector(new List<double>() {1, 3}));
alg.addEdge(2, 4, 10.0, new DoubleVector(new List<double>() {1, 2}));
alg.addEdge(3, 4, -1.0, new DoubleVector(new List<double>() {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

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:

@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}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].