lifebeyondfife / Decider

An Open Source .Net Constraint Programming Solver
MIT License
150 stars 21 forks source link

ArgumentNullException raised when calling StateInteger.SearchAllSolutions #59

Closed giovinazzo-kevin closed 2 years ago

giovinazzo-kevin commented 2 years ago

I'm trying to enumerate all solutions for a custom point structure P(X, Y) where the variables X and Y are defined as having the domain [0, 10]. I'm expecting 11*11 = 121 solutions in the unconstrained case. The solver returns all solutions correctly, but fails at the very end with a NRE.

image

image

lifebeyondfife commented 2 years ago

Hi Kevin, thanks for trying out Decider.

I should hopefully be able to work out what variable node is set to a null reference. I'd need the sourcecode so I can recreate the bug. Is there a branch you could share me to?

Cheers, Iain

giovinazzo-kevin commented 2 years ago

Hi Iain,

Thank you for the incredibly fast reply.

I've isolated the problem down to these two lines:

using Decider.Csp.BaseTypes;
using Decider.Csp.Integer;

var state = new StateInteger(new[] { 
        new VariableInteger("X", 0, 10), 
        new VariableInteger("Y", 0, 10) 
    }, 
    Enumerable.Empty<IConstraint>()
);
state.SearchAllSolutions();

This is a fresh console application project targeting .NET 6.

lifebeyondfife commented 2 years ago

I think I see, so there's no actual constraint, it's enumerating every pair from [(0, 0), (0, 1), ... (10, 10)].

I should have some time to look into this tomorrow. I'll be in touch if I cannot reproduce the error.

giovinazzo-kevin commented 2 years ago

No worries! For the time being and as far as I'm concerned catching the exception seems to be working.

This is just a fresh hobby project so I'm not bothered by leaving that in for a while, assuming nothing else breaks (I'll let you know, in case).

Anyway, thank you for creating this project.

lifebeyondfife commented 2 years ago

Found the issue. Searching all solutions where every combination is a valid possibility eventually leads to searching for a solution which has an empty variable. This causes the search routine to fail when trying to instantiate the empty variable. I've put a check for empty variables in the search function before starting.

I'll create a PR sometime this week and publish a new nuget package.

lifebeyondfife commented 2 years ago

This bug has been fixed by https://github.com/lifebeyondfife/Decider/pull/60. Thanks once more, @G3Kappa. Hope Decider is useful for your hobby project.