コード例 #1
0
        public static void ExpandEdge(this DirectedMetaGraph graph, uint vertex1, uint vertex2, List <uint> vertices, bool inverted, bool forward)
        {
            MetaEdge shortestEdge = graph.GetShortestEdge(vertex1, vertex2, (Func <uint[], float?>)(data =>
            {
                float weight;
                bool?direction;
                ContractedEdgeDataSerializer.Deserialize(data[0], out weight, out direction);
                if (!direction.HasValue || direction.Value == forward)
                {
                    return(new float?(weight));
                }
                return(new float?());
            }));

            if (shortestEdge == null)
            {
                throw new Exception(string.Format("No edge found from {0} to {1}.", new object[2]
                {
                    (object)vertex1,
                    (object)vertex2
                }));
            }
            uint contractedId = shortestEdge.GetContractedId();

            if ((int)contractedId == -2)
            {
                return;
            }
            if (inverted)
            {
                graph.ExpandEdge(contractedId, vertex1, vertices, false, !forward);
                vertices.Add(contractedId);
                graph.ExpandEdge(contractedId, vertex2, vertices, true, forward);
            }
            else
            {
                graph.ExpandEdge(contractedId, vertex2, vertices, false, forward);
                vertices.Add(contractedId);
                graph.ExpandEdge(contractedId, vertex1, vertices, true, !forward);
            }
        }
コード例 #2
0
        /// <summary>
        /// Expands a the shortest edge between the two given vertices.
        /// </summary>
        public static void ExpandEdge(this DirectedMetaGraph graph, uint vertex1, uint vertex2, List <uint> vertices, bool inverted,
                                      bool forward)
        {
            // check if expansion is needed.
            var edge = graph.GetShortestEdge(vertex1, vertex2, data =>
            {
                float weight;
                bool?direction;
                ContractedEdgeDataSerializer.Deserialize(data[0], out weight, out direction);
                if (direction == null || direction.Value == forward)
                {
                    return(weight);
                }
                return(null);
            });

            if (edge == null)
            { // no edge found!
                throw new Exception(string.Format("No edge found from {0} to {1}.", vertex1, vertex2));
            }
            var edgeContractedId = edge.GetContractedId();

            if (edgeContractedId != Constants.NO_VERTEX)
            { // further expansion needed.
                if (inverted)
                {
                    graph.ExpandEdge(edgeContractedId, vertex1, vertices, false, !forward);
                    vertices.Add(edgeContractedId);
                    graph.ExpandEdge(edgeContractedId, vertex2, vertices, true, forward);
                }
                else
                {
                    graph.ExpandEdge(edgeContractedId, vertex2, vertices, false, forward);
                    vertices.Add(edgeContractedId);
                    graph.ExpandEdge(edgeContractedId, vertex1, vertices, true, !forward);
                }
            }
        }