I am interested in calculating routes based on the weights of links for traffic simulation using MATSim API. Every link has an attribute of safety index and the calculated route should represent the safest path. The Dijkstra routing algorithm calculates shortest path. It is perfect to use it, if only I can specify that the algorithm should consider safety index instead of length. I don't know if it is possible to do it in MATSim and how. Or maybe other routing algorithms implemented in MATSim can suit better.
Thanks!
This should be possible be implementing your own TravelDisutility-Class. Have a look at the interface org.matsim.core.router.util.TravelDisutility
. An implementation looking only at free speeds can be found in org.matsim.core.router.costcalculators.FreespeedTravelTimeAndDisutility
. You might start with this and adapt it such that getLinkTravelDisutility()
will return a value not based on the speed, but on your savety index. Note that values must be larger than 0
, and small values (i.e. close to 0) are preferred over larger values.
I don't know how you calculate your safety index, but you should normalize it somehow by the length of the link. Otherwise, one long link could be preferred over a series of short links, even though they could all have the same safety value.
Once you have your implementation, you can bind it using Guice. An example for this could be found in the class org.matsim.run.InitRoutes
. Then it should be used for the routing in MATSim.