Add EdgeCost with AddVerticesAndEdge?

Topics: algorithm, graph
Jan 3, 2012 at 12:44 AM

I have a list of highway links, I am interested in applying a shortest path algorithm.

Each link has a start node and end node, and a distance.

I build the graph as follows:

   foreach (RoadLink link in listRoadLink)
                        {
                           graph.AddVerticesAndEdge(new Edge<int> (link.StartNodeIdentifier,link.EndNodeIdentifier));                      
                        }

My question is how to identify the added edge, so that I can later add the distance as an edge cost in a dictionary, e.g. if I have:

    Dictionary<Edge<int>, double> edgeCost2 = new Dictionary<Edge<int>, double>(graph.EdgeCount);

The problem is that iterating on the edges

    foreach (var e in graph.Edges)
                        {
                            outputFile.WriteLine(e);
                            Console.WriteLine(e);
                        }

does not give me the same order of edges as when I entered originally, which is the point at which I know the distance for the edge being added.

 

Thank you.

 

R, Males

Cincinnati, Ohio, USA