private static SolverContext GetSampleContext(string modelName) { var strats = new { Var = INT_VAR_SIMPLE, Val = INT_VALUE_SIMPLE }; const int vmin = 0, vmax = 10; const string xName = "x"; const string yName = "y"; // TODO: TBD: so apparently naming constraints may not be such a good thing... const string constraintName = "equation"; var sc = new SolverContext(modelName); Assert.That(sc.Get(s => s.ConstraintCount()), Is.EqualTo(0)); var exprs = sc.Expressions; Assert.That(exprs, Has.Count.EqualTo(0)); sc .Expression(s => { var x = s.MakeIntVar(vmin, vmax, xName); Assert.That(x.Name(), Is.EqualTo(xName)); return(x); }) .Expression(s => { var y = s.MakeIntVar(vmin, vmax, yName); Assert.That(y.Name(), Is.EqualTo(yName)); return(y); }) ; Assert.That(exprs, Has.Count.EqualTo(2)); Assert.That(sc.Constraints, Has.Count.EqualTo(0)); sc .Constrain(s => { var x = (IntVar)exprs.First(e => e.Name() == xName); var y = (IntVar)exprs.First(e => e.Name() == yName); var c = x + y == 5; Assert.That(c, Is.TypeOf <WrappedConstraint>()); Assert.That(c.Cst.ToString(), Is.EqualTo("((x(0..10) + y(0..10)) == 5)")); c.Cst.SetName(constraintName); Assert.That(c.Cst.Name(), Is.EqualTo(constraintName)); return(c); }) ; Assert.That(sc.Constraints, Has.Count.EqualTo(1)); Assert.That(sc.Monitors, Has.Count.EqualTo(0)); sc .Monitor(s => s.MakeAllSolutionCollector()) ; Assert.That(sc.Monitors, Has.Count.EqualTo(1)); Assert.Null(sc.DecisionBuilder); sc .CreateDecisionBuilder( e => new IntVarVector(e.OfType <IntVar>().ToList()) , (s, v) => s.MakePhase(v, strats.Var, strats.Val) ) ; Assert.NotNull(sc.DecisionBuilder); return(sc); }