public static void Main(string[] args) { Network net = new Network(); IntVariable X = new IntVariable(net, 0, 708); IntVariable Y = new IntVariable(net, 0, 708); IntVariable Z = new IntVariable(net, 0, 708); IntVariable T = new IntVariable(net, 0, 708); X.Add(Y).Add(Z).Add(T).Equals(711); X.Ge(Y); Y.Ge(Z); Z.Ge(T); X.Multiply(Y).Multiply(Z).Multiply(T).Equals(711000000); Solver solver = new DefaultSolver(net); for (solver.Start(); solver.WaitNext(); solver.Resume()) { Solution solution = solver.Solution; Console.Out.WriteLine(); Console.Out.WriteLine(" {0:F} + {1:F} + {2:F} + {3:F} = {4:F} ", solution.GetIntValue(X) / 100.0, solution.GetIntValue(Y) / 100.0, solution.GetIntValue(Z) / 100.0, solution.GetIntValue(T) / 100.0, 7.11); } solver.Stop(); Console.ReadLine(); }
public static void Main(String[] args) { // Create a constraint network Network net = new Network(); // Declare variables IntVariable x = new IntVariable(net); IntVariable y = new IntVariable(net); // x >= 0 x.Ge(0); // y >= 0 y.Ge(0); // x + y == 7 x.Add(y).Equals(7); // 2x + 4y == 20 x.Multiply(2).Add(y.Multiply(4)).Equals(20); // Solve the problem Solver solver = new DefaultSolver(net); /*Solution solution = solver.findAll(Solution); * int xv = solution.GetIntValue(x); * int yv = solution.GetIntValue(y); * Console.Out.WriteLine("x = " + xv + ", y = " + yv); */ for (solver.Start(); solver.WaitNext(); solver.Resume()) { Solution solution = solver.Solution; int xv = solution.GetIntValue(x); int yv = solution.GetIntValue(y); Console.Out.WriteLine("x8 = " + xv + ", y = " + yv); } solver.Stop(); //solver.findAll(new FirstStepHandler(x, y)); Console.In.ReadLine(); }