Exemple #1
0
 /// <summary>
 /// Converts the specified geometry collection to an existing graph instance.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="graph">The graph.</param>
 /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
 /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
 private static void ConvertToGraph(IEnumerable <IGeometry> geometry, IGeometryGraph graph, Boolean isBidirectional, Boolean preserveMetadata)
 {
     foreach (IGeometry item in geometry)
     {
         ConvertToGraph(item, graph, isBidirectional, preserveMetadata);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphEdge" /> class.
 /// </summary>
 /// <param name="source">The source vertex.</param>
 /// <param name="target">The target vertex.</param>
 /// <param name="metadata">The metadata.</param>
 public GraphEdge(IGeometryGraph graph, GraphVertex source, GraphVertex target, IDictionary <String, Object> metadata)
 {
     _graph    = graph;
     _source   = source;
     _target   = target;
     _metadata = _graph.Factory.GetFactory <IMetadataFactory>().CreateCollection(metadata);
 }
Exemple #3
0
        /// <summary>
        /// Converts the specified geometry to an existing graph instance.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="graph">The graph.</param>
        /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
        /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
        private static void ConvertToGraph(IGeometry geometry, IGeometryGraph graph, Boolean isBidirectional, Boolean preserveMetadata)
        {
            if (geometry is IPoint)
            {
                ConvertToGraph(geometry as IPoint, graph, isBidirectional, preserveMetadata);
            }
            if (geometry is ILineString)
            {
                ConvertToGraph(geometry as ILineString, graph, isBidirectional, preserveMetadata);
            }
            if (geometry is IPolygon)
            {
                ConvertToGraph(geometry as IPolygon, graph, isBidirectional, preserveMetadata);
            }
            if (geometry is IEnumerable <IGeometry> )
            {
                ConvertToGraph(geometry as IEnumerable <IGeometry>, graph, isBidirectional, preserveMetadata);
            }
            if (geometry is IGeometryGraph)
            {
                ConvertToGraph(geometry as IGeometryGraph, graph, isBidirectional, preserveMetadata);
            }

            throw new ArgumentException("geometry", "Conversion of the specified geometry is not supported.");
        }
        /// <summary>
        /// Creates a graph.
        /// </summary>
        /// <param name="other">The other geometry graph.</param>
        /// <param name="vertexEqualityComparer">The vertex comparer.</param>
        /// <param name="edgeEqualityComparer">The edge comparer.</param>
        /// <returns>A graph that matches <param name="other" /> using the specified comparers.</returns>
        public IGeometryGraph CreateGraph(IGeometryGraph other, IEqualityComparer <IGraphVertex> vertexEqualityComparer, IEqualityComparer <IGraphEdge> edgeEqualityComparer)
        {
            IGeometryGraph graph = new GeometryGraph(vertexEqualityComparer, edgeEqualityComparer, GetFactory <IGeometryFactory>(), other.Metadata);

            other.ToGraph(graph); // using the extension method

            return(graph);
        }
        /// <summary>
        /// Creates a graph.
        /// </summary>
        /// <returns>A graph that matches <param name="other" />.</returns>
        public IGeometryGraph CreateGraph(IGeometryGraph other)
        {
            IGeometryGraph graph = new GeometryGraph(other.VertexComparer, other.EdgeComparer, GetFactory <IGeometryFactory>(), other.Metadata);

            other.ToGraph(graph); // using the extension method

            return(graph);
        }
Exemple #6
0
        public void SetUp()
        {
            // source: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

            IGeometryFactory factory = new GeometryFactory();

            // source graph
            _sourceGraph = factory.CreateNetwork();

            // vertices
            IGraphVertex vertex1 = _sourceGraph.AddVertex(new Coordinate(0, 0));
            IGraphVertex vertex2 = _sourceGraph.AddVertex(new Coordinate(1, 0));
            IGraphVertex vertex3 = _sourceGraph.AddVertex(new Coordinate(1, 1));
            IGraphVertex vertex4 = _sourceGraph.AddVertex(new Coordinate(2, 1));
            IGraphVertex vertex5 = _sourceGraph.AddVertex(new Coordinate(1, 2));
            IGraphVertex vertex6 = _sourceGraph.AddVertex(new Coordinate(0, 2));

            // forward edges
            _sourceGraph.AddEdge(vertex1, vertex2, CreateWeightMetadata(7));
            _sourceGraph.AddEdge(vertex1, vertex3, CreateWeightMetadata(9));
            _sourceGraph.AddEdge(vertex1, vertex6, CreateWeightMetadata(14));
            _sourceGraph.AddEdge(vertex2, vertex3, CreateWeightMetadata(10));
            _sourceGraph.AddEdge(vertex2, vertex4, CreateWeightMetadata(15));
            _sourceGraph.AddEdge(vertex3, vertex4, CreateWeightMetadata(11));
            _sourceGraph.AddEdge(vertex3, vertex6, CreateWeightMetadata(2));
            _sourceGraph.AddEdge(vertex4, vertex5, CreateWeightMetadata(6));
            _sourceGraph.AddEdge(vertex5, vertex6, CreateWeightMetadata(9));

            // reverse edges
            _sourceGraph.AddEdge(vertex2, vertex1, CreateWeightMetadata(7));
            _sourceGraph.AddEdge(vertex3, vertex1, CreateWeightMetadata(9));
            _sourceGraph.AddEdge(vertex6, vertex1, CreateWeightMetadata(14));
            _sourceGraph.AddEdge(vertex3, vertex2, CreateWeightMetadata(10));
            _sourceGraph.AddEdge(vertex4, vertex2, CreateWeightMetadata(15));
            _sourceGraph.AddEdge(vertex4, vertex3, CreateWeightMetadata(11));
            _sourceGraph.AddEdge(vertex6, vertex3, CreateWeightMetadata(2));
            _sourceGraph.AddEdge(vertex5, vertex4, CreateWeightMetadata(6));
            _sourceGraph.AddEdge(vertex6, vertex5, CreateWeightMetadata(9));

            // source and target vertices
            _sourceVertex = vertex1;
            _targetVertex = vertex5;

            // result graph
            _resultGraph = factory.CreateNetwork();

            // vertices
            vertex1 = _resultGraph.AddVertex(new Coordinate(0, 0), CreateDistanceMetadata(0));
            vertex3 = _resultGraph.AddVertex(new Coordinate(1, 1), CreateDistanceMetadata(9));
            vertex5 = _resultGraph.AddVertex(new Coordinate(1, 2), CreateDistanceMetadata(20));
            vertex6 = _resultGraph.AddVertex(new Coordinate(0, 2), CreateDistanceMetadata(11));

            // edges
            _resultGraph.AddEdge(vertex1, vertex3);
            _resultGraph.AddEdge(vertex3, vertex6);
            _resultGraph.AddEdge(vertex6, vertex5);
        }
Exemple #7
0
 /// <summary>
 /// Converts the specified polygon to an existing graph instance.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="graph">The graph.</param>
 /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
 /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
 private static void ConvertToGraph(IPolygon geometry, IGeometryGraph graph, Boolean isBidirectional, Boolean preserveMetadata)
 {
     ConvertToGraph(geometry.Shell.Coordinates, geometry.Shell.Metadata, graph, geometry.Shell.IsRing, isBidirectional, preserveMetadata);
     if (geometry.HoleCount > 0)
     {
         foreach (ILinearRing linearRing in geometry.Holes)
         {
             ConvertToGraph(linearRing.Coordinates, linearRing.Metadata, graph, linearRing.IsRing, isBidirectional, preserveMetadata);
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Converts the specified geometry to a graph.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="isBidirectional">Indicates whether the graph should be bidirectional.</param>
        /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
        /// <returns>The equivalent graph representation of the geometry.</returns>
        /// <exception cref="System.ArgumentNullException">he geometry is null.</exception>
        public static IGeometryGraph ToGraph(this IGeometry geometry, Boolean isBidirectional, Boolean preserveMetadata)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry", "The geometry is null.");
            }

            IGeometryGraph graph = geometry.Factory.CreateGraph();

            ConvertToGraph(geometry, graph, isBidirectional, preserveMetadata);

            return(graph);
        }
Exemple #9
0
        /// <summary>
        /// Converts the specified geometry instance into an existing graph instance.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="graph">The graph.</param>
        /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
        /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The geometry is null.
        /// or
        /// The graph is null.
        /// </exception>
        public static void ToGraph(this IGeometry geometry, IGeometryGraph graph, Boolean isBidirectional, Boolean preserveMetadata)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry", "The geometry is null.");
            }
            if (graph == null)
            {
                throw new ArgumentNullException("graph", "The graph is null.");
            }

            ConvertToGraph(geometry, graph, isBidirectional, preserveMetadata);
        }
        /// <summary>
        /// Computes the transformation of the source geometry graph.
        /// </summary>
        /// <param name="source">The source geometry graph.</param>
        /// <returns>The geometry graph in the specified reference system.</returns>
        private IGeometryGraph Compute(IGeometryGraph source)
        {
            IGeometryGraph graph = _factory.CreateGraph(source.VertexComparer, source.EdgeComparer, _metadataPreservation ? source.Metadata : null);

            Dictionary <IGraphVertex, IGraphVertex> vertexMapping = new Dictionary <IGraphVertex, IGraphVertex>();

            foreach (IGraphVertex vertex in source.Vertices)
            {
                vertexMapping.Add(vertex, graph.AddVertex(Compute(vertex.Coordinate), _metadataPreservation ? vertex.Metadata : null));
            }

            foreach (IGraphVertex vertex in source.Vertices)
            {
                foreach (IGraphEdge edge in source.OutEdges(vertex))
                {
                    graph.AddEdge(vertexMapping[edge.Source], vertexMapping[edge.Target], _metadataPreservation ? edge.Metadata : null);
                }
            }

            return(graph);
        }
        public void SetUp()
        {
            IGeometryFactory factory = new GeometryFactory();

            // source graph
            _sourceGraph = factory.CreateNetwork();

            IGraphVertex vertex1 = _sourceGraph.AddVertex(new Coordinate(0, 1));
            IGraphVertex vertex2 = _sourceGraph.AddVertex(new Coordinate(1, 1));
            IGraphVertex vertex3 = _sourceGraph.AddVertex(new Coordinate(1, 0));
            IGraphVertex vertex4 = _sourceGraph.AddVertex(new Coordinate(2, 0));
            IGraphVertex vertex5 = _sourceGraph.AddVertex(new Coordinate(0, 0));

            _sourceGraph.AddEdge(vertex1, vertex2, CreateWeightMetadata(5));
            _sourceGraph.AddEdge(vertex1, vertex3, CreateWeightMetadata(8));
            _sourceGraph.AddEdge(vertex1, vertex4, CreateWeightMetadata(-4));
            _sourceGraph.AddEdge(vertex2, vertex1, CreateWeightMetadata(-2));
            _sourceGraph.AddEdge(vertex3, vertex2, CreateWeightMetadata(-3));
            _sourceGraph.AddEdge(vertex3, vertex4, CreateWeightMetadata(9));
            _sourceGraph.AddEdge(vertex4, vertex2, CreateWeightMetadata(7));
            _sourceGraph.AddEdge(vertex5, vertex1, CreateWeightMetadata(6));
            _sourceGraph.AddEdge(vertex5, vertex3, CreateWeightMetadata(7));

            // source vertex
            _sourceVertex = vertex5;

            // result graph
            _resultGraph = factory.CreateNetwork();

            vertex1 = _resultGraph.AddVertex(new Coordinate(0, 1), CreateDistanceMetadata(2));
            vertex2 = _resultGraph.AddVertex(new Coordinate(1, 1), CreateDistanceMetadata(4));
            vertex3 = _resultGraph.AddVertex(new Coordinate(1, 0), CreateDistanceMetadata(7));
            vertex4 = _resultGraph.AddVertex(new Coordinate(2, 0), CreateDistanceMetadata(-2));
            vertex5 = _resultGraph.AddVertex(new Coordinate(0, 0), CreateDistanceMetadata(0));

            _resultGraph.AddEdge(vertex5, vertex3);
            _resultGraph.AddEdge(vertex3, vertex2);
            _resultGraph.AddEdge(vertex2, vertex1);
            _resultGraph.AddEdge(vertex1, vertex4);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BellmanFordAlgorithm"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public BellmanFordAlgorithm(IGeometryGraph source, IGeometryGraph target, IDictionary <OperationParameter, Object> parameters)
     : base(source, target, GraphOperationMethods.BellmannFordAlgorithm, parameters)
 {
 }
Exemple #13
0
        /// <summary>
        /// Tests execution for multiple reference systems.
        /// </summary>
        /// <param name="metadataPreservation">Indicates whether the metadata should be preserved.</param>
        private void TestExecuteForReferenceSystems(Boolean metadataPreservation)
        {
            Coordinate     sourceCoordinate = new Coordinate(10, 10);
            IGeometryGraph sourceGraph      = new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV).CreateGraph(new Coordinate[] { sourceCoordinate });


            // projected to projected

            GeoCoordinate sourceGeoCoordinate   = ProjectedCoordinateReferenceSystems.HD72_EOV.Projection.Reverse(sourceCoordinate);
            GeoCoordinate expectedGeoCoordinate = GeographicTransformations.HD72_WGS84_V1.Forward(sourceGeoCoordinate);
            Coordinate    expectedCoordinate    = ProjectedCoordinateReferenceSystems.WGS84_WorldMercator.Projection.Forward(expectedGeoCoordinate);

            IDictionary <OperationParameter, Object> parameters = new Dictionary <OperationParameter, Object>();

            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.WGS84_WorldMercator);
            parameters.Add(CommonOperationParameters.MetadataPreservation, metadataPreservation);

            GraphReferenceTransformation transformation = new GraphReferenceTransformation(sourceGraph, parameters);

            transformation.Execute();

            IGeometryGraph resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(1, resultGraph.VertexCount);
            Assert.AreEqual(expectedCoordinate, resultGraph.Vertices[0].Coordinate);
            Assert.AreEqual(sourceGraph.Metadata, resultGraph.Metadata);


            // geographic to projected

            sourceGeoCoordinate   = new GeoCoordinate(Angle.FromDegree(45), Angle.FromDegree(45));
            expectedGeoCoordinate = GeographicTransformations.HD72_WGS84_V1.Forward(sourceGeoCoordinate);
            expectedCoordinate    = ProjectedCoordinateReferenceSystems.WGS84_WorldMercator.Projection.Forward(expectedGeoCoordinate);

            sourceCoordinate = new Coordinate(45, 45);
            sourceGraph      = new GeometryFactory(Geographic2DCoordinateReferenceSystems.HD72).CreateGraph(new Coordinate[] { sourceCoordinate });

            parameters = new Dictionary <OperationParameter, Object>();
            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.WGS84_WorldMercator);

            transformation = new GraphReferenceTransformation(sourceGraph, parameters);
            transformation.Execute();

            resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(expectedCoordinate, resultGraph.Vertices[0].Coordinate);


            // projected to geographic

            sourceCoordinate      = new Coordinate(10, 10);
            sourceGeoCoordinate   = ProjectedCoordinateReferenceSystems.HD72_EOV.Projection.Reverse(sourceCoordinate);
            expectedGeoCoordinate = GeographicTransformations.HD72_WGS84_V1.Forward(sourceGeoCoordinate);

            sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV).CreateGraph(new Coordinate[] { sourceCoordinate });

            parameters = new Dictionary <OperationParameter, Object>();
            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, Geographic2DCoordinateReferenceSystems.WGS84);

            transformation = new GraphReferenceTransformation(sourceGraph, parameters);
            transformation.Execute();

            resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(expectedGeoCoordinate.Latitude.GetValue(UnitsOfMeasurement.Degree), resultGraph.Vertices[0].Coordinate.X);
            Assert.AreEqual(expectedGeoCoordinate.Longitude.GetValue(UnitsOfMeasurement.Degree), resultGraph.Vertices[0].Coordinate.Y);


            // projected to projected (reverse)

            sourceCoordinate      = new Coordinate(10, 10);
            sourceGeoCoordinate   = ProjectedCoordinateReferenceSystems.WGS84_WorldMercator.Projection.Reverse(sourceCoordinate);
            expectedGeoCoordinate = GeographicTransformations.HD72_WGS84_V1.Reverse(sourceGeoCoordinate);
            expectedCoordinate    = ProjectedCoordinateReferenceSystems.HD72_EOV.Projection.Forward(expectedGeoCoordinate);

            sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.WGS84_WorldMercator).CreateGraph(new Coordinate[] { sourceCoordinate });

            parameters = new Dictionary <OperationParameter, Object>();
            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.HD72_EOV);

            transformation = new GraphReferenceTransformation(sourceGraph, parameters);
            transformation.Execute();

            resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(expectedCoordinate, resultGraph.Vertices[0].Coordinate);


            // same reference system

            sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.WGS84_WorldMercator).CreateGraph(new Coordinate[] { sourceCoordinate });

            parameters = new Dictionary <OperationParameter, Object>();
            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.WGS84_WorldMercator);

            transformation = new GraphReferenceTransformation(sourceGraph, parameters);
            transformation.Execute();

            resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(sourceGraph.Vertices[0].Coordinate, resultGraph.Vertices[0].Coordinate);


            // no source reference system

            sourceGraph = new GeometryFactory().CreateGraph(new Coordinate[] { sourceCoordinate });

            parameters = new Dictionary <OperationParameter, Object>();
            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.WGS84_WorldMercator);

            transformation = new GraphReferenceTransformation(sourceGraph, parameters);
            transformation.Execute();

            resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(sourceGraph.Vertices[0].Coordinate, resultGraph.Vertices[0].Coordinate);


            // no target reference system

            parameters = new Dictionary <OperationParameter, Object>();
            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, null);

            Assert.Throws <ArgumentException>(() => transformation = new GraphReferenceTransformation(sourceGraph, parameters));
        }
