The problem

I am using osm2po's TspDefaultMatrix to create a cost (time) matrix:

new TspDefaultMatrix(graph, vertexIds, maxCost, Log.stdout(Log.LEVEL_LOG), properties)

Where properties contains:

findShortestPath: false
ignoreRestrictions: false
ignoreOneWays: false
heuristicFactor: 1.0

I tried many value for maxCost (0, 1, 2, Float.MAX_VALUE). Except for maxCost = 0, I always get this in the log:

DEBUG  Heuristic MaxCost set to 0.2134047

followed by some:

WARN   Matrix [8][9] unreachable!
WARN   Matrix [8][3] unreachable!

because, indeed, some of the vertexId are more than 0.2134047 hours appart.

The question

I want to know how this value (0.2134047) is calculated and how I can effectively tell TspDefaultMatrix to use my maxCost.

By the ways, I did not found (was not searching a lot) the osm2po source code. Is it available ? I would have been able to answer my question myself.


By the way, I was using version 4.8.8 of osm2po to build the .gph file and at runtime.

1 Answer 1


The parameter maxCost refers to one path of many. It does not denote the entire TSP-Route. osm2po uses some kind of heuristic here, assuming that after some full traverserls the longest path between two arbitrary points is found. This parameter is (sorry for that - I've forgotten) not published. The default value is set to 3. Meaning that after the third full traversel, the maxCost will be limited to the longest path found so far. The reason why I use this heuristic is simple: Assume you are going to calculate a matrix for a very short distance on a very large country/continent. If there is sth. wrong with the input parameters (unreachable vertices, e.g.) the algo would try to find a solution on the entire graph instead of a limited region. Here is the parameter you can play with:

int fullSearchLoops = Integer.parseInt(
  params.getProperty("matrix.fullSearchLoops", "3"));

Increasing this to e.g. 10 should eliminate your warnings.

  • Wow, thank you for your very fast answer! I just tried it. When I set matrix.fullSearchLoops = 10, it works like a charms, without even any impact on the performances. And btw, thank you for this great, fast, usefull and clean tool you made. Feb 5, 2014 at 20:33
  • And what about the project sources; are they available ? Is there any concern regarding the usage of this project in a commercial application ? Feb 5, 2014 at 20:36
  • one very important question: do you get different results now?
    – Carsten
    Feb 5, 2014 at 20:36
  • It's closed source (freeware) but you can use it for commercial applications.
    – Carsten
    Feb 5, 2014 at 20:41
  • The two results are exactly the same (with matrix.fullSearchLoops equals to 3 and 10). Except, obviously, for those places in the matrix where I previously had some NaN due to the unreachable vertex pairs, now I have a good value. Can you tell me if there is a rule (like nbVertices / 2 or something) I can follow when choosing a number to put in the matrix.fullSearchLoops property ? Feb 5, 2014 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.