Skip to main content

Compute Routes easy and fast

Project description

Build Status codecov

Logo

WIP Package

Scikit Route is a Python module create with Python and Cython to optimize route and travel problems and there are a lot of different alogithms in the package for all the different purposes.

Scikit Route have the spirit and the soul of Scikit Learn wich mean that is fully oriented to the programmer, easy to use and to understund, you can create algorithm with a few lines of code, and the modules, submodules, methods of the algorithms, etc, are the same than Scikit Learn wich will make even easyer to use this library if you previously know Scikit Learn.

This project was started in 2020 by Alberto Rubiales and one of the main goals is to be integrated in the future with Scikit Learn project.

Anyone is free to help and developt the package.

Installation

Dependencies

scikit_route requires:

  • Python (>=3.6)
  • Numpy (>=1.19)
  • Pandas (>=1.1)
  • Scikit-Learn (>=0.23)
  • Cython (>=0.29)

Others version could work but it's not guaranted.

Also to Allow functions with plotting capabilites requires Matplotlib (>=3.1)

User installation

The easiest way to install scikit_route is using pip: pip install scikit_route

or conda:

conda instal -c conda-forge scikit_route

Fast User Guide

This is an example on how to use Scikit Route and show how easy it is.

Here the MTSPTW problem is solved, we need to create a good path for our commercials in the City in Barcelona and we have time restrictions (in Spain is not legal work more than 8h) and cost restrictions. We will use the Genetic algorithm wich is a algorithm that fit very well for our approach.

Load the modules

First of all we load the modules that we will use:

from sklearn_route.datasets import load_barcelona
from sklearn_route.preprocessing import matrix_to_dict
from sklearn_route.genetics import Genetic

Pre-processing data

Here we put the data in the format required by the algorithm. In this case we use the matrix_to_dict function to transform our id_points cost in fuel and in time to dicts of dicts. You can see the docs of all functions, using the help() command. Also there are more detailed examples in the docs webpage.

df_barcelona = load_barcelona()

#Dataset - id of origin - id of destiny - column to transform (in this case the hour)
time_matrix = matrix_to_dict(df_barcelona, "id_origin", "id_destinity", "hora")

#Dataset - id of origin - id of destiny - column to transform (in this case the cost)
cost_matrix = matrix_to_dict(df_barcelona, "id_origin", "id_destinity", "hora")

#Create a random route, it's will needed to initiate the algorithm
route_example = list(dict.fromkeys(cost_matrix_df).keys())

Running the Algorithm

Here we see how the algorithm operation is the same as Scikit Learn. You can see all the Hyperparamenters, what they do, and examples with the builtin help() function. Also there are more detailed examples in the docs webpage.

In this case we choose an algorithm with Metaheuristic aproach to the problem. There are other algorithms in the package that can solve this problem or have another approach.

#Instantiate the algorithm
ga = Genetic(p_m = 0.3, pop=400, gen=2000, k=5, p_c early_stoping=100, max_time_work=6, extra_cost=12.83)

#random route - time_matrix - cost_matrix
result = ga.fit(route_example, time_matrix, cost_matrix)

#Printing the best route
print(result)

#Printing the loss function
print(ga.history_)

Conclusions

Sklearn Route is library to solve differents types of route problems, easy to use and fast to learn. If you want to know more about the different algorithms, hyperparameters, how it works and more examples, the package have a very deep and detailed documentations with a lot of examples in the official documentation here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skroute-1.0.0a1.tar.gz (263.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skroute-1.0.0a1-cp37-cp37m-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.7m

File details

Details for the file skroute-1.0.0a1.tar.gz.

File metadata

  • Download URL: skroute-1.0.0a1.tar.gz
  • Upload date:
  • Size: 263.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.7.6

File hashes

Hashes for skroute-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 2d63f0c65e89ed2028dc98b9c8fcd84766b3d69607dfe5c3a77e38beeebe61c3
MD5 8698e9f935aff5579729e79f431c59e1
BLAKE2b-256 9ed7aa4ede8f0bfabcf79a6275c77f9da48b03fc388712a118018f7c1fc06f58

See more details on using hashes here.

File details

Details for the file skroute-1.0.0a1-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: skroute-1.0.0a1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.7.6

File hashes

Hashes for skroute-1.0.0a1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cf4ebe851e704ac18798e5eb68dc0b623f683ab7839e3d6bcbea29491b91414b
MD5 e76cfe9f4b377dc0f8d5d17f3fc34f9f
BLAKE2b-256 8607a600ab2703138e007270212ec8cb1afcc9843516d011a17b18eb3f7453c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page