| | 1 | | using System; |
| | 2 | | using Itinero.Routes.Paths; |
| | 3 | | using Itinero.Routing.Costs; |
| | 4 | | using Itinero.Snapping; |
| | 5 | |
|
| | 6 | | namespace Itinero.Routing.Flavours.Dijkstra.Bidirectional; |
| | 7 | |
|
| | 8 | | internal static class DijkstraAlgorithmExtensions |
| | 9 | | { |
| | 10 | | public static void Push(this DijkstraAlgorithm dijkstraAlgorithm, ICostFunction costFunction, SnapPoint snapPoint, |
| | 11 | | bool asOrigin) |
| 18 | 12 | | { |
| 18 | 13 | | var enumerator = dijkstraAlgorithm.RoutingNetwork.GetEdgeEnumerator(); |
| 18 | 14 | | var costEnumerator = new CostEdgeEnumerator(enumerator, costFunction); |
| | 15 | |
|
| 18 | 16 | | if (asOrigin) |
| 9 | 17 | | { |
| 9 | 18 | | var (cost, _) = costEnumerator.MoveToAndGetCost(snapPoint.EdgeId, true, true, []); |
| 18 | 19 | | if (cost > 0) dijkstraAlgorithm.Push(snapPoint.EdgeId, true, cost * (1 - snapPoint.OffsetFactor())); |
| | 20 | |
|
| 9 | 21 | | (cost, _) = costEnumerator.MoveToAndGetCost(snapPoint.EdgeId, false, true, []); |
| 18 | 22 | | if (cost > 0) dijkstraAlgorithm.Push(snapPoint.EdgeId, false, cost * snapPoint.OffsetFactor()); |
| 9 | 23 | | } |
| | 24 | | else |
| 9 | 25 | | { |
| 9 | 26 | | var (cost, _) = costEnumerator.MoveToAndGetCost(snapPoint.EdgeId, true, false, []); |
| 18 | 27 | | if (cost > 0) dijkstraAlgorithm.Push(snapPoint.EdgeId, true, cost * (1 - snapPoint.OffsetFactor())); |
| | 28 | |
|
| 9 | 29 | | (cost, _) = costEnumerator.MoveToAndGetCost(snapPoint.EdgeId, false, false, []); |
| 18 | 30 | | if (cost > 0) dijkstraAlgorithm.Push(snapPoint.EdgeId, false, cost * snapPoint.OffsetFactor()); |
| 9 | 31 | | } |
| 18 | 32 | | } |
| | 33 | |
|
| | 34 | | public static Path GetPathToVisit(this DijkstraAlgorithm dijkstraAlgorithm, uint p) |
| 4 | 35 | | { |
| 4 | 36 | | var path = new Path(dijkstraAlgorithm.RoutingNetwork); |
| 4 | 37 | | var visit = dijkstraAlgorithm.GetVisit(p); |
| | 38 | |
|
| 4 | 39 | | while (true) |
| 4 | 40 | | { |
| 4 | 41 | | if (visit.previousPointer == uint.MaxValue) |
| 4 | 42 | | { |
| 4 | 43 | | path.Prepend(visit.edge, visit.forward); |
| 4 | 44 | | break; |
| | 45 | | } |
| | 46 | |
|
| 0 | 47 | | path.Prepend(visit.edge, visit.forward); |
| 0 | 48 | | visit = dijkstraAlgorithm.GetVisit(visit.previousPointer); |
| 0 | 49 | | } |
| | 50 | |
|
| 4 | 51 | | return path; |
| 4 | 52 | | } |
| | 53 | | } |