martindevans / Cassowary.net

An incremental constraint solver for .NET
http://jozilla.net/Software/CassowaryNet
GNU Lesser General Public License v2.1
3 stars 5 forks source link

ClSimplexSolverExtensions.AddConstraint (versions without variables as parameters) are recreating variables then called multiple times #8

Open krypt-lynx opened 4 years ago

krypt-lynx commented 4 years ago

ClSimplexSolverExtensions.AddConstraint (ones which do not receive variables as parameters) generating new variables each time they called. I'm not sure is it intended behavior or not.

Example:

var solver = new ClSimplexSolver();
solver.AutoSolve = false;

var _L = new ClVariable("L", 0);
var _R = new ClVariable("R", 500);

var _W = new ClVariable("W");

solver.AddStay(_L);
solver.AddStay(_R);

//solver.AddConstraint(
//    _L, _R, _W,
//    (L, R, W) => L + W == R
//);
solver.AddConstraint(
    (L, R, W) => L + W == R
);

solver.Solve();

Console.WriteLine(_W);

Output: [W:0]

Expected output: [W:500]

Description of the solver:

{Tableau:
[99971e14-f8d4-4d10-9bc6-c2d8dfc611bf:obj] <==> 1*[ep1:slack] + 1*[em1:slack] + 1*[ep2:slack] + 1*[em2:slack]
[L:0] <==> -1*[ep1:slack] + 1*[em1:slack]
[R:500] <==> 500 + -1*[ep2:slack] + 1*[em2:slack]
[W:500] <==> 500 + 1*[ep1:slack] + -1*[em1:slack] + -1*[ep2:slack] + 1*[em2:slack] + -1*[d1:dummy]

so, there is a W variable, but not the one I created. Also stays somehow survived.