Giter Club home page Giter Club logo

optimizer-api's Introduction

Mapotempo Optimizer API Build Status

Run an optimizer REST API depending of many contraints for a Vehicle Routing Problem (VRP).

Prerequisite

For ruby, bundler and gems, rbenv or rvm are recommanded.

On Ubuntu

sudo apt install libssl-dev libyaml-dev
  • Depending on the Ubuntu version, libssl 1.0 may not be available. Then the following may fix the issue.
sudo add-apt-repository 'deb http://security.ubuntu.com/ubuntu bionic-security main'
sudo apt update
sudo apt install libssl1.0-dev
  • Ruby 2.5.5 (if not using rbenv/rvm)
sudo apt install ruby-full
  • redis-server
sudo apt install redis-server
  • Start redis service
sudo systemctl enable redis-server.service
  • libgeos-dev
sudo apt install libgeos-dev libgeos-3.7.1
  • libicu-dev
sudo apt install libicu-dev

On Mac OS

brew install redis
brew install geos

Installation

gem install bundler
bundle install

This project requires some solver and interface projects in order to be fully functional!

Note : when updating OR-Tools you should to recompile optimizer-ortools.

By default, Optimizer-API and the related projects are supposed to be in parallel folders as follows:

Project folders

We recommand to use a symbolic link to point the OR-Tools asset.

  ln -s or-tools_Debian-10-64bit_v7.8.7959 or-tools

Configuration

Adjust config/environments files.

Running

bundle exec rackup [-p 1791]

And in production mode:

APP_ENV=production bundle exec rackup [-p 1791]

Start Redis and then start the worker

APP_ENV=production COUNT=5 QUEUE=* bundle exec rake resque:workers

Usage

The API is defined in Swagger format at http://localhost:1791/0.1/swagger_doc and can be tested with Swagger-UI http://swagger.mapotempo.com/?url=http://optimizer.mapotempo.com/0.1/swagger_doc

curl -X POST --header "Content-Type:application/json" --data '{"vrp":{"vehicles":[]}}' http://localhost:1791/0.1/vrp/submit.json?api_key=demo

Moreover, the concepts used are described in the docs folder.

Test

Run tests:

APP_ENV=test bundle exec rake test

If you want to get information about how long each test lasts:

TIME=true HTML=true APP_ENV=test bundle exec rake test

This generates a report with test times. You can find the report in optimizer-api/test/html_reports folder.

