Commit 95f81f9d authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

Merge branch 'master' of gitlab.crans.org:leger/rv2

parents 09220ab2 3f1360b8
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
*.swp *.swp
src/elevation_create_database src/elevation_create_database
src/elevation_query_database src/elevation_query_database
src/route_create_databases
src/route_query_lookup_database src/route_query_lookup_database
src/route_query_nodes_database src/route_query_nodes_database
src/route src/analyze_pbf
src/get_route
src/lmdb_rewriter
src/route_create_databases_from_pbf
...@@ -5,6 +5,7 @@ LMDB ...@@ -5,6 +5,7 @@ LMDB
---- ----
This lib is necessary for all executables. Let your distribution do the job. This lib is necessary for all executables. Let your distribution do the job.
(liblmdb-dev on debian).
osmpbf osmpbf
------ ------
...@@ -12,13 +13,14 @@ osmpbf ...@@ -12,13 +13,14 @@ osmpbf
This lib is necessary only for the creation of route database. Do not do this in This lib is necessary only for the creation of route database. Do not do this in
the rv2 dir but in the dir which contains rv2 (or change rv2 src makefile). the rv2 dir but in the dir which contains rv2 (or change rv2 src makefile).
{{{ This lib need libprotobuf to be build and the protobuf compiler. Let your
distribution do the job (libprotobuf-dev and protobuf-compiler on debian).
git clone https://github.com/inphos42/osmpbf.git git clone https://github.com/inphos42/osmpbf.git
cd osmpbf cd osmpbf
git clone https://github.com/inphos42/generics.git git clone https://github.com/inphos42/generics.git
cmake . cmake .
make make
}}}
Build Build
===== =====
...@@ -26,23 +28,23 @@ Build ...@@ -26,23 +28,23 @@ Build
Go in the src dir, and use make for the target you want. The following target Go in the src dir, and use make for the target you want. The following target
are available: are available:
- elevation_create_database: creation of elevation database from srtm files - `elevation_create_database`: creation of elevation database from srtm files
- elevation_query_database: query of elevation by coordinates - `elevation_query_database`: query of elevation by coordinates
- lmdb_rewriter: rewrite a lmdb database, usefull to rewrite big sparse file as - `lmdb_rewriter`: rewrite a lmdb database, usefull to rewrite big sparse file as
little dense one. little dense one.
- route_create_database_from_pbf: (needs osmpbf lib) creation of the route - `route_create_database_from_pbf`: (needs osmpbf lib) creation of the route
database (constituted by two db, lookup and nodes) from a pbf file and using database (constituted by two db, lookup and nodes) from a pbf file and using
elevation database. elevation database.
- route_query_lookup_database: query lookup db in route db to found nodes id - `route_query_lookup_database`: query lookup db in route db to found nodes id
near the given coordinates. Nodes are searched on the same connected near the given coordinates. Nodes are searched on the same connected
component. component.
- route_query_nodes_database: query nodes db in route db to have informations - `route_query_nodes_database`: query nodes db in route db to have informations
about given nodes id. about given nodes id.
- route: Give a route between given coordinated. The goal of the project. - `get_route`: Give a route between given coordinated. The goal of the project.
...@@ -14,16 +14,14 @@ pbf is updated if the pdf cover the same area. ...@@ -14,16 +14,14 @@ pbf is updated if the pdf cover the same area.
Analyze pbf Analyze pbf
----------- -----------
{{{
./src/analyze_pbf SOMEWHERE/france-latest.osm.pbf > SOMEWHERE/list_needed_srtm ./src/analyze_pbf SOMEWHERE/france-latest.osm.pbf > SOMEWHERE/list_needed_srtm
}}}
The `analyze_pbf` program give: The `analyze_pbf` program give:
- in stdout the list of needed srtm tiles. - in stdout the list of needed srtm tiles.
- is stderr the number of couple (way,node)s usefull for routing. Let N the - is stderr the number of couple (way,node)s usefull for routing. Let N the
number of couple (way,node)s returned by analyze_pbf. The prediction are the number of couple (way,node)s returned by `analyze_pbf`. The prediction are the
following: following:
- (150 Bytes) × N : the routing database size - (150 Bytes) × N : the routing database size
...@@ -44,28 +42,22 @@ With the `list_needed_srtm`, download the tiles. A script is provided in scripts ...@@ -44,28 +42,22 @@ With the `list_needed_srtm`, download the tiles. A script is provided in scripts
This script is the definition of brutality. This script is the definition of brutality.
{{{
./scripts/dlsrtm SOMEWHERE/list_needed_srtm SOMEWHERE/srtmzip ./scripts/dlsrtm SOMEWHERE/list_needed_srtm SOMEWHERE/srtmzip
}}}
Unzip SRTM files Unzip SRTM files
---------------- ----------------
{{{
mkdir -p SOMEWHERE/srtm mkdir -p SOMEWHERE/srtm
find SOMEWHERE/srtmzip/ -print0 | xargs -0 -n1 -I{} unzip {} -d SOMEWHERE/srtm find SOMEWHERE/srtmzip/ -print0 | xargs -0 -n1 -I{} unzip {} -d SOMEWHERE/srtm
}}}
We don't need SOMEWHERE/srtmzip anymore. You can remove it. We don't need `SOMEWHERE/srtmzip` anymore. You can remove it.
Creating elevation db Creating elevation db
--------------------- ---------------------
{{{
./src/elevation_create_database SOMEWHERE/ele_db_sparse SOMEWHERE/srtm/*.hgt ./src/elevation_create_database SOMEWHERE/ele_db_sparse SOMEWHERE/srtm/*.hgt
}}}
This elevation db is directly usable. Buto create this elevation db, the program This elevation db is directly usable. Buto create this elevation db, the program
use a writable map, and the elevation database is a big sparse file. If you are use a writable map, and the elevation database is a big sparse file. If you are
...@@ -73,20 +65,19 @@ not planning to backup, or transfer this file, you can skip the next step, but ...@@ -73,20 +65,19 @@ not planning to backup, or transfer this file, you can skip the next step, but
the time used in the next step is very small, and this is not a good idea in the time used in the next step is very small, and this is not a good idea in
general case. general case.
We don't need `SOMEWHERE/srtm anymore`. You can remove it.
Converting elevation db Converting elevation db
----------------------- -----------------------
We use the agnostic lmdb_rewriter programm. It read source database, and We use the agnostic `lmdb_rewriter` programm. It read source database, and
re-write it sequencialy (without using writable map). The two database are re-write it sequencialy (without using writable map). The two database are
equivalent, but the created elevation db from last step is a big sparse file, equivalent, but the created elevation db from last step is a big sparse file,
and after this step, the elevation db is a small dense file. and after this step, the elevation db is a small dense file.
{{{
./src/lmdb_rewriter SOMEWHERE/ele_db_sparse SOMEWHERE/ele_db ./src/lmdb_rewriter SOMEWHERE/ele_db_sparse SOMEWHERE/ele_db
}}}
SOMEWHERE/ele_db_sparse is not needed anymore. `SOMEWHERE/ele_db_sparse` is not needed anymore.
Keep it Keep it
...@@ -95,19 +86,17 @@ Keep it ...@@ -95,19 +86,17 @@ Keep it
Keep this elevation database. It is not needed to recreate it when the pbf is Keep this elevation database. It is not needed to recreate it when the pbf is
updated. Except the case when new area is added to the pbf which are not in the updated. Except the case when new area is added to the pbf which are not in the
elevation database, but in this case, you will know it, the routing db (next elevation database, but in this case, you will know it, the routing db (next
part) creation will fail, with a explanation. part) creation will fail, with a explanation (maybe).
Testing the elevation database Testing the elevation database
------------------------------ ------------------------------
The program elevation_query_database use coupe (lon,lat) in stdin and give The program `elevation_query_database` use coupe (lon,lat) in stdin and give
elevation in stdout. For example, to get the elevation of the point given by elevation in stdout. For example, to get the elevation of the point given by
coords (lon=1.017, lat=48.513) use: coords (lon=1.017, lat=48.513) use:
{{{
echo 1.017 48.513 | ./src/elevation_query_database SOMEWHERE/ele_db echo 1.017 48.513 | ./src/elevation_query_database SOMEWHERE/ele_db
}}}
Building routing database Building routing database
...@@ -116,16 +105,16 @@ Building routing database ...@@ -116,16 +105,16 @@ Building routing database
You need to rebuild it each time the pbf is updated (if you need a updated You need to rebuild it each time the pbf is updated (if you need a updated
routing, of course). To create this database, you need to have: routing, of course). To create this database, you need to have:
- the pbf (obviously) - the pbf (obviously)
- a elevation database which cover the area - a elevation database which cover the area
- a large amount of RAM (see predictions in previous part obtained by pbf - a large amount of RAM (see predictions in previous part obtained by pbf
analysis) analysis)
{{{ Run:
./src/route_create_databases_from_pbf SOMEWHERE/france-latest.osm.pbf SOMEWHERE/ele_db SOMEWHERE/route_db ./src/route_create_databases_from_pbf SOMEWHERE/france-latest.osm.pbf SOMEWHERE/ele_db SOMEWHERE/route_db
}}}
Have a cup of tea. Have a cup of tea.
...@@ -136,7 +125,7 @@ The routing database is made by two databases, the lookup database, and the node ...@@ -136,7 +125,7 @@ The routing database is made by two databases, the lookup database, and the node
database. database.
First we test the lookup database. For that the program First we test the lookup database. For that the program
route_query_lookup_database do the job. This program take a set of coupe `route_query_lookup_database` do the job. This program take a set of coupe
(lon,lat) terminated by 0. For example, to get the nodes in the same connected (lon,lat) terminated by 0. For example, to get the nodes in the same connected
component which are near points of coords: component which are near points of coords:
- (lon=0.044, lat=45.661) - (lon=0.044, lat=45.661)
...@@ -145,18 +134,14 @@ component which are near points of coords: ...@@ -145,18 +134,14 @@ component which are near points of coords:
use the following command: use the following command:
{{{
echo 0.044 45.661 0.169 45.648 0.240 45.737 0 \ echo 0.044 45.661 0.169 45.648 0.240 45.737 0 \
| ./src/route_query_lookup_database SOMEWHERE/route_db | ./src/route_query_lookup_database SOMEWHERE/route_db
}}}
Second we test the node db. You must have node id (you can use nodes id found by Second we test the node db. You must have node id (you can use nodes id found by
the lookup, with this you can also verify node are near queried coordinates). the lookup, with this you can also verify node are near queried coordinates).
For example, to obtain information about the nodes 1068822559 and 561188093, use For example, to obtain information about the nodes 1068822559 and 561188093, use
the following command: the following command:
{{{
echo 1068822559 561188093 \ echo 1068822559 561188093 \
| ./src/route_query_nodes_database SOMEWHERE/route_db | ./src/route_query_nodes_database SOMEWHERE/route_db
}}}
...@@ -4,12 +4,12 @@ CXXFLAGS=-O2 -std=c++11 ...@@ -4,12 +4,12 @@ CXXFLAGS=-O2 -std=c++11
#LDFLAGS=-g -Wall #LDFLAGS=-g -Wall
LDFLAGS=-O2 -fwhole-program -flto LDFLAGS=-O2 -fwhole-program -flto
LDLIBS_LMDB=-llmdb -lpthread LDLIBS_LMDB=-llmdb -lpthread
LDLIBS_OSMPBF=-L../../osmpbf/osmpbf -losmpbf -lprotobuf -lz LDLIBS_OSMPBF=-L../../osmpbf/osmpbf -losmpbf -lprotobuf -lz -lpthread
INCLUDE_OSMPBF=-I../../osmpbf -I../../osmpbf/osmpbf/include INCLUDE_OSMPBF=-I../../osmpbf -I../../osmpbf/osmpbf/include
.PHONY: clean .PHONY: clean
all: elevation_create_database elevation_query_database route_query_nodes_database route_query_lookup_database route route_create_databases_from_pbf lmdb_rewriter analyze_pbf all: elevation_create_database elevation_query_database route_query_nodes_database route_query_lookup_database get_route route_create_databases_from_pbf lmdb_rewriter analyze_pbf
lmdb_rewriter: lmdb_rewriter.o lmdb_rewriter: lmdb_rewriter.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB) $(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB)
...@@ -26,7 +26,7 @@ route_query_nodes_database: route_query_nodes_database.o nodes_db.o conv_functio ...@@ -26,7 +26,7 @@ route_query_nodes_database: route_query_nodes_database.o nodes_db.o conv_functio
route_query_lookup_database: route_query_lookup_database.o lookup.o functions.o nodes_db.o lookup_db.o conv_functions.o route_query_lookup_database: route_query_lookup_database.o lookup.o functions.o nodes_db.o lookup_db.o conv_functions.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB) $(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB)
route: route.o route_db.o lookup.o functions.o nodes_db.o lookup_db.o conv_functions.o get_route.o get_route: get_route_main.o route_db.o lookup.o functions.o nodes_db.o lookup_db.o conv_functions.o get_route.o read_from_stdin.o write_to_stdout.o
$(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB) $(CC) $(LDFLAGS) -o $@ $+ $(LDLIBS_LMDB)
route_create_databases_from_pbf: route_create_databases_from_pbf.o lookup_db.o nodes_db.o elevation.o parse_way.o conv_functions.o route_create_databases_from_pbf: route_create_databases_from_pbf.o lookup_db.o nodes_db.o elevation.o parse_way.o conv_functions.o
...@@ -74,7 +74,7 @@ route_db.o: route_db.cc route_db.h conf.h lookup.h lookup_db.h nodes_db.h types. ...@@ -74,7 +74,7 @@ route_db.o: route_db.cc route_db.h conf.h lookup.h lookup_db.h nodes_db.h types.
get_route.o: get_route.cc get_route.h get_route.o: get_route.cc get_route.h
$(CC) $(CXXFLAGS) -c $< -o $@ $(CC) $(CXXFLAGS) -c $< -o $@
route.o: route.cc get_route_main.o: get_route_main.cc
$(CC) $(CXXFLAGS) -c $< -o $@ $(CC) $(CXXFLAGS) -c $< -o $@
route_create_databases_from_pbf.o: route_create_databases_from_pbf.cc route_create_databases_from_pbf.o: route_create_databases_from_pbf.cc
...@@ -83,5 +83,12 @@ route_create_databases_from_pbf.o: route_create_databases_from_pbf.cc ...@@ -83,5 +83,12 @@ route_create_databases_from_pbf.o: route_create_databases_from_pbf.cc
analyze_pbf.o: analyze_pbf.cc analyze_pbf.o: analyze_pbf.cc
$(CC) $(CXXFLAGS) $(INCLUDE_OSMPBF) -c $< -o $@ $(CC) $(CXXFLAGS) $(INCLUDE_OSMPBF) -c $< -o $@
read_from_stdin.o: read_from_stdin.cc conf.h types.h
$(CC) $(CXXFLAGS) -c $< -o $@
write_to_stdout.o: write_to_stdout.cc conf.h types.h route_db.h
$(CC) $(CXXFLAGS) -c $< -o $@
clean: clean:
rm -f *.o rm -f *.o
...@@ -29,5 +29,6 @@ ...@@ -29,5 +29,6 @@
#define RV_MAXIMUM_USED_ANGLE 3 // rad #define RV_MAXIMUM_USED_ANGLE 3 // rad
#define RV_MAXIMUM_RADIUS_OF_CURVATURE 500 // m #define RV_MAXIMUM_RADIUS_OF_CURVATURE 500 // m
#define RV_STATUS_SCALE 1000
#endif #endif
...@@ -184,29 +184,12 @@ double rv_heuristic( ...@@ -184,29 +184,12 @@ double rv_heuristic(
nodeF->lat, nodeF->lat,
nodeF->elevation); nodeF->elevation);
if(parameters.criterion == RV_CRITERION_ENERGY)
{
double delta_elevation = nodeF->elevation - nodeA->elevation;
double min_energy = parameters.mass * RV_G * (parameters.Cr * distance_AF + delta_elevation);
if(min_energy<0)
min_energy = 0;
return(statusA.criterion + min_energy);
}
if(parameters.criterion == RV_CRITERION_TIME)
{
double delta_elevation = nodeF->elevation - nodeA->elevation;
double min_energy = parameters.mass * RV_G * (parameters.Cr * distance_AF + delta_elevation);
if(min_energy<0)
min_energy = 0;
return(statusA.criterion + min_energy/parameters.power);
}
if(parameters.criterion == RV_CRITERION_DISTANCE) if(parameters.criterion == RV_CRITERION_DISTANCE)
{ {
return(statusA.criterion + distance_AF); return(statusA.criterion + distance_AF);
} }
if(parameters.criterion == RV_CRITERION_ENERGY_APPROX || parameters.criterion == RV_CRITERION_TIME_APPROX) if(parameters.criterion == RV_CRITERION_ENERGY || parameters.criterion == RV_CRITERION_TIME)
{ {
double delta_elevation = nodeF->elevation - nodeA->elevation; double delta_elevation = nodeF->elevation - nodeA->elevation;
double velocity = rv_constant_speed_with_constant_power(parameters, distance_AF, delta_elevation); double velocity = rv_constant_speed_with_constant_power(parameters, distance_AF, delta_elevation);
...@@ -214,7 +197,7 @@ double rv_heuristic( ...@@ -214,7 +197,7 @@ double rv_heuristic(
if(min_energy<0) if(min_energy<0)
min_energy = 0; min_energy = 0;
if(parameters.criterion == RV_CRITERION_ENERGY_APPROX) if(parameters.criterion == RV_CRITERION_ENERGY)
return(statusA.criterion + min_energy); return(statusA.criterion + min_energy);
else else
return(statusA.criterion + min_energy/parameters.power); return(statusA.criterion + min_energy/parameters.power);
...@@ -328,9 +311,9 @@ void rv_step( ...@@ -328,9 +311,9 @@ void rv_step(
statusB.distance = statusA.distance + distance_AB; statusB.distance = statusA.distance + distance_AB;
statusB.power = power; statusB.power = power;
if(parameters.criterion == RV_CRITERION_ENERGY || parameters.criterion == RV_CRITERION_ENERGY_APPROX || parameters.criterion == RV_CRITERION_ENERGY_D) if(parameters.criterion == RV_CRITERION_ENERGY || parameters.criterion == RV_CRITERION_ENERGY_D)
statusB.criterion = statusA.criterion + energy * penalty; statusB.criterion = statusA.criterion + energy * penalty;
else if(parameters.criterion == RV_CRITERION_TIME || parameters.criterion == RV_CRITERION_TIME_APPROX || parameters.criterion == RV_CRITERION_TIME_D) else if(parameters.criterion == RV_CRITERION_TIME || parameters.criterion == RV_CRITERION_TIME_D)
statusB.criterion = statusA.criterion + time * penalty; statusB.criterion = statusA.criterion + time * penalty;
else if(parameters.criterion == RV_CRITERION_DISTANCE) else if(parameters.criterion == RV_CRITERION_DISTANCE)
statusB.criterion = statusA.criterion + distance_AB * penalty; statusB.criterion = statusA.criterion + distance_AB * penalty;
......
...@@ -3,12 +3,24 @@ ...@@ -3,12 +3,24 @@
std::list<std::list<route_point_t> > get_routes( std::list<std::list<route_point_t> > get_routes(
route_db_t* route_db, route_db_t* route_db,
parameters_t & parameters, parameters_t & parameters,
std::list< std::pair<double,double> > & geos) std::list< std::pair<double,double> > & geos,
stdout_output_t stdout_output,
bool state_status_on_stderr)
{ {
std::list<nid_t> nids; std::list<nid_t> nids;
route_db->lookup(geos, nids);
if(state_status_on_stderr)
fprintf(stderr,"## state: lookup\n");
int rc = route_db->lookup(geos, nids);
if(rc == RV_ERROR_NO_NODE_FOUND)
{
fprintf(stderr,"## state: failed no_nodes_found_in_the_same_cc\n");
abort();
}
std::list<std::list<route_point_t> > ret; std::list<std::list<route_point_t> > ret;
unsigned int track = 0;
for(std::list<nid_t>::iterator nids_it = nids.begin(); for(std::list<nid_t>::iterator nids_it = nids.begin();
nids_it != nids.end(); nids_it != nids.end();
...@@ -18,13 +30,22 @@ std::list<std::list<route_point_t> > get_routes( ...@@ -18,13 +30,22 @@ std::list<std::list<route_point_t> > get_routes(
nids_it_next++; nids_it_next++;
if(nids_it_next!=nids.end()) if(nids_it_next!=nids.end())
{ {
ret.push_back( if(state_status_on_stderr)
fprintf(stderr,"## state: routing_track %lu\n",track);
std::list<route_point_t> current_route =
get_route_between_nids( get_route_between_nids(
route_db, route_db,
parameters, parameters,
*nids_it, *nids_it,
*nids_it_next)); *nids_it_next,
state_status_on_stderr);
ret.push_back(current_route);
if(stdout_output == RV_STDOUT_OUTPUT_TEXT)
write_to_stdout(route_db, track, current_route);
} }
track++;
} }
return(ret); return(ret);
} }
...@@ -34,7 +55,8 @@ std::list<route_point_t> get_route_between_nids( ...@@ -34,7 +55,8 @@ std::list<route_point_t> get_route_between_nids(
route_db_t* route_db, route_db_t* route_db,
parameters_t & parameters, parameters_t & parameters,
nid_t & nid_initial, nid_t & nid_initial,
nid_t & nid_final) nid_t & nid_final,
bool state_status_on_stderr)
{ {
std::priority_queue<edge_in_queue_t> queue; // This is the ordoned queue used to explore std::priority_queue<edge_in_queue_t> queue; // This is the ordoned queue used to explore
edge_map_t edges_map; edge_map_t edges_map;
...@@ -43,6 +65,13 @@ std::list<route_point_t> get_route_between_nids( ...@@ -43,6 +65,13 @@ std::list<route_point_t> get_route_between_nids(
// first we add edge starting from the initial node in the queue // first we add edge starting from the initial node in the queue
node_info_t* initial_node = route_db->get_node(nid_initial); node_info_t* initial_node = route_db->get_node(nid_initial);
node_info_t* final_node = route_db->get_node(nid_final); node_info_t* final_node = route_db->get_node(nid_final);
double total_flight_distance = rv_distance(
initial_node->fixed->lon,
initial_node->fixed->lat,
final_node->fixed->lon,
final_node->fixed->lat);
unsigned int last_printed_status = 0;
edge_t null_edge; edge_t null_edge;
null_edge.A = 0; null_edge.A = 0;
...@@ -57,6 +86,7 @@ std::list<route_point_t> get_route_between_nids( ...@@ -57,6 +86,7 @@ std::list<route_point_t> get_route_between_nids(
status.velocity=0; status.velocity=0;
status.energy=0; status.energy=0;
status.time=0; status.time=0;
status.distance=0;
status.power=0; status.power=0;
status.walk=false; status.walk=false;
status.from_edge=null_edge; status.from_edge=null_edge;
...@@ -90,6 +120,23 @@ std::list<route_point_t> get_route_between_nids( ...@@ -90,6 +120,23 @@ std::list<route_point_t> get_route_between_nids(
node_info_t* A_node = route_db->get_node(running_edge_in_queue.edge.A); node_info_t* A_node = route_db->get_node(running_edge_in_queue.edge.A);
node_info_t* B_node = route_db->get_node(running_edge_in_queue.edge.B); node_info_t* B_node = route_db->get_node(running_edge_in_queue.edge.B);
if(state_status_on_stderr)
{
double flight_distance = rv_distance(
final_node->fixed->lon,
final_node->fixed->lat,
B_node->fixed->lon,
B_node->fixed->lat);
double status = 1 - flight_distance / total_flight_distance;
status = status*status;
if( (unsigned int)(status*RV_STATUS_SCALE) > last_printed_status)
{
last_printed_status = (unsigned int)(status*RV_STATUS_SCALE);
fprintf(stderr,"## status: %lu\n",last_printed_status);
}
}
if(running_edge_in_queue.edge.B == nid_final) // We are near the end if(running_edge_in_queue.edge.B == nid_final) // We are near the end
{ {
......
...@@ -4,17 +4,22 @@ ...@@ -4,17 +4,22 @@
#include "conf.h" #include "conf.h"
#include "route_db.h" #include "route_db.h"
#include "types.h" #include "types.h"
#include "write_to_stdout.h"
#include <queue> #include <queue>
std::list<route_point_t> get_route_between_nids( std::list<route_point_t> get_route_between_nids(
route_db_t* route_db, route_db_t* route_db,
parameters_t & parameters, parameters_t & parameters,
nid_t & nid_from, nid_t & nid_from,
nid_t & nid_to); nid_t & nid_to,
bool state_status_on_stderr = false);
std::list<std::list<route_point_t> > get_routes( std::list<std::list<route_point_t> > get_routes(
route_db_t* route_db, route_db_t* route_db,
parameters_t & parameters, parameters_t & parameters,
std::list< std::pair<double,double> > & geos); std::list< std::pair<double,double> > & geos,
stdout_output_t stdout_output = RV_STDOUT_OUTPUT_NONE,
bool state_status_on_stderr = false);
#endif #endif
#include "get_route.h"
#include "read_from_stdin.h"
int main(int argc, char** argv)
{
if(argc<2)
abort();
route_db_t route_db(argv[1]);
parameters_t parameters = read_parameters_from_stdin();
std::list<std::pair<double,double>> geos = read_points_from_stdin();
get_routes(&route_db, parameters, geos, RV_STDOUT_OUTPUT_TEXT, true);
return(0);
}
#include "read_from_stdin.h"
parameters_t read_parameters_from_stdin()
{
parameters_t parameters;
// default values
parameters.mass = 90;
parameters.power = 140;
parameters.SCx = .45;
parameters.Cr = .008;
parameters.velocity_nopower = 9.7;
parameters.velocity_brake = 13.9;
parameters.velocity_equilibrium = 1.4;
parameters.criterion = RV_CRITERION_ENERGY;
parameters.power_walk = 140;
parameters.lateral_acceleration = .5;
parameters.walk_penalty = 1;
parameters.Cw = .03;
std::string line;
while(true)
{
std::getline(std::cin, line);
unsigned int k = line.find(' ');
std::string key = line.substr(0,k);
std::string val = line.substr(k+1,std::string::npos);
if(key == "mass")
parameters.mass = atof(val.c_str());
else if(key == "power")
parameters.power = atof(val.c_str());
else if(key == "SCx")
parameters.SCx = atof(val.c_str());
else if(key == "Cr")
parameters.Cr = atof(val.c_str());
else if(key == "velocity_nopower")
parameters.velocity_nopower = atof(val.c_str());
else if(key == "velocity_brake")
parameters.velocity_brake = atof(val.c_str());
else if(key == "velocity_equilibrium")
parameters.velocity_equilibrium = atof(val.c_str());
else if(key == "power_walk")
parameters.power_walk = atof(val.c_str());
else if(key == "lateral_acceleration")
parameters.lateral_acceleration = atof(val.c_str());
else if(key == "walk_penalty")
parameters.walk_penalty = atof(val.c_str());
else if(key == "Cw")
parameters.Cw = atof(val.c_str());
else if(key == "criterion")
{
if(val == "energy")
parameters.criterion = RV_CRITERION_ENERGY;
else if(val == "energy_d")
parameters.criterion = RV_CRITERION_ENERGY_D;
else if(val == "time")
parameters.criterion = RV_CRITERION_TIME;
else if(val == "time_d")
parameters.criterion = RV_CRITERION_TIME_D;
else if(val == "distance")
parameters.criterion = RV_CRITERION_DISTANCE;
else
{
fprintf(stderr,"Unknown criterion [%s]\n",val.c_str());
abort();
}
}
else if(key == "points")
break;
else
{
fprintf(stderr,"Unknown parameter [%s]\n",key.c_str());
abort();
}
}
return parameters;
}
std::list<std::pair<double,double>> read_points_from_stdin()
{
std::list<std::pair<double,double>> points;
std::string line;
while(true)
{
std::getline(std::cin, line);
unsigned int k = line.find(' ');
std::string v1 = line.substr(0,k);
std::string v2 = line.substr(k+1,std::string::npos);
if(v1 == "route")
break;
points.push_back(
std::pair<double,double>(
atof(v1.c_str()),<