Ejemplo n.º 1
0
 static void TestSolver() {
     var solver = new Solver();
     Variable a = solver.AddVariable("a", 0, 2);
     Variable b = solver.AddVariable("b", 1, 2);
     solver.AddConstraint(a, b, 2);
     solver.Solve();
 }
        public void Test_MoveMidVarsToSegmentEnds_PushIn()
        {
            var solver = new Solver();
            const double FixedVarWeight = 1e8;
            var heavy0 = solver.AddVariable(null, 0, FixedVarWeight);
            var heavy1 = solver.AddVariable(null, 2, FixedVarWeight);
            var light0 = solver.AddVariable(null, 1);
            var light1 = solver.AddVariable(null, 1);
            solver.AddConstraint(light0, heavy0, 0);
            solver.AddConstraint(heavy1, light1, 0);
            solver.AddNeighborPair(light0, light1, 1 / FixedVarWeight);
            solver.Solve();

            // expected values
            const double Heavy0Expected = 1.00000001E-08;
            const double Light0Expected = 1.00000001E-08;
            const double Light1Expected = 1.99999999;
            const double Heavy1Expected = 1.99999999;
            if (!ApproxEquals(heavy0.ActualPos, Heavy0Expected) || !ApproxEquals(light0.ActualPos, Light0Expected)
                || !ApproxEquals(light1.ActualPos, Light1Expected) || !ApproxEquals(heavy1.ActualPos, Heavy1Expected))
            {
                if (TestGlobals.VerboseLevel > 0)
                {
                    WriteLine("Failed - actual/expected: h0={0}/{1} l0={2}/{3} l1={4}/{5} h1={6}/{7}",
                            heavy0.ActualPos,
                            Heavy0Expected,
                            light0.ActualPos,
                            Light0Expected,
                            light1.ActualPos,
                            Light1Expected,
                            heavy1.ActualPos,
                            Heavy1Expected);
                }
                Validate.Fail("Results were not as expected");
            }
        }