Git Product home page Git Product logo

open-vrp's Introduction

Open-VRP

Check out the Wiki for an overview of Open-VRP or scroll down for a summary, fork and get-started!

Synopsis

Open VRP is a framework to model and solve VRP-like problems for students, academics, businesses and hobbyist alike. This framework allows for quick implementation of simple TSP/VRP problems to more complicated VRPTW, PDPTW, MDCPVRPPDTW, or however cool you want to sound. The library is extensibly written in Common Lisp's CLOS. Depending on your interest/purpose, an algorithm can be:

The Problem object (e.g. VRP) and the Algorithm object (e.g. Genetic Algorithm) are modelled seperately and combined with the generic method (solve-prob problem algo). Different solution algorithms can be tested and compared against each other on the same problem (which you only model once).

Current features (v. 0.6.2)

  • TSP, VRP, CVRP, VRPTW, CVRPTW
  • Homogenous/heterogenous fleet
  • Demands, duration, capacity, time-windows, speed
  • Define network using coordinates or (asymettric) distance matrix
  • Tabu Search
  • Logging of search progress (to file or to REPL)
  • Plotting of final solution or after each iteration
  • Test-case loader (Solomon and TSPLIB format)
  • Batch-run to test algo on a directory of test-cases

Vision

Too often have I found myself having to build a VRP model from scratch, just to experiment with some meta-heuristics for a school paper. Academics/students with a background/interest in Mathematics/Operations Research without the skills/patience for die-hard coding (in C++/Java), have no choice but to spend their valuable time stuck in the debug/test/debug cycle. Here is why those in OR should consider Common Lisp as an option.

With this framework, I hope to catalyze the research and application of routing solutions. Researchers in innovative new algorithms should not need to fiddle in the Eclipse debugger screen. They should be able to focus all their energy and effort in devising their heuristics. OR should be kept fun and engaging.

The ultimate vision for Open VRP is a simple intuitive toolkit for the OR community, free for anyone.

Installation

~$ git clone git://github.com/mck-/Open-VRP.git

Add this path and evaluate require:

