I need to create an implementation of a directed weighted multigraph with dynamic edges:
The edges will be changing during the pathfinding, in the following way:
Summary of the pathfinding:
- Pathfinding starts at S.
- S -> V1 (through edge with weight 3)
- V1 -> V2 (through edge with weight 7, as edge with weight 3 is not available for this path).
- V2 -> V4 is not possible, so we go back for another iteration.
- S -> V1 (through edge with weight 3)
- V1 -> V3 (through edge with weight 8)
- V3 -> V4 (through edge with weight 3)
- V4 -> E (through edge with weight 6)
Of course, this is a simplification of the process, but to provide a general idea of how the edges would change, according to current path - let us take for example, that if S -> V1 was made via the edge with weight 5, then V1 -> V2 will be possible via both paths. As a conclusion, the available edges for each next vertex in the pathfinding depend on characteristics of the last edge that has been selected.
A real world example that represents this problem could be the following:
We want to use public transportation to reach from the City of Turin (Italy), to the City of Palermo (Italy).
There are several paths with several available transportation services between them. Let us take a look at the path Turin (Italy) -> Naples (Italy) -> Palermo (Italy).
The following trains are available for the path Turin -> Naples:
- Turin -> Naples (departs at 13:00 and arrives at 19:00)
- Turin -> Naples (departs at 15:00 and arrives at 21:00)
Also, the following boats are available for the path Naples -> Palermo:
- Naples -> Palermo (departs at 18:00 and arrives at 01:00 on the next day)
- Naples -> Palermo (departs at 20:00 and arrives at 04:00 on the next day)
So, despite we have multiple edges between the vertices Turin -> Naples and Naples -> Palermo, we only have one available travel option, and it is Turin -> Naples (departs at 13:00) + Naples -> Palermo (departs at 20:00).
My questions are:
- Is the best way to represent this problem as a directed weighted multigraph (what I have chosen as of this point) - vertices being the cities, edges being the transportation options, weight being the time of transportation (time of arrival - time of departure)?
- What would be the most efficient way of finding the shortest path of such a graph with dynamically changing edges (no new edges will be added to the graph during traversal, only the existing ones will be turned ON & OFF, depending on the path chosen prior them)?