/** * Calculate the distance from the target vertex to the input * vertex using forward star form. * (FLOWER) * * @param vertex */ public Path UpdateCostForward(BaseVertex vertex) { double cost = Graph.DISCONNECTED; // 1. get the set of successors of the input vertex ISet <BaseVertex> adjVertexSet = graph.GetAdjacentVertices(vertex); // 2. make sure the input vertex exists in the index if (!startVertexDistanceIndex.ContainsKey(vertex)) { startVertexDistanceIndex.Add(vertex, Graph.DISCONNECTED); } // 3. update the distance from the root to the input vertex if necessary foreach (BaseVertex curVertex in adjVertexSet) { // 3.1 get the distance from the root to one successor of the input vertex double distance = startVertexDistanceIndex.ContainsKey(curVertex)? startVertexDistanceIndex[curVertex] : Graph.DISCONNECTED; // 3.2 calculate the distance from the root to the input vertex distance += graph.GetEdgeWeight(vertex, curVertex); //distance += ((VariableGraph)graph).get_edge_weight_of_graph(vertex, curVertex); // 3.3 update the distance if necessary double costOfVertex = startVertexDistanceIndex[vertex]; if (costOfVertex > distance) { startVertexDistanceIndex.AddOrReplace(vertex, distance); predecessorIndex.AddOrReplace(vertex, curVertex); cost = distance; } } // 4. create the subPath if exists Path subPath = null; if (cost < Graph.DISCONNECTED) { subPath = new Path(); subPath.SetWeight(cost); java.util.LinkedList <BaseVertex> vertexList = subPath.GetVertexList(); vertexList.add(vertex); BaseVertex selVertex = predecessorIndex[vertex]; while (selVertex != null) { vertexList.add(selVertex); selVertex = predecessorIndex.GetValueIfExists(selVertex); } } return(subPath); }