Getting TopologicalSort back into an Adjacency Graph

Topics: algorithm, graph
Dec 8, 2009 at 6:42 PM

1. I create an adjacency graph from reading an input shape file

for (uint i = 0; i < myLayer.DataSource.GetFeatureCount(); ++i)
                FeatureDataRow feat = myLayer.DataSource.GetFeature(i);

                string to_comid = feat.ItemArray[feat.Table.Columns.IndexOf("TO_COMID")].ToString();
                string from_comid = feat.ItemArray[feat.Table.Columns.IndexOf("FROM_COMID")].ToString();
                string k = feat.ItemArray[feat.Table.Columns.IndexOf("K")].ToString();
                string x = feat.ItemArray[feat.Table.Columns.IndexOf("X")].ToString();

                int v1 = Convert.ToInt32(from_comid);
                int v2 = Convert.ToInt32(to_comid);


                var e1 = new TaggedEdge<int, Reach>(v1, v2, new Reach(Convert.ToDouble(x), Convert.ToDouble(k), Convert.ToDateTime(start), Convert.ToDouble(timestep)));

 2. Next, I sort this list:

var topo = QuickGraph.Algorithms.AlgorithmExtensions.TopologicalSort<int, TaggedEdge<int, Reach>>(g);

3. Finally, I want to create a new adjacency graph, with the vertices and edges sorted.  I've tried many different things, but none have worked.  I'm not supplying any code here because nothing I've try seems to come close to working.  I've searched thourhg the documentation and discussions, but there is not info about sorting an adjacency graph and creating another one from the sorted values.

How can I do this? Can I use ".ToAdjacencyGraph()"?  If so, can someone please supply an example.


Any help is greatly appreciated!