(push "/path/to/Open-VRP/" asdf:*central-registry*)
(require 'open-vrp)
(in-package :open-vrp)

Usage

Check the Wiki for more documentation, the following is a short summary of the main functionality.

solve-prob expects a problem object and an algo object.

test-vrp, solomon25, solomon100, christofides-1 and christofides-2 are pre-loaded demo problems. To use Tabu Search:

(solve-prob test-vrp (make-instance 'tabu-search :iterations 10 :animatep T))
(solve-prob solomon100 (make-instance 'tabu-search :iterations 100))
(solve-prob christofides-2 (make-instance 'tabu-search :iterations 50))

By default, problems will plot to plots/name.png and log to run-logs/name.txt where name refers to the :name slot of the Problem object. (toggle-plot <problem>) to disable plotting the final solution. Use (set-log-mode <problem> x) to switch from [0] no logging, [1] logging to file or [2] logging to the REPL.

If you don't like the legend in the plot, turn it off with (toggle-legend <problem>).

When :animatep is set to T, each iteration will produce a plot in run-frames/Iteration x.png (much slower, since it needs to plot each iteration). You may use (toggle-animate <algo>) to turn it on/off.

You can define your own problem objects with:

(define-problem "VRP" fleet-size :node-coords-list node-coords :to-depot T)
(define-problem "CVRP" fleet-size :node-coords-list node-coords :demands demands-list :capacities capacity-list)
(define-problem "VRPTW" fleet-size :node-coords-list node-coords :time-windows time-windows :durations durations :speeds speed)

where node-coords is a list of pairs, demands-list a list of associated demands (must be same length), and fleet-size is the number of vehicles. When a demands-list and vehicle capacity are provided, the resulting problem is a CVRP. If time-windows (list of pairs) and durations are given, the resulting problem object is a VRPTW. When everything is provided, it creates a CVRPTW. Each class of problem has its own specific constraints to check.

You may also provide a(n asymmetric) distance matrix instead of node-coords (real-life problems). You won't be able to plot the solution without node-coords though.

(define-problem "ASYM-CVRP" 3 :demands '(0 1 2 3 2 1) :capacities 8 :dist-array dist-aray)

Note that the above will create 6 nodes, so the dimensions of the dist-array must be 6x6. Also note that we provide a single number for capacities (instead of a list with length 3), which means that all vehicles will have a capacity of 8. Single numbers are allowed for :demands, :durations, :capacites and :speeds

Or to load a problem from a text-file (currently supports Solomon-format and TSPLIB cvrp format):

(defvar test-case-solomon (load-test-case-file "path-to-solomon-file-format.txt"))
(defvar test-case-tsplib (load-test-case-file "path-to-tsplib-file-format.vrp"))

When the algo is finished running, it returns the Algo object, which contains :current-sol and :best-sol. Use iterate-more to keep searching:

(iterate-more <algo> int)

Output

An example output of Solomon's VRPTW 100-customers benchmark test-case, solved with Tabu Search.

alt Optimal solution

TODO

  • Extend VRP model to PDPTW
  • Run logs/statistics for test-result gathering (including batch runs)
  • User-interface (better macros)
  • Plotting can be improved (real-time output instead of .png files)
  • ...

License

Open-VRP is licensed under the terms of the Lisp Lesser GNU Public License, known as the LLGPL. The LLGPL consists of a preamble (see above URL) and the LGPL. Where these conflict, the preamble takes precedence. Open-VRP is referenced in the preamble as the "LIBRARY."

open-vrp's People

Contributors

ckairaba avatar mck- avatar puercopop 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar

open-vrp's Issues

any package for python?

Dear authors,

It seems that this package is written by Lisp. I am wondering that is there a released python package to solve vehicle routing problem?

return to base

For most VRP problems you do, but not all of them.

One approach is to start with [0] [0] as initial routes, and insert nodes in between them:

Adjust initial solutions to have two base nodes in the route
Adjust way of checking for "empty routes"
Adjust generating moves (to prevent appending to end of route, after the [0])

Another approach is to append [0] at the end:

Adjust fitness calculation
Adjust constraints checking (make sure it gets back in time)
Adjust print solution and final solution

Which one is better?

run stats and logs

some basic run stats and logs of the runs would be nice in an output file.

Perhaps a batch run, with mean/stdv/time..

Also a graph of some sort tracking the run - best-sol-fitness on the Y and iterations on the X.

Quicklisp

I suggest updating the installation slightly by mentioning Quicklisp, because beginners may don't konw how to deal with lib and dependence.

OVRP?

Does the word "Open" in the repository name refer to the Open VRP variant? Or "Open Source" ?

Provided that at OVRP, the vehicle does not return to the depot,
Is it possible to solve Open Vehicle Routing Problem with your code?

random plotting colors

Currently for plotting routes, the colors are selected at random. Sometimes the colors are white (hence invisible). For animation plotting, the colors are also inconsistent.

TSPLIB loader needs to be generalized

read-cvrp.lisp can only read CVRP files from TSPLIB. It'd be great if it could read TSP, VRP, VRPTW etc using the same format.

Currently, the code assumes a demand_section, so when attempting to load a TSP file (without a demand section), it won't work.

tabu search slot :current-sol not setf properly after run-algo

For some strange reason I don't understand, after (run-algo test-vrp (make-instance 'tabu-search)) the :current-sol slot of the tabu-search instance returned, is still empty.

When manually doing:

(defvar test-ts (make-instance 'tabu-search))
(initialize test-vrp test-ts)
(iterate test-ts)

it does set it correctly. And (run-algo) for TS is implemented to do exactly that. Initialize, iterate and return the algo instance.

Tabu search is slow!

The algorithm needs some serious tweaking. On a 100-node sized problem, each iteration takes a few seconds. This is much slower than my Java implementation, which could do 100 iterations in a few seconds.

Guess it's time to profile...

define-problem macro to accept single values AND lists

Currently, all key attributes only accept lists (that are of equal length to either node-coords or fleet-size). e.g. :capacities has to be a list of equal length to fleet-size, with each element setting each vehicle's capacity. Same applies for :speeds.

It'd be nice if you could also provide a single value, which would create a homogenous fleet.

8fac15c was an attempt that failed in lexical environments.

Fiddling with nested backquotes for a few days, I decided to ask for help. Though the answer was helpful, it couldn't apply cleanly to this rather large macro.

Anyone up for the challenge?

Extend VRPTW to PDPTW

  • new classes
  • new insertion-moves
  • new TS moves
  • new fitness func
  • new constraintsp func
  • new test-case reader for Li & Lim benchmark data
  • extend define-problem macro
  • extend create-network macro
  • extend create-fleet macro

Increase performance of Tabu Search

Profile results of Tabu Search on solomon100 with 300 iterations (Tue 13 Mar, 2012)
(Open-VRP v 0.5 -- Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz -- 4GB)

seconds  |     gc     |     consed    |    calls    |  sec/call  |  name  

26.118 |      0.936 | 1,311,487,712 |  25,107,886 |   0.000001 | ROUTE-INDICES
17.093 |      0.000 |       106,344 |  21,381,787 |   0.000001 | NODE-DISTANCE
 9.436 |      0.000 |        80,008 |   9,638,717 |   0.000001 | NODE
 9.335 |      0.156 |   170,091,848 |  21,381,787 |   0.000000 | OPEN-VRP.UTIL::DISTANCE-COORDS
 8.428 |      0.000 |        74,248 |   8,049,010 |   0.000001 | VEHICLE
 5.399 |      0.024 |    63,482,488 |   9,869,463 |   0.000001 | TIME-AFTER-SERVING-NODE
 5.348 |      0.000 |         4,248 |  13,122,868 |   0.000000 | NODE-ID
 5.091 |      0.000 |    12,483,496 |     366,157 |   0.000014 | SORT-IGNORE-NIL
 4.544 |      0.000 |         4,568 |  11,639,224 |   0.000000 | NODE-END
 4.447 |      0.116 |   130,699,528 |     365,677 |   0.000012 | OPEN-VRP.ALGO::GENERATE-INSERTION-MOVES
 4.168 |      0.000 |             0 |  10,220,055 |   0.000000 | MOVE-FITNESS
 3.508 |      0.000 |           256 |   9,638,959 |   0.000000 | PROBLEM-NETWORK
 3.468 |      0.000 |         4,504 |   8,538,766 |   0.000000 | PROBLEM-FLEET
 2.780 |      0.000 |           728 |   6,581,171 |   0.000000 | VEHICLE-ROUTE
 2.694 |      0.000 |        19,616 |   2,724,639 |   0.000001 | NODE-ON-ROUTEP
 2.571 |      0.000 |       105,504 |   1,617,893 |   0.000002 | EMPTY-ROUTEP
 2.559 |      0.012 |    28,142,048 |     436,600 |   0.000006 | ONE-DESTINATIONP
 1.839 |      0.000 |         4,440 |   2,575,481 |   0.000001 | IN-CAPACITYP
 1.621 |      0.004 |    30,858,912 |   1,308,832 |   0.000001 | DISTANCE
 1.604 |      0.000 |             8 |   3,138,302 |   0.000001 | PROBLEM-TO-DEPOT
 1.188 |      0.000 |            48 |   2,724,639 |   0.000000 | (SETF MOVE-FITNESS)
 1.129 |      0.000 |             0 |   2,532,335 |   0.000000 | NODE-DEMAND
 0.625 |      0.000 |     9,587,304 |     122,321 |   0.000005 | OPEN-VRP.UTIL::GET-FROM-LIST

load test case issues

Hi
Just try the following command in your console :
$ cd $HOME
$ git clone https://github.com/mck-/Open-VRP
$ sbcl

  • (pushnew "~/Open-VRP" asdf:central-registry)
  • (asdf:operate 'asdf:load-op :open-vrp)

You will get the following error :
debugger invoked on a SB-INT:SIMPLE-FILE-ERROR in thread

<THREAD "initial thread" RUNNING {AB1F999}>:

error opening #P"/home/kairaba/test-cases/25-cust.txt"

To correct this bug, we need to change the definition of the test-case variables in the file test-cases.lisp. So,
we get the following definitions :
(defvar solomon25 (load-testcase-solomon (merge-pathnames "test-cases/25-cust.txt"
(asdf:system-source-directory 'open-vrp))))
...
I put some other corrections in my open-vrp fork.
Cheers

(in-package 'open-vrp) problem

I have installed SBCL and asdf, quicklisp and other libraries.

When I input (in-package 'open-vrp), it shows warning message as follow. I do not know what's wrong. Where should I check? How to solve it? Thanks


(in-package 'open-vrp)

debugger invoked on a SIMPLE-TYPE-ERROR in thread

<THREAD "main thread" RUNNING {AB4F921}>:

'OPEN-VRP cannot be coerced to a string.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

(STRING 'OPEN-VRP)
0] (solve-prob test-vrp (make-instance 'tabu-search :iterations 10 :animatep T))

; in: LAMBDA (#:G799)
; (SOLVE-PROB TEST-VRP (MAKE-INSTANCE 'TABU-SEARCH :ITERATIONS 10 :ANIMATEP T))
;
; caught STYLE-WARNING:
; undefined function: SOLVE-PROB
;
; caught WARNING:
; undefined variable: TEST-VRP
;
; compilation unit finished
; Undefined function:
; SOLVE-PROB
; Undefined variable:
; TEST-VRP
; caught 1 WARNING condition
; caught 1 STYLE-WARNING condition

debugger invoked on a UNBOUND-VARIABLE in thread

<THREAD "main thread" RUNNING {AB4F921}>:

The variable TEST-VRP is unbound.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Reduce debugger level (to debug level 1).
1: Exit debugger, returning to top level.

((LAMBDA (#:G799)) #)

multi-start heuristics

A multi-start wrapper function would be useful for all kinds of search heuristics that have randomness in their initial solution generation.

It runs the algo multiple times, from which the best solution is chosen.

This widens the exploration of the search space by starting from multiple points.

plotting coords

when loading 25 customer solomon test-case, the coords for plotting seems to be off (using only 1 quarter of the canvas). Some calculation in util/draw-solution.lisp is not correct.

See Tabu-List in logs and/or plots

Hi there,

I don't know how active this still is, but I'm having a problem with some test and I would like to check the tabu-list. There is nothing in the logs or plots about which node is currently on the tabu-list.
Is there some way to check the list?
cheers

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.