Question about the operator "path_between"

82 views
Skip to first unread message

Thomas Elskens

unread,
Mar 8, 2014, 11:14:30 AM3/8/14
to gama-p...@googlegroups.com


Hello,

I would have a little question about the use of the operator "path_between". I'm trying to use it in a function who calculates the traveltime between two agents, as follows :

int compute_traveltime(agent departure, agent arrival)
{
int result <- 0 ;
write "Début du calcul de path chemin" ;
path chemin <- (le_graphe path_between(departure::arrival)) ;
write "Début de l'initialisation de segments" ;
list<geometry> segments <- chemin.segments ;
loop line over: segments
{
float distance <- line.perimeter ;
float speed <- (road(chemin agent_from_geometry line)).max_speed ;
result <- result + round(speed / distance) ;
}
return result ;
}

Result of this function : the simulation "hangs" : I get no error-message or something, the simulation just does not go further (in the console I get only "Début du calcul de path chemin", never the following debugging message). This is a bit annoying, as I had big expectations about this operator to greatly simplify a genetic algorithm to solve a variant of the sales-man tour. 

In issue 248 I read that in order to make the operator "path_between" work, roads-segments should be split (and not be composed out of long lines), but my road_shapefile contains 22880 road-segments, thus this cannot be the cause. 

In attachment, you can find the model (a reduced version of it, for debugging purposes) and the configuration details of GAMA. 

I would be very grateful if someone could help me on this issue,

Thomas Elskens
PULSE.zip
Configuration_GAMA.txt

Patrick Taillandier

unread,
Mar 8, 2014, 1:55:10 PM3/8/14
to gama-p...@googlegroups.com
Hi,

Well done, you found a spelling error in GAMA ;) : Dijkstra (and not Djikstra). It will be corrected in GAMA 1.6.1. Thus, instead of using the Dijkstra algo, GAMA was using the Floyd Warshall one that computes all pairs of shortest paths (requires a lot of memory for big graphs like yours).

Thus, for the moment, you just have to replace the line 97:

set le_graphe <- (as_edge_graph(list(road))) with_optimizer_type "Dijkstra";

by:

set le_graphe <- (as_edge_graph(list(road))) ;


By default, the algorithm used to computed the shortest paths is Dijkstra

Cheers,

Patrick 


--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Thomas Elskens

unread,
Mar 9, 2014, 8:55:22 AM3/9/14
to gama-p...@googlegroups.com

Thanks a lot, now the simulation already goes a bit further !

Thomas Elskens

unread,
Mar 9, 2014, 10:11:58 AM3/9/14
to gama-p...@googlegroups.com

Unfortunately I've been a bit too hasty. Indeed, simulation does not hang any longer, but the result returned is simply null ? 

This surprises me, as I have taken care to localize all agents on the roadnetwork itself, as follows :

create carrier number: nb_carriers
{
point tmp <- any_location_in(one_of(arrondissements)) ;
location <- point(road closest_to tmp) ;
}
create retailer number: nb_retailers
{
point tmp <- any_location_in(one_of(quartiers));
location <- point(road closest_to tmp) ;
do extract_init_data_retailers() ;
}

Am I missing something ? My road network is perhaps simply to big and should be down-sized ? 

Thanks a lot for your help,

Thomas

P.S.

With regard to the zip-file, I've found another bug at line 312 (and 330). I expected the "self" keyword to behave as "this" in Java when passed as a parameter in a dotted functioncall :
int home_time_needed <- world.compute_traveltime(self,(currentgene.delivery_route at 0)) ;

but this was not the case and I have corrected into the following :

int home_time_needed <- 0 ;
ask world
{
       set home_time_needed <- compute_traveltime(myself,(currentgene.delivery_route at 0)) ;
}

Patrick Taillandier

unread,
Mar 10, 2014, 6:25:40 AM3/10/14
to gama-p...@googlegroups.com
Hi,

My advice: instead of choosing a location of a road, choose directly a vertex of the graph to locate your agents:

create carrier number: nb_carriers{
// to do : distance_to_city : entier préétabli ou ... ?
point tmp <- any_location_in(one_of(arrondissements)) ;
location <- point(le_graphe.vertices with_min_of (point(each) distance_to tmp));
}
create retailer number: nb_retailers{
point tmp <- any_location_in(one_of(quartiers));
location <- point(le_graphe.vertices with_min_of (point(each) distance_to tmp));
do extract_init_data_retailers() ;
}


BTW, a possible optimization is to directly give the location of your agents as departure and arrival of your shortest path computation

int compute_traveltime(agent departure, agent arrival)
{
....
path chemin <- (le_graphe path_between(departure.location::arrival.location)) ;

 
Cheers,

Patrick


--

Thomas Elskens

unread,
Mar 10, 2014, 11:12:46 AM3/10/14
to gama-p...@googlegroups.com
Now it works ! Thanks very much !

Thomas


Le samedi 8 mars 2014 17:14:30 UTC+1, Thomas Elskens a écrit :
Reply all
Reply to author
Forward
0 new messages