本文整理汇总了C#中Solver.MakeSumGreaterOrEqual方法的典型用法代码示例。如果您正苦于以下问题:C# Solver.MakeSumGreaterOrEqual方法的具体用法?C# Solver.MakeSumGreaterOrEqual怎么用?C# Solver.MakeSumGreaterOrEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver.MakeSumGreaterOrEqual方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve
private static long Solve(long num_buses_check = 0)
{
SolverParameters sPrm = new SolverParameters();
sPrm.compress_trail = 0;
sPrm.trace_level = 0;
sPrm.profile_level = 0;
Solver solver = new Solver("OrTools",sPrm);
//this works
// IntVar[,] x = solver.MakeIntVarMatrix(2,2, new int[] {-2,0,1,2}, "x");
//this doesn't work
IntVar[,] x = solver.MakeIntVarMatrix(2, 2, new int[] { 0, 1, 2 }, "x");
for (int w = 0; w < 2; w++)
{
IntVar[] b = new IntVar[2];
for (int i = 0; i < 2; i++)
{
b[i] = solver.MakeIsEqualCstVar(x[w, i], 0);
}
solver.Add(solver.MakeSumGreaterOrEqual(b, 2));
}
IntVar[] x_flat = x.Flatten();
DecisionBuilder db = solver.MakePhase(x_flat,
Solver.CHOOSE_FIRST_UNBOUND,
Solver.ASSIGN_MIN_VALUE);
solver.NewSearch(db);
while (solver.NextSolution())
{
Console.WriteLine("x: ");
for (int j = 0; j < 2; j++)
{
Console.Write("worker" + (j + 1).ToString() + ":");
for (int i = 0; i < 2; i++)
{
Console.Write(" {0,2} ", x[j, i].Value());
}
Console.Write("\n");
}
Console.WriteLine("End at---->" + DateTime.Now);
}
Console.WriteLine("\nSolutions: {0}", solver.Solutions());
Console.WriteLine("WallTime: {0}ms", solver.WallTime());
Console.WriteLine("Failures: {0}", solver.Failures());
Console.WriteLine("Branches: {0} ", solver.Branches());
solver.EndSearch();
return 1;
}