A simple logistic routing system using Ruby, Rails, PostgreSQL, Postgis and PGRouting.
You need to install PostgreSQL and other two extensions: Postgis and PGRouting.
The easiest way is using Homebrew on Mac OS:
brew update
brew install postgresql postgis pgrouting
But if you're using other OS I highly recommend you to read those guides:
- http://www.postgresql.org/download/
- http://postgis.net/install
- http://docs.pgrouting.org/2.0/en/doc/src/installation/index.html
IMHO, PostgreSQL has the best community around spatial data and routing systems, with the most complete tools available.
It's reliable and free.
Installing Ruby is really simple with RVM or Rbenv:
After installing all the main dependencies clone the project:
git clone [email protected]:guivinicius/logistique.git
and run bundler
cd logistique
bundle install
Install Foreman gem: https://github.com/ddollar/foreman
gem install foreman
Change the database.yml
file to your own configurations and run the following commands:
foreman start
rake db:setup
Since the app is pretty much a simple API, makes sense to use Sinatra or Rails-api, but I'm planning to build a interface as well.
- URL: /maps
- VERB: POST
- PARAMETERS:
- map[name]
- map[network]
To send the network follow the format below, each line is a route composed by source, target and length in Kilometers:
A B 10
B D 15
A C 20
C D 30
B E 50
D E 30
The first line is a route from the point A to point B with a distance of 10 kilometers.
- Encoding your own data with %20 for spaces and %0A for line Breaks:
curl -X POST \
-d 'map[name]=Default' \
-d 'map[network]=A%20B%2010%0AB%20D%2015%0AA%20C%2020%0AC%20D%2030%0AB%20E%2050%0AD%20E%2030' \
http://localhost:3000/maps
- Using a external json file
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d @data.json \
http://localhost:3000/maps
# data.json
{
"map": {
"name": "Default",
"network": "A B 10\nB D 15\nA C 20\nC D 30\nB E 50\nD E 30"
}
}
- URL: /maps/:id/best_route
- VERB: GET
- PARAMETERS:
- id (map id)
- source (point)
- target (point)
- vehicle_autonomy
- fuel_price
$ curl -X GET \
-d "source=A&target=D&vehicle_autonomy=10&fuel_price=2.50" \
http://localhost:3000/maps/4/best_route
#result
{
"route":"A B D",
"cost":6.25
}