If you want to run a specific test file (let's say real_cases_periodic_test.rb file only):

APP_ENV=test bundle exec rake test TEST=test/real_cases_periodic_test.rb

If you want to run only one specific test (let's say test_instance_clustered test only) you can use focus or call:

APP_ENV=test bundle exec rake test TESTOPTS="--name=test_instance_clustered"

Tests are splitted into several sets and you can replay only one or more set(s):

APP_ENV=test bundle exec rake test:api
APP_ENV=test bundle exec rake test:api test:models

You can list all available tasks with:

bundle exec rake -T

You can add your own tests on specific Vehicle Routing Problem (for instance data from real cases). Let's see how to create a new test called "new_test". You will find template for test in test/real_cases_test.rb

Before creating test, you need to capture scenario, in order to have a static image of your problem, insensitive to the routers edits.

Add your test JSON file into test/fixtures/. Now to create your test, just copy test template in test/wrappers/real_cases_test.rb, or any equivalent file. Once launched, the dump file of the problem will be created and put aswell in test/fixtures as following:

  • new_test.dump file corresponding to complete vrp with calculated matrices if not provided

If you create a test by using .dump, your test will fail as soon as vrp model is changed. Just run following task to update fixtures:

TEST_DUMP_VRP=true APP_ENV=test bundle exec rake test TEST=test/real_cases_test.rb

Note: you can update a test and run the modified scenario with new vrp .json:

bundle exec rackup [-p 1791]
COUNT=5 QUEUE=* bundle exec rake resque:workers
curl -X POST --header "Content-Type:application/json" --data @test/fixtures/my_test.json http://localhost:1791/0.1/vrp/submit.json?api_key=key

If you don't want to run some long real cases tests you can deactive them:

SKIP_REAL_CASES=true APP_ENV=test bundle exec rake test

Github Actions

To test on Github Actions with a optimizer-ortools different than the latest version, specify in your Actions configuration the following environment variable : OPTIMIZER_ORTOOLS_VERSION with you github owner nick.

Docker

Start the services docker compose up -d

Start the api docker compose exec api bundle exec rackup -o 0.0.0.0

Stop the services docker compose stop

optimizer-api's People

Contributors

alain-andre avatar braktar avatar dependabot[bot] avatar fab-girard avatar flomapo avatar fonsecadeline avatar frodrigo avatar mika-5 avatar mrfenril avatar pierre-graber avatar senhalil avatar xals avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

optimizer-api's Issues

Request for advice

I have a set of points that is done in two days.
I would like that at the end of the first day, the vehicle stops on one point and does not return to the depot. On the second day, the vehicle starts again at the point where it stopped there instead of returning to the depot.
I hope I have been understandable...
Thank

Error with matrix

Hello !

I have an error when I use matrix system :

"avancement": "The task failed because of an error: undefined method []' for nil:NilClass", (/home/www/optimizer-api/optimizer_wrapper.rb:563:in block in route_total_dimension')

My json :
{ "vrp": { "configuration": { "preprocessing": { "cluster_threshold": 0.0, "prefer_short_segment": true }, "resolution": { "duration": 600000, "initial_time_out": 18000, "iterations_without_improvment": 300, "time_out_multiplier": 2 }, "restitution": { "intermediate_solutions": false } }, "matrices": [ { "distance": [ [ 0, 41512.1, 20525.1, 50609, 37095.3 ], [ 40837.4, 0, 41662.6, 20075.9, 9429.4 ], [ 19289.4, 43685.5, 0, 37427.4, 39268.7 ], [ 50317, 19821.3, 37287.9, 0, 28403.1 ], [ 37252.1, 9548.8, 38077.3, 27283.8, 0 ] ], "id": "matrice1", "time": [ [ 0, 2630.8, 1280.3, 2925.5, 2079.8 ], [ 2576.8, 0, 2759.2, 1470.8, 780.8 ], [ 1208.6, 2802.8, 0, 2357.5, 2251.8 ], [ 2866.7, 1441.1, 2312.1, 0, 1917.8 ], [ 2062.6, 777.9, 2245, 1948, 0 ] ] } ], "points": [ { "id": "l0", "matrix_index": 0 }, { "id": "l1", "matrix_index": 2 }, { "id": "l2", "matrix_index": 3 }, { "id": "l3", "matrix_index": 4 }, { "id": "l4", "matrix_index": 5 } ], "services": [ { "activity": { "duration": 1800, "point_id": "l1", "timewindows": [ { "end": 43200, "start": 0 } ] }, "id": "s1", "type": "service" }, { "activity": { "duration": 1800, "point_id": "l2", "timewindows": [ { "end": 43200, "start": 0 } ] }, "id": "s2", "type": "service" }, { "activity": { "duration": 1800, "point_id": "l3", "timewindows": [ { "end": 43200, "start": 0 } ] }, "id": "s3", "type": "service" }, { "activity": { "duration": 1800, "point_id": "l4", "timewindows": [ { "end": 43200, "start": 0 } ] }, "id": "s4", "type": "service" } ], "vehicles": [ { "end_point_id": "l0", "id": "c1", "matrix_id": "matrice1", "start_point_id": "l0", "timewindow": { "end": 64800, "start": 0 } }, { "end_point_id": "l0", "id": "c2", "matrix_id": "matrice1", "start_point_id": "l0", "timewindow": { "end": 64800, "start": 0 } }, { "end_point_id": "l0", "id": "c3", "matrix_id": "matrice1", "start_point_id": "l0", "timewindow": { "end": 64800, "start": 0 } }, { "end_point_id": "l0", "id": "c4", "matrix_id": "matrice1", "start_point_id": "l0", "timewindow": { "end": 64800, "start": 0 } }, { "end_point_id": "l0", "id": "c5", "matrix_id": "matrice1", "start_point_id": "l0", "timewindow": { "end": 64800, "start": 0 } } ] } }

Can you help me please ?
Thanks a lot

Mistake in documentation

Hello,

In swagger.json, Vehicle definition's part :

  {
    "id": "vehicle_id-1",
    "router_mode": "car",
    "router_dimension": "time",
    "speed_multiplier": 1.0,
    "sequence_timewindows": [{
        "day_index": 0,
        "start": 25200,
        "end": 57600
    }, {
        "day_index": 1,
        "start": 25200,
        "end": 57600
    }, {
        "day_index": 2,
        "start": 25200,
        "end": 57600
    }, {
        "day_index": 3,
        "start": 25200,
        "end": 57600
    }, {
        "day_index": 4,
        "start": 25200,
        "end": 57600
    }],
    "start_point_id": "store",
    "end_point_id": "store",
    "unavailable_work_day_indices": [5, 7]
  }

Indice 7 for the day does not exist (between 0, 6)

"unavailable_work_day_indices": [5, 6]

Thank

Break time evolution

Hello,

An idea of evolution:
When we specify a break for a vehicle, the time of the break is mixed with the time of the trip. (travel_time)
It could be interesting to separate in two values : travel_time and break_time.

In any case, your tools work very well!

Thanks

Strange results

Hello,

My test :
JSON

Vehicule Time :
Day 1 : 7H - 24H => 7 * 3600 : 25200
Day 2 : 24H - 48H
Day 3 : 48H - 72H
Day 4 : 72H - 96H
Day 5 : 96H - 120H
Day 6 : 120H - 139H => 139 * 3600 : 500400

 "timewindow":{  
               "start":25200,
               "end":500400
            }

Break :
Day 1 : 19H - 31H
Day 2 : 43H - 55H
Day 3 : 67H - 75H
Day 4 : 91H - 103H
Day 5 : 115H - 126H

"rests":[  
         {  
            "duration":43200,
            "id":"break-0",
            "timewindows":[  
               {  
                  "start":68400,
                  "end":68900
               }
            ]
         },
         {  
            "duration":43200,
            "id":"break-1",
            "timewindows":[  
               {  
                  "start":154800,
                  "end":155300
               }
            ]
         },
         {  
            "duration":43200,
            "id":"break-2",
            "timewindows":[  
               {  
                  "start":241200,
                  "end":241700
               }
            ]
         },
         {  
            "duration":43200,
            "id":"break-3",
            "timewindows":[  
               {  
                  "start":327600,
                  "end":328100
               }
            ]
         },
         {  
            "duration":43200,
            "id":"break-4",
            "timewindows":[  
               {  
                  "start":414000,
                  "end":414500
               }
            ]
         }
      ]

Services :
Day 1 : 9H - 17H
Day 2 : 33H - 41H
Day 3 : 57H - 65H
Day 4 : 81H - 89H
Day 5 : 105H - 113H
Day 6 : 129H - 137H

{  
            "id":"service31",
            "type":"service",
            "activity":{  
               "point_id":"point_31",
               "timewindows":[  
                  {  
                     "start":32400,
                     "end":57600
                  },
                  {  
                     "start":118800,
                     "end":147600
                  },
                  {  
                     "start":205200,
                     "end":234000
                  },
                  {  
                     "start":291600,
                     "end":320400
                  },
                  {  
                     "start":378000,
                     "end":406800
                  },
                  {  
                     "start":464400,
                     "end":493200
                  }
               ],
               "duration":3600
            }
         },

The solution is complete but very strange :

screen shot 2018-08-17 at 11 05 30
(the white point is unassign)
screen shot 2018-08-17 at 11 21 48

  • over the last two days there is no result
  • the first day start at 11H (blue road) yet there is another point beside (18, 19, 20)
  • order make service is strange

Can you help me please ?

Thank

Error on docker container

optimizer_1 | [ E 2018-05-23 13:06:16.8901 10/Ti age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /srv/app: The application encountered the following error: undefined local variable or method `server' for #<Rack::Builder:0x005569e292e7c0 @run=nil, @Map=nil, @use=[]> (NameError)

it runs without errors but on optimizing reques it fails and gives back an html back and this error

API - Right breaks setting

Hi, first thanks for your software it's amazing.
I use it and I have a question about the right setting to be apply to set a break.

Below there is an object for your api but it seem to not understand the break.

Detail about the configuration object :

  • all time values are in seconds start from midnight
  • I set a break of 30 minutes between 12 am and 1pm

Thanks in advance.

JSON configuration

https://gist.github.com/braktar/3a86291589e798b4d1a7c1277f165ae7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.