public void SimpleTestWithSearchMonitorsAndDecisionBuilder() { CpModel model; string modelText; const string modelName = "TestModelLoader"; const string equationText = "((x(0..10) + y(0..10)) == 5)"; using (var s = new Solver(modelName)) { var x = s.MakeIntVar(0, 10, "x"); var y = s.MakeIntVar(0, 10, "y"); var c = x + y == 5; Assert.That(c.Cst.ToString(), Is.EqualTo(equationText)); s.Add(c); Assert.That(s.ConstraintCount(), Is.EqualTo(1)); var collector = s.MakeAllSolutionCollector(); var db = s.MakePhase(x, y, ChooseFirstUnbound, AssignMinValue); Console.WriteLine("First search..."); s.NewSearch(db, collector); while (s.NextSolution()) { Console.WriteLine($"{x.ToString()} + {y.ToString()} == 5"); break; } s.EndSearch(); using (var vect = new SearchMonitorVector()) { vect.Add(collector); model = s.ExportModelWithSearchMonitorsAndDecisionBuilder(vect, db); modelText = model.ToString(); } } using (var s = new Solver(modelName)) { // TODO: TBD: load but without any monitors and/or DB ... s.LoadModel(model); var loader = s.ModelLoader(); // Do a quick sanity check that we at least have the proper constraint loaded. Assert.That(s.ConstraintCount(), Is.EqualTo(1)); var x = loader.IntegerExpressionByName("x").Var(); var y = loader.IntegerExpressionByName("y").Var(); { var c = x + y == 5; // These should PASS as well... Assert.That(c.Cst.ToString(), Is.Not.EqualTo("TrueConstraint()")); Assert.That(c.Cst.ToString(), Is.EqualTo(equationText)); } { /* I dare say that THIS should PASS as well, but due to the fact that IntVar and * derivatives are treated as IntExpr, it is FAILING. */ var actual = s.ExportModel(); Assert.That(actual.ToString(), Is.EqualTo(modelText)); } var db = s.MakePhase(x, y, ChooseFirstUnbound, AssignMinValue); Console.WriteLine("Second search..."); s.NewSearch(db); while (s.NextSolution()) { Console.WriteLine($"{x.ToString()} + {y.ToString()} == 5"); } s.EndSearch(); } }