public static void Main(string[] args) { long timeout = 5; int n = 80; // number of binary variables int m = n / 5; // number of constraints int p = n / 5; // Each constraint picks p variables and requires that half of them are 1 Random R = new Random(1234); //TAG:begin-model using (Model M = new Model("SolveBinary")) { M.SetLogHandler(System.Console.Out); //Variable x = M.Variable("x", n, Domain.InRange(0,1)); Variable x = M.Variable("x", n, Domain.Binary()); M.Objective(ObjectiveSense.Minimize, Expr.Sum(x)); //M.SetSolverParam("numThreads",1); int[] idxs = new int[n]; for (int i = 0; i < n; ++i) { idxs[i] = i; } int[] cidxs = new int[p]; for (var i = 0; i < m; ++i) { nshuffle(R, idxs, p); Array.Copy(idxs, cidxs, p); M.Constraint(Expr.Sum(x.Pick(cidxs)), Domain.EqualsTo(p / 2)); } //TAG:end-model var B = new Breaker(M, timeout); //TAG:begin-create-thread var T = new Thread(new ThreadStart(B.run)); T.Start(); //TAG:end-create-thread M.Solve(); B.stopThread(); T.Join(); Console.WriteLine("End."); } }