public void CheckGraphBuilderExceptionUsingARepeatedGeometry() { GraphBuilder builder = new GraphBuilder(); Assert.IsTrue(builder.Add(a)); Assert.IsFalse(builder.Add(a)); builder.PrepareAlgorithm(); }
public void CheckGraphBuilderExceptionUsingDifferentFactories() { GraphBuilder builder = new GraphBuilder(); Assert.IsTrue(builder.Add(a)); Assert.IsTrue(builder.Add(b, c)); Assert.IsTrue(builder.Add(d)); builder.Add(GeometryFactory.Default.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(50, 50), })); }
public void BuildGraphAndSearchShortestPathUsingGraphBuilder() { // Build algorithm GraphBuilder builder = new GraphBuilder(); builder.Add(a); builder.Add(b, c); builder.Add(d); DijkstraShortestPathAlgorithm <IPoint, IEdge <IPoint> > algorithm = builder.PrepareAlgorithm(); // Attach a distance observer to give us the shortest path distances VertexDistanceRecorderObserver <IPoint, IEdge <IPoint> > distObserver = new VertexDistanceRecorderObserver <IPoint, IEdge <IPoint> >(); distObserver.Attach(algorithm); // Attach a Vertex Predecessor Recorder Observer to give us the paths VertexPredecessorRecorderObserver <IPoint, IEdge <IPoint> > predecessorObserver = new VertexPredecessorRecorderObserver <IPoint, IEdge <IPoint> >(); predecessorObserver.Attach(algorithm); // Run algorithm algorithm.Compute(start); // Check results int distance = distObserver.Distances[end]; Assert.AreEqual(2, distance); IDictionary <IPoint, IEdge <IPoint> > predecessors = predecessorObserver.VertexPredecessors; for (int i = 0; i < distance; i++) { IEdge <IPoint> edge = predecessors[end]; if (i == 0) { Assert.AreEqual(d.GetPointN(d.NumPoints - 2), edge.Source); Assert.AreEqual(d.EndPoint, edge.Target); } else if (i == 1) { Assert.AreEqual(a.StartPoint, edge.Source); Assert.AreEqual(d.GetPointN(d.NumPoints - 2), edge.Target); } end = edge.Source; } // Detach the observers distObserver.Detach(algorithm); predecessorObserver.Detach(algorithm); }
public void BuildGraphAndSearchShortestPathUsingGraphBuilder() { // Build algorithm GraphBuilder builder = new GraphBuilder(); builder.Add(a); builder.Add(b, c); builder.Add(d); DijkstraShortestPathAlgorithm<IPoint, IEdge<IPoint>> algorithm = builder.PrepareAlgorithm(); // Attach a distance observer to give us the shortest path distances VertexDistanceRecorderObserver<IPoint, IEdge<IPoint>> distObserver = new VertexDistanceRecorderObserver<IPoint, IEdge<IPoint>>(); distObserver.Attach(algorithm); // Attach a Vertex Predecessor Recorder Observer to give us the paths VertexPredecessorRecorderObserver<IPoint, IEdge<IPoint>> predecessorObserver = new VertexPredecessorRecorderObserver<IPoint, IEdge<IPoint>>(); predecessorObserver.Attach(algorithm); // Run algorithm algorithm.Compute(start); // Check results int distance = distObserver.Distances[end]; Assert.AreEqual(2, distance); IDictionary<IPoint, IEdge<IPoint>> predecessors = predecessorObserver.VertexPredecessors; for (int i = 0; i < distance; i++) { IEdge<IPoint> edge = predecessors[end]; if (i == 0) { Assert.AreEqual(d.GetPointN(d.NumPoints - 2), edge.Source); Assert.AreEqual(d.EndPoint, edge.Target); } else if (i == 1) { Assert.AreEqual(a.StartPoint, edge.Source); Assert.AreEqual(d.GetPointN(d.NumPoints - 2), edge.Target); } end = edge.Source; } // Detach the observers distObserver.Detach(algorithm); predecessorObserver.Detach(algorithm); }
public void CheckGraphBuilderExceptionUsingDifferentFactories() { GraphBuilder builder = new GraphBuilder(); Assert.IsTrue(builder.Add(a)); Assert.IsTrue(builder.Add(b, c)); Assert.IsTrue(builder.Add(d)); builder.Add(GeometryFactory.Default.CreateLineString(new ICoordinate[] { new Coordinate(0 ,0), new Coordinate(50 , 50), })); }
public void CheckGraphBuilderExceptionUsingARepeatedGeometry() { GraphBuilder builder = new GraphBuilder(); Assert.IsTrue(builder.Add(a)); Assert.IsFalse(builder.Add(a)); builder.PrepareAlgorithm(); }