Exemple #14
0
        /// <summary>
        /// Tests execution for multiple graphs.
        /// </summary>
        /// <param name="metadataPreservation">Indicates whether the metadata should be preserved.</param>
        private void TestExecuteForGraphs(Boolean metadataPreservation)
        {
            // empty graph

            IGeometryGraph sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV).CreateGraph();

            IDictionary <OperationParameter, Object> parameters = new Dictionary <OperationParameter, Object>();

            parameters.Add(ReferenceOperationParameters.TargetReferenceSystem, ProjectedCoordinateReferenceSystems.WGS84_WorldMercator);
            parameters.Add(CommonOperationParameters.MetadataPreservation, metadataPreservation);

            GraphReferenceTransformation transformation = new GraphReferenceTransformation(sourceGraph, parameters);

            transformation.Execute();

            IGeometryGraph resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(0, resultGraph.VertexCount);
            Assert.AreEqual(0, resultGraph.EdgeCount);
            Assert.AreEqual(sourceGraph.Metadata, resultGraph.Metadata);


            // graph with points and edges

            Coordinate[] coordinates = new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 20), new Coordinate(30, 30) };

            sourceGraph = new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV).CreateGraph();
            IGraphVertex[] vertices = coordinates.Select(coordinate => sourceGraph.AddVertex(coordinate)).ToArray();

            sourceGraph.AddEdge(vertices[0], vertices[1]);
            sourceGraph.AddEdge(vertices[1], vertices[2]);

            transformation = new GraphReferenceTransformation(sourceGraph, parameters);
            transformation.Execute();

            resultGraph = transformation.Result as IGeometryGraph;

            Assert.AreEqual(3, resultGraph.VertexCount);
            Assert.AreEqual(2, resultGraph.EdgeCount);
            Assert.AreEqual(1, resultGraph.OutEdges(resultGraph.Vertices[0]).Count);
            Assert.AreEqual(resultGraph.Vertices[1], resultGraph.OutEdges(resultGraph.Vertices[0]).First().Target);
            Assert.AreEqual(1, resultGraph.OutEdges(resultGraph.Vertices[1]).Count);
            Assert.AreEqual(resultGraph.Vertices[2], resultGraph.OutEdges(resultGraph.Vertices[1]).First().Target);

            for (Int32 vertexIndex = 0; vertexIndex < resultGraph.VertexCount; vertexIndex++)
            {
                GeoCoordinate sourceGeoCoordinate   = ProjectedCoordinateReferenceSystems.HD72_EOV.Projection.Reverse(coordinates[vertexIndex]);
                GeoCoordinate expectedGeoCoordinate = GeographicTransformations.HD72_WGS84_V1.Forward(sourceGeoCoordinate);
                Coordinate    expectedCoordinate    = ProjectedCoordinateReferenceSystems.WGS84_WorldMercator.Projection.Forward(expectedGeoCoordinate);

                Assert.AreEqual(expectedCoordinate, resultGraph.Vertices[vertexIndex].Coordinate);
            }


            // not supported geometry

            Mock <IGeometry> geometryMock = new Mock <IGeometry>(MockBehavior.Loose);

            geometryMock.Setup(geometry => geometry.Factory).Returns(() => new GeometryFactory(ProjectedCoordinateReferenceSystems.HD72_EOV));
            geometryMock.Setup(geometry => geometry.ReferenceSystem).Returns(() => ProjectedCoordinateReferenceSystems.HD72_EOV);

            transformation = new GraphReferenceTransformation(geometryMock.Object, parameters);
            Assert.Throws <InvalidOperationException>(() => transformation.Execute());
        }
        public void SetUp()
        {
            // source: http://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm

            IGeometryFactory factory = new GeometryFactory();

            // source graph
            _sourceGraph = factory.CreateNetwork();

            // vertices
            IGraphVertex vertexA = _sourceGraph.AddVertex(new Coordinate(0, 2));
            IGraphVertex vertexB = _sourceGraph.AddVertex(new Coordinate(0, 0));
            IGraphVertex vertexC = _sourceGraph.AddVertex(new Coordinate(1, 1));
            IGraphVertex vertexD = _sourceGraph.AddVertex(new Coordinate(2, 2));
            IGraphVertex vertexE = _sourceGraph.AddVertex(new Coordinate(2, 0));
            IGraphVertex vertexF = _sourceGraph.AddVertex(new Coordinate(3, 2));
            IGraphVertex vertexG = _sourceGraph.AddVertex(new Coordinate(3, 0));

            // forward edges
            _sourceGraph.AddEdge(vertexA, vertexB, CreateCapacityMetadata(3));
            _sourceGraph.AddEdge(vertexA, vertexD, CreateCapacityMetadata(3));
            _sourceGraph.AddEdge(vertexB, vertexC, CreateCapacityMetadata(4));
            _sourceGraph.AddEdge(vertexC, vertexA, CreateCapacityMetadata(3));
            _sourceGraph.AddEdge(vertexC, vertexD, CreateCapacityMetadata(1));
            _sourceGraph.AddEdge(vertexC, vertexE, CreateCapacityMetadata(2));
            _sourceGraph.AddEdge(vertexD, vertexE, CreateCapacityMetadata(2));
            _sourceGraph.AddEdge(vertexD, vertexF, CreateCapacityMetadata(6));
            _sourceGraph.AddEdge(vertexE, vertexB, CreateCapacityMetadata(1));
            _sourceGraph.AddEdge(vertexE, vertexG, CreateCapacityMetadata(1));
            _sourceGraph.AddEdge(vertexF, vertexG, CreateCapacityMetadata(9));

            // reverse edges
            _sourceGraph.AddEdge(vertexB, vertexA, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexD, vertexA, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexC, vertexB, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexA, vertexC, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexD, vertexC, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexE, vertexC, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexE, vertexD, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexF, vertexD, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexB, vertexE, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexG, vertexE, CreateCapacityMetadata(0));
            _sourceGraph.AddEdge(vertexG, vertexF, CreateCapacityMetadata(0));

            // source and target vertices
            _sourceVertex = vertexA;
            _targetVertex = vertexG;

            // result graph
            _resultGraph = factory.CreateNetwork();

            // vertices
            vertexA = _resultGraph.AddVertex(new Coordinate(0, 2));
            vertexB = _resultGraph.AddVertex(new Coordinate(0, 0));
            vertexC = _resultGraph.AddVertex(new Coordinate(1, 1));
            vertexD = _resultGraph.AddVertex(new Coordinate(2, 2));
            vertexE = _resultGraph.AddVertex(new Coordinate(2, 0));
            vertexF = _resultGraph.AddVertex(new Coordinate(3, 2));
            vertexG = _resultGraph.AddVertex(new Coordinate(3, 0));

            // edges
            _resultGraph.AddEdge(vertexA, vertexB, CreateResidualCapacityMetadata(1));
            _resultGraph.AddEdge(vertexA, vertexD, CreateResidualCapacityMetadata(0));
            _resultGraph.AddEdge(vertexB, vertexC, CreateResidualCapacityMetadata(2));
            _resultGraph.AddEdge(vertexC, vertexA, CreateResidualCapacityMetadata(3));
            _resultGraph.AddEdge(vertexC, vertexD, CreateResidualCapacityMetadata(0));
            _resultGraph.AddEdge(vertexC, vertexE, CreateResidualCapacityMetadata(1));
            _resultGraph.AddEdge(vertexD, vertexE, CreateResidualCapacityMetadata(2));
            _resultGraph.AddEdge(vertexD, vertexF, CreateResidualCapacityMetadata(2));
            _resultGraph.AddEdge(vertexE, vertexB, CreateResidualCapacityMetadata(1));
            _resultGraph.AddEdge(vertexE, vertexG, CreateResidualCapacityMetadata(0));
            _resultGraph.AddEdge(vertexF, vertexG, CreateResidualCapacityMetadata(5));
        }
        /// <summary>
        /// Creates a graph.
        /// </summary>
        /// <param name="factory">The geometry factory.</param>
        /// <returns>A graph that matches <param name="other" />.</returns>
        public static IGeometryGraph CreateGraph(this IGeometryFactory factory, IGeometryGraph other)
        {
            EnsureFactory(factory);

            return(factory.GetFactory <IGeometryGraphFactory>().CreateGraph(other));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphVertex" /> class.
 /// </summary>
 /// <param name="coordinate">The coordinate.</param>
 /// <param name="metadata">The metadata.</param>
 public GraphVertex(IGeometryGraph graph, Coordinate coordinate, IDictionary <String, Object> metadata)
 {
     _graph      = graph;
     _coordinate = coordinate;
     _metadata   = _graph.Factory.GetFactory <IMetadataFactory>().CreateCollection(metadata);
 }
Exemple #18
0
        public void SetUp()
        {
            _referenceSystemMock = new Mock <IReferenceSystem>(MockBehavior.Strict);
            IGeometryFactory factory = new GeometryFactory(_referenceSystemMock.Object);

            // source: http://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm

            // source graph
            _sourceGraph = factory.CreateNetwork();

            IGraphVertex vertex1 = _sourceGraph.AddVertex(new Coordinate(0, 0));
            IGraphVertex vertex2 = _sourceGraph.AddVertex(new Coordinate(1, 0));
            IGraphVertex vertex3 = _sourceGraph.AddVertex(new Coordinate(1, 1));
            IGraphVertex vertex4 = _sourceGraph.AddVertex(new Coordinate(2, 1));
            IGraphVertex vertex5 = _sourceGraph.AddVertex(new Coordinate(1, 2));
            IGraphVertex vertex6 = _sourceGraph.AddVertex(new Coordinate(0, 2));
            IGraphVertex vertex7 = _sourceGraph.AddVertex(new Coordinate(2, 0));

            _sourceGraph.AddEdge(vertex1, vertex2, CreateWeightMetadata(7));
            _sourceGraph.AddEdge(vertex1, vertex4, CreateWeightMetadata(4));
            _sourceGraph.AddEdge(vertex2, vertex3, CreateWeightMetadata(11));
            _sourceGraph.AddEdge(vertex2, vertex4, CreateWeightMetadata(9));
            _sourceGraph.AddEdge(vertex2, vertex5, CreateWeightMetadata(10));
            _sourceGraph.AddEdge(vertex3, vertex5, CreateWeightMetadata(5));
            _sourceGraph.AddEdge(vertex4, vertex5, CreateWeightMetadata(15));
            _sourceGraph.AddEdge(vertex4, vertex6, CreateWeightMetadata(6));
            _sourceGraph.AddEdge(vertex5, vertex6, CreateWeightMetadata(12));
            _sourceGraph.AddEdge(vertex6, vertex7, CreateWeightMetadata(13));
            _sourceGraph.AddEdge(vertex5, vertex7, CreateWeightMetadata(8));

            _sourceGraph.AddEdge(vertex2, vertex1, CreateWeightMetadata(7));
            _sourceGraph.AddEdge(vertex4, vertex1, CreateWeightMetadata(4));
            _sourceGraph.AddEdge(vertex3, vertex2, CreateWeightMetadata(11));
            _sourceGraph.AddEdge(vertex4, vertex2, CreateWeightMetadata(9));
            _sourceGraph.AddEdge(vertex5, vertex2, CreateWeightMetadata(10));
            _sourceGraph.AddEdge(vertex5, vertex3, CreateWeightMetadata(5));
            _sourceGraph.AddEdge(vertex5, vertex4, CreateWeightMetadata(15));
            _sourceGraph.AddEdge(vertex6, vertex4, CreateWeightMetadata(6));
            _sourceGraph.AddEdge(vertex6, vertex5, CreateWeightMetadata(12));
            _sourceGraph.AddEdge(vertex7, vertex6, CreateWeightMetadata(13));
            _sourceGraph.AddEdge(vertex7, vertex5, CreateWeightMetadata(8));

            // result graph
            _resultGraph = factory.CreateNetwork();

            vertex1 = _resultGraph.AddVertex(new Coordinate(0, 0));
            vertex2 = _resultGraph.AddVertex(new Coordinate(1, 0));
            vertex3 = _resultGraph.AddVertex(new Coordinate(1, 1));
            vertex4 = _resultGraph.AddVertex(new Coordinate(2, 1));
            vertex5 = _resultGraph.AddVertex(new Coordinate(1, 2));
            vertex6 = _resultGraph.AddVertex(new Coordinate(0, 2));
            vertex7 = _resultGraph.AddVertex(new Coordinate(2, 0));

            _resultGraph.AddEdge(vertex1, vertex2, CreateWeightMetadata(7));
            _resultGraph.AddEdge(vertex1, vertex4, CreateWeightMetadata(4));
            _resultGraph.AddEdge(vertex2, vertex5, CreateWeightMetadata(10));
            _resultGraph.AddEdge(vertex3, vertex5, CreateWeightMetadata(5));
            _resultGraph.AddEdge(vertex4, vertex6, CreateWeightMetadata(6));
            _resultGraph.AddEdge(vertex5, vertex7, CreateWeightMetadata(8));

            _resultGraph.AddEdge(vertex2, vertex1, CreateWeightMetadata(7));
            _resultGraph.AddEdge(vertex4, vertex1, CreateWeightMetadata(4));
            _resultGraph.AddEdge(vertex5, vertex2, CreateWeightMetadata(10));
            _resultGraph.AddEdge(vertex5, vertex3, CreateWeightMetadata(5));
            _resultGraph.AddEdge(vertex6, vertex4, CreateWeightMetadata(6));
            _resultGraph.AddEdge(vertex7, vertex5, CreateWeightMetadata(8));
        }
Exemple #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrimsAlgorithm" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public PrimsAlgorithm(IGeometryGraph source, IDictionary <OperationParameter, Object> parameters)
     : this(source, null, parameters)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DijkstrasSinglePathAlgorithm" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public DijkstrasSinglePathAlgorithm(IGeometryGraph source, IGeometryGraph target, IDictionary <OperationParameter, Object> parameters)
     : base(source, target, GraphOperationMethods.DijkstrasSinglePathAlgorithm, parameters)
 {
 }
Exemple #21
0
 /// <summary>
 /// Converts the specified geometry instance into an existing graph instance.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="graph">The graph.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The geometry is null.
 /// or
 /// The graph is null.
 /// </exception>
 public static void ToGraph(this IGeometry geometry, IGeometryGraph graph)
 {
     ToGraph(geometry, graph, false, false);
 }
Exemple #22
0
        /// <summary>
        /// Converts the specified coordinate list to an existing graph instance.
        /// </summary>
        /// <param name="coordinates">The coordinates.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="graph">The graph.</param>
        /// <param name="isCircular">Indicates whether the source is circular.</param>
        /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
        /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
        private static void ConvertToGraph(IList <Coordinate> coordinates, IMetadataCollection metadata, IGeometryGraph graph, Boolean isCircular, Boolean isBidirectional, Boolean preserveMetadata)
        {
            if (graph == null || coordinates == null || coordinates.Count <= 0)
            {
                return;
            }

            IGraphVertex source = graph.AddVertex(coordinates[0], preserveMetadata ? metadata : null);
            IGraphVertex first  = source;
            IGraphVertex target;

            for (Int32 i = 1; i < coordinates.Count - 1; ++i)
            {
                target = graph.AddVertex(coordinates[i], preserveMetadata ? metadata : null);
                graph.AddEdge(source, target, preserveMetadata ? metadata : null);
                if (isBidirectional)
                {
                    graph.AddEdge(target, source, preserveMetadata ? metadata : null);
                }
                source = target;
            }

            if (isCircular)
            {
                graph.AddEdge(source, first, preserveMetadata ? metadata : null);
                if (isBidirectional)
                {
                    graph.AddEdge(first, source, preserveMetadata ? metadata : null);
                }
            }
            else
            {
                target = graph.AddVertex(coordinates[coordinates.Count - 1], preserveMetadata ? metadata : null);
                graph.AddEdge(source, target, preserveMetadata ? metadata : null);
                if (isBidirectional)
                {
                    graph.AddEdge(target, source, preserveMetadata ? metadata : null);
                }
            }
        }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryToNetworkConversion" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public GeometryToNetworkConversion(IGeometry source, IGeometryGraph target, IDictionary <OperationParameter, Object> parameters)
     : base(source, target, GraphOperationMethods.GeometryToNetworkConversion, parameters)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AStarAlgorithm" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public AStarAlgorithm(IGeometryGraph source, IGeometryGraph target, IDictionary <OperationParameter, Object> parameters)
     : base(source, target, GraphOperationMethods.AStarAlgorithm, parameters)
 {
     _heuristicMetric          = ResolveParameter <Func <IGraphVertex, IGraphVertex, Double> >(GraphOperationParameters.HeuristicMetric);
     _heuristicLimitMultiplier = Convert.ToDouble(ResolveParameter(GraphOperationParameters.HeuristicLimitMultiplier));
 }
Exemple #25
0
 /// <summary>
 /// Converts the specified line string to an existing graph instance.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="graph">The graph.</param>
 /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
 /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
 private static void ConvertToGraph(ILineString geometry, IGeometryGraph graph, Boolean isBidirectional, Boolean preserveMetadata)
 {
     ConvertToGraph(geometry.Coordinates, geometry.Metadata, graph, geometry.IsRing, isBidirectional, preserveMetadata);
 }
Exemple #26
0
 /// <summary>
 /// Converts the specified point to an existing graph instance.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="graph">The graph.</param>
 /// <param name="isBidirectional">Indicates whether the conversion should be performed bidirectionally.</param>
 /// <param name="preserveMetadata">Indicates whether the metadata should be preserved.</param>
 private static void ConvertToGraph(IPoint geometry, IGeometryGraph graph, Boolean isBidirectional, Boolean preserveMetadata)
 {
     graph.AddVertex(geometry.Coordinate, preserveMetadata ? geometry.Metadata : null);
 }
Exemple #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrimsAlgorithm" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public PrimsAlgorithm(IGeometryGraph source, IGeometryGraph target, IDictionary <OperationParameter, Object> parameters)
     : base(source, target, GraphOperationMethods.PrimsAlgorithm, parameters)
 {
     _sourceVertex = ResolveParameter <IGraphVertex>(GraphOperationParameters.SourceVertex);
 }
Exemple #28
0
        // TODO: use multikey dictionary for reverse edges that are not available

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="EdmondsKarpAlgorithm"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="parameters">The parameters.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The source is null.
        /// or
        /// The method requires parameters which are not specified.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// The parameters do not contain a required parameter value.
        /// or
        /// The type of a parameter does not match the type specified by the method.
        /// or
        /// The parameter value does not satisfy the conditions of the parameter.
        /// </exception>
        public EdmondsKarpAlgorithm(IGeometryGraph source, IDictionary <OperationParameter, Object> parameters)
            : base(source, null, GraphOperationMethods.EdmondsKarpAlgorithm, parameters)
        {
        }
Exemple #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KruskalsAlgorithm" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="parameters">The parameters.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source is null.
 /// or
 /// The method requires parameters which are not specified.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The parameters do not contain a required parameter value.
 /// or
 /// The type of a parameter does not match the type specified by the method.
 /// or
 /// The value of a parameter is not within the expected range.
 /// or
 /// The specified source and result are the same objects, but the method does not support in-place operations.
 /// </exception>
 public KruskalsAlgorithm(IGeometryGraph source, IGeometryGraph target, IDictionary <OperationParameter, Object> parameters)
     : base(source, target, GraphOperationMethods.KruskalsAlgorithm, parameters)
 {
 }
        /// <summary>
        /// Creates a graph.
        /// </summary>
        /// <param name="factory">The geometry factory.</param>
        /// <param name="vertexEqualityComparer">The vertex comparer.</param>
        /// <param name="edgeEqualityComparer">The edge comparer.</param>
        /// <returns>A graph that matches <param name="other" /> using the specified comparers.</returns>
        public static IGeometryGraph CreateGraph(this IGeometryFactory factory, IGeometryGraph other, IEqualityComparer <IGraphVertex> vertexEqualityComparer, IEqualityComparer <IGraphEdge> edgeEqualityComparer)
        {
            EnsureFactory(factory);

            return(factory.GetFactory <IGeometryGraphFactory>().CreateGraph(other, vertexEqualityComparer, edgeEqualityComparer));
        }