예제 #1
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);
        }
        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>
        /// 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);
        }
예제 #4
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);
                }
            }
        }
예제 #5
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));
        }
        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));
        }