NullReferenceException for simple NetworkSimplex
a delicious .NET graph library
Status: Alpha
Brought to you by:
bszalkai
Hello !
I'm trying to use the NetworkSimplex algorithm to model a minimum cost flow problem. But I'm having trouble making it work.
I get this error :
NullReferenceException: Object reference not set to an instance of an object
Satsuma.Supergraph.U (Satsuma.Arc arc) (at <5efc169d7c1b49ccb914f69786edb6d6>:0)
Satsuma.Supergraph.U (Satsuma.Arc arc) (at <5efc169d7c1b49ccb914f69786edb6d6>:0)
Satsuma.NetworkSimplex.Step () (at <5efc169d7c1b49ccb914f69786edb6d6>:0)
Satsuma.NetworkSimplex.Run () (at <5efc169d7c1b49ccb914f69786edb6d6>:0)
This is how I tried to use it (obviously my real use case is more complex, but this fails the same) :
CustomGraph graph = new CustomGraph();
Node nodeA = graph.AddNode();
Node nodeB = graph.AddNode();
Node nodeC = graph.AddNode();
Arc arcAB = graph.AddArc(nodeA, nodeB, Directedness.Undirected);
Arc arcAC = graph.AddArc(nodeA, nodeC, Directedness.Undirected);
Arc arcBC = graph.AddArc(nodeB, nodeC, Directedness.Undirected);
Func<Arc, long> lowerBound = delegate (Arc arc) { return 0; };
Func<Arc, long> upperBound = delegate (Arc arc) { return 10; };
Func<Arc, double> cost = delegate (Arc arc) { return 0f; };
Func<Node, long> supply = delegate (Node node)
{
if (node == nodeA)
return 1;
if (node == nodeB)
return -1;
return 0;
};
NetworkSimplex solver = new NetworkSimplex(graph, lowerBound, upperBound, supply, cost);
solver.Run();
In the reference doc, it says NetworkSimplex treats all Arc as Directed, so I also tried adding all arcs like this :
Arc arcAB = graph.AddArc(nodeA, nodeB, Directedness.Directed);
Arc arcAC = graph.AddArc(nodeA, nodeC, Directedness.Directed);
Arc arcBC = graph.AddArc(nodeB, nodeC, Directedness.Directed);
Arc arcBA = graph.AddArc(nodeA, nodeB, Directedness.Directed);
Arc arcCA = graph.AddArc(nodeC, nodeA, Directedness.Directed);
Arc arcCB = graph.AddArc(nodeC, nodeB, Directedness.Directed);
But still the same error.
Am I using it wrong ? An example would be very welcome.
I'm trying to use this using 0.6 Debug DLL in Unity3D with .NET 4.6 Framework.
Thanks !
Hello, I could not reproduce this bug using your code.
Hello. I found the same result. The NPE ocurrs in Supergraph ln 233. Object'graph' is not initialized because Graph ln 288 passes a null object to the constructor.