public void TestThreeEdges() { var graph = new RoutingNetwork(new Itinero.Graphs.Geometric.GeometricGraph(1, 2)); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 2, 2); graph.AddEdge(0, 1, new EdgeData() { Profile = 2 }, null); graph.AddEdge(0, 2, new EdgeData() { Profile = 1 }, null); graph.AddEdge(2, 1, new EdgeData() { Profile = 1 }, null); // execute algorithm. var algorithm = new NetworkOptimizer(graph, MergeDelegate); algorithm.Run(); // check result. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(2, edges.First(x => x.To == 1).Data.Profile); Assert.AreEqual(1, edges.First(x => x.To == 2).Data.Profile); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(2, edges.First(x => x.To == 0).Data.Profile); Assert.AreEqual(1, edges.First(x => x.To == 2).Data.Profile); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(1, edges.First(x => x.To == 0).Data.Profile); Assert.AreEqual(1, edges.First(x => x.To == 1).Data.Profile); }
public void TestTwoIdenticalEdges() { // create graph with one vertex and start adding 2. var graph = new RoutingNetwork(new Itinero.Graphs.Geometric.GeometricGraph(1, 2)); // make sure to add 1 and 2. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 2, 2); graph.AddEdge(0, 1, new EdgeData() { Profile = 1, MetaId = 1, Distance = 10 }, null); graph.AddEdge(1, 2, new EdgeData() { Profile = 1, MetaId = 1, Distance = 20 }, null); // execute algorithm. var algorithm = new NetworkOptimizer(graph, MergeDelegate); algorithm.Run(); // check result. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().Data.Profile); Assert.AreEqual(1, edges.First().Data.MetaId); Assert.AreEqual(30, edges.First().Data.Distance); var shape = edges.Shape; Assert.IsNotNull(shape); Assert.AreEqual(1, shape.Count); Assert.AreEqual(1, shape.First().Latitude); Assert.AreEqual(1, shape.First().Longitude); }
public void TestTwoIdenticalEdgesWithShapes() { var graph = new RoutingNetwork(new Itinero.Graphs.Geometric.GeometricGraph(1, 2)); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 2, 2); graph.AddEdge(0, 1, new EdgeData() { Profile = 1 }, new Coordinate(0.5f, 0.5f)); graph.AddEdge(1, 2, new EdgeData() { Profile = 1 }, new Coordinate(1.5f, 1.5f)); // execute algorithm. var algorithm = new NetworkOptimizer(graph, MergeDelegate); algorithm.Run(); // check result. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().Data.Profile); var shape = new List <Coordinate>(edges.Shape); Assert.AreEqual(3, shape.Count); Assert.AreEqual(0.5, shape[0].Latitude); Assert.AreEqual(0.5, shape[0].Longitude); Assert.AreEqual(1, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(1.5, shape[2].Latitude); Assert.AreEqual(1.5, shape[2].Longitude); graph = new RoutingNetwork(new Itinero.Graphs.Geometric.GeometricGraph(1, 2)); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 2, 2); graph.AddEdge(1, 0, new EdgeData() { Profile = 1 }, new Coordinate(0.5f, 0.5f)); graph.AddEdge(1, 2, new EdgeData() { Profile = 1 }, new Coordinate(1.5f, 1.5f)); // execute algorithm. algorithm = new NetworkOptimizer(graph, MergeDelegate); algorithm.Run(); // check result. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().Data.Profile); shape = new List <Coordinate>(edges.Shape); Assert.AreEqual(3, shape.Count); Assert.AreEqual(0.5, shape[0].Latitude); Assert.AreEqual(0.5, shape[0].Longitude); Assert.AreEqual(1, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(1.5, shape[2].Latitude); Assert.AreEqual(1.5, shape[2].Longitude); graph = new RoutingNetwork(new Itinero.Graphs.Geometric.GeometricGraph(1, 2)); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 2, 2); graph.AddEdge(1, 0, new EdgeData() { Profile = 1 }, new Coordinate(0.5f, 0.5f)); graph.AddEdge(2, 1, new EdgeData() { Profile = 1 }, new Coordinate(1.5f, 1.5f)); // execute algorithm. algorithm = new NetworkOptimizer(graph, MergeDelegate); algorithm.Run(); // check result. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().Data.Profile); Assert.AreEqual(true, edges.First().DataInverted); shape = new List <Coordinate>(edges.Shape); Assert.AreEqual(3, shape.Count); Assert.AreEqual(1.5, shape[0].Latitude); Assert.AreEqual(1.5, shape[0].Longitude); Assert.AreEqual(1, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(0.5, shape[2].Latitude); Assert.AreEqual(0.5, shape[2].Longitude); }