0
$\begingroup$

Here’s what I’m working on: I want to build routes that maximize my custom metrics. I don’t want to share the exact details of these metrics, but for every candidate route I calculate N metrics and I’m looking for the route that performs best across all of them.

Under the hood, I use routing engines (Valhalla / GraphHopper / OSRM) on top of OpenStreetMap to build actual paths from A to B. However, it seems too complex to integrate my metrics directly into the routing engine (it would require rewriting a lot of core logic).

So instead, I built a solution using a graph from OSM + Simulated Annealing + routing:

  • I start with a random initial route and ask the routing engine to construct a valid path.

  • Then I run N iterations of Simulated Annealing, with two mutation types:

    • Mutation 1: Choose a random sub-route (up to 50% of the route at first), find its midpoint, create a perpendicular, and select a nearby vertex in the graph as a detour point. Then remove the sub-route and reconnect using the routing engine through that detour. Conceptually: “Let’s try this road instead of the current one.” Usually this makes the route longer (which can be fine if metrics improve).
    • Mutation 2: Choose a random sub-route, remove it entirely, and reconnect its start and end directly with the routing engine. Conceptually: “Let’s skip this part and just connect the ends.” Usually this shortens the route.

As in standard Simulated Annealing, after each mutation I recalculate metrics and decide whether to accept the change. I repeat this many times, restarting the process as needed.

This kind of works, but the results are poor because most mutations are useless. They tend to make random, odd changes and lead to weird routes.

When I look at examples online (like Simulated Annealing for TSP), mutations are simple: e.g. swap two random vertices. That works because in TSP the graph is fully connected. But in my case, I’m using a real road network graph, so I can’t just “swap nodes” — I need meaningful mutations.

For example: if a route goes from A to B along road C, and there’s a parallel road D, I’d like the mutation to try “use D instead of C.” Right now my approach (random sub-route → random perpendicular → random vertex nearby) is too random and inefficient, giving poor results.

My question: How can I design more effective mutations for this kind of real-road routing problem?

$\endgroup$
4
  • $\begingroup$ Welcome! Your problem looks interesting, but what is the specific input and output you are working with? I am assuming it is some kind of weighted/labeled graph? $\endgroup$ Commented Aug 25 at 21:36
  • $\begingroup$ @CalebStanford The input is a fraph from OSM (I have it on my side) and I have routing-engine with the same graph - because it resolves many issues like "access=no" on OSM, so I need routing engige under the hood. Yes I kind of have different weighted edges (but only on my side, not in routing) which I calculate and try to choose the best one. $\endgroup$ Commented Aug 26 at 6:20
  • $\begingroup$ @njuffa Yes it would work if you are looking for shortest path, in my case I want to find a route that benefits all metrics - shortest distance is not one of them. $\endgroup$ Commented Aug 26 at 6:21
  • $\begingroup$ @njuffa for now problem is not initial state, but mutations (improving current solution). If I turn off mutations completely (0 iterations) and just random initial state - it works almost the same, as with mutation, lol. It shouldn't be like that. It shows that my mutations almost uselss (and it's true) because 99% of the time I do some weird useless stuff. So again as a asked in initial question - I am wondering how can I do these mutations "smarter" than just random sub-route and random detour vertex. $\endgroup$ Commented Aug 26 at 14:27

1 Answer 1

1
$\begingroup$

You said "I’m looking for the route that performs best across all of them" Could your custom metrics be somehow combined into one goal functions with help of weights, sum of squares, etc.? Simulated Annealing is a method of global optimization of goal function, so better to represent your problem as a classic goal function optimization (at least virtually). At this moment I am not fully sure that Simulated Annealing is a method of choice for your problem.

$\endgroup$
1
  • $\begingroup$ Yes I have a function which combines all my metrics, so as a result I just have a number (int) which represents the score of the route. So I am looking for a route that maximizes this score. $\endgroup$ Commented Aug 26 at 20:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.