public void TestOneHopTwoEdges() { var weightHandler = new DefaultWeightHandler(null); var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, weightHandler.MetaSize); graph.AddEdge(0, 1, 100, true, Constants.NO_VERTEX); graph.AddEdge(0, 2, 200, true, Constants.NO_VERTEX); var dykstra = new Itinero.Algorithms.Contracted.Dual.Dykstra <float>(graph, weightHandler, 0, false, float.MaxValue); dykstra.WasFound += (p, v, w) => { if (v == 0) { Assert.AreEqual(0, w); } else if (v == 1) { Assert.AreEqual(100, w); } else if (v == 2) { Assert.AreEqual(200, w); } return(false); }; dykstra.Run(); Assert.AreEqual(true, dykstra.HasRun); Assert.AreEqual(true, dykstra.HasSucceeded); }
public void TestTwoEdgeOneHop() { var weightHandler = new DefaultWeightHandler(null); var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, weightHandler.MetaSize); graph.AddEdge(0, 1, 100, true, Constants.NO_VERTEX); graph.AddEdge(0, 2, 200, true, Constants.NO_VERTEX); var bidirectionalDykstra = new Itinero.Algorithms.Contracted.Dual.BidirectionalDykstra <float>(graph, weightHandler, 0, 1); bidirectionalDykstra.Run(); Assert.AreEqual(true, bidirectionalDykstra.HasRun); Assert.AreEqual(true, bidirectionalDykstra.HasSucceeded); EdgePath <float> path; if (bidirectionalDykstra.TryGetForwardVisit(0, out path)) { Assert.AreEqual(0, path.Vertex); Assert.AreEqual(0, path.Weight); Assert.AreEqual(null, path.From); } if (bidirectionalDykstra.TryGetForwardVisit(1, out path)) { Assert.AreEqual(1, path.Vertex); Assert.AreEqual(100, path.Weight); Assert.IsNotNull(path.From); Assert.AreEqual(0, path.From.Vertex); } if (bidirectionalDykstra.TryGetForwardVisit(2, out path)) { Assert.AreEqual(2, path.Vertex); Assert.AreEqual(200, path.Weight); Assert.IsNotNull(path.From); Assert.AreEqual(0, path.From.Vertex); } if (bidirectionalDykstra.TryGetBackwardVisit(1, out path)) { Assert.AreEqual(1, path.Vertex); Assert.AreEqual(0, path.Weight); Assert.AreEqual(null, path.From); } if (bidirectionalDykstra.TryGetBackwardVisit(0, out path)) { Assert.AreEqual(0, path.Vertex); Assert.AreEqual(100, path.Weight); Assert.IsNotNull(path.From); Assert.AreEqual(1, path.From.Vertex); } }
/// <summary> /// Checks if the given point is connected to the rest of the network. Use this to detect points on routing islands. /// </summary> /// <param name="radiusInMeter">The radius metric, that's always a distance in meters.</param> /// <returns></returns> public sealed override Result <bool> TryCheckConnectivity(IProfileInstance profileInstance, RouterPoint point, float radiusInMeter, bool?forward = null) { try { if (!_db.Supports(profileInstance.Profile)) { return(new Result <bool>("Routing profile is not supported.", (message) => { return new Exception(message); })); } // get the weight handler. var getGetFactor = this.GetDefaultGetFactor(profileInstance); Func <ushort, Factor> getShortestFactor = (p) => { // only keep directional information, get factor to 1 for distance metrics only. var factor = getGetFactor(p); if (factor.Value == 0) { return(new Factor() { Direction = factor.Direction, Value = 0 }); } return(new Factor() { Direction = factor.Direction, Value = 1 }); }; var weightHandler = new DefaultWeightHandler(getShortestFactor); var checkForward = forward == null || forward.Value; var checkBackward = forward == null || !forward.Value; if (checkForward) { // build and run forward dykstra search. var dykstra = new Algorithms.Default.EdgeBased.Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, _db.GetGetRestrictions(profileInstance.Profile, true), point.ToEdgePaths(_db, weightHandler, true), radiusInMeter, false); dykstra.Run(); if (!dykstra.HasSucceeded || !dykstra.MaxReached) { // something went wrong or max not reached. return(new Result <bool>(false)); } } if (checkBackward) { // build and run backward dykstra search. var dykstra = new Algorithms.Default.EdgeBased.Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, _db.GetGetRestrictions(profileInstance.Profile, false), point.ToEdgePaths(_db, weightHandler, false), radiusInMeter, true); dykstra.Run(); if (!dykstra.HasSucceeded || !dykstra.MaxReached) { // something went wrong or max not reached. return(new Result <bool>(false)); } } return(new Result <bool>(true)); } catch (Exception ex) { return(new Result <bool>(ex.Message, (m) => ex)); } }