QuickGraph
QuickGraph copied to clipboard
CompressedSparseRow bug
While looking through sources in file https://github.com/YaccConstructor/QuickGraph/blob/master/src/QuickGraph/CompressedSparseRowGraph.cs I've noticed that the method FromGraph
seems likely not to work due to the fact that start
variable isn't updated after initialization.
I've confirmed my suspicions: I've run Topological sort on adjacency graph (it turned out OK), then converted that graph to CSR and run on that - it throws QuickGraph.NonAcyclicGraphException
Sample code:
// a simple adjacency graph representation
int[][] graph = new int[5][];
graph[0] = new int[] { };
graph[1] = new int[] { 2, 3 };
graph[2] = new int[] { 3, 0 };
graph[3] = new int[] { 0 };
graph[4] = new int[] { 1 };
// interoping with quickgraph
var g = GraphExtensions.ToDelegateVertexAndEdgeListGraph(
Enumerable.Range(0, graph.Length),
v => Array.ConvertAll(graph[v], w => new SEquatableEdge<int>(v, w))
);
// it's ready to use!
foreach (var v in g.TopologicalSort())
Console.WriteLine(v);
var csr = CompressedSparseRowGraph<int>.FromGraph(g);
foreach (var vertex in csr.TopologicalSort())
{
Console.WriteLine(vertex);
}
P.S. It turned out that there's no sense for me in using QuickGraph's CSR anyway, so I just want to report this.