17using Xunit.Abstractions;
23 private readonly ITestOutputHelper output;
39 Assert.Equal(0.0, x.
Lb());
40 Assert.Equal(100.0, x.
Ub());
44 Assert.Equal(1.0, ct1.
Lb());
45 Assert.Equal(
double.PositiveInfinity, ct1.
Ub());
49 Assert.Equal(
double.NegativeInfinity, ct2.
Lb());
50 Assert.Equal(1.0, ct2.
Ub());
54 Assert.Equal(1.0, ct3.
Lb());
55 Assert.Equal(1.0, ct3.
Ub());
59 Assert.Equal(
double.NegativeInfinity, ct4.
Lb());
60 Assert.Equal(1.0, ct4.
Ub());
64 Assert.Equal(1.0, ct5.
Lb());
65 Assert.Equal(
double.PositiveInfinity, ct5.
Ub());
69 Assert.Equal(1.0, ct6.
Lb());
70 Assert.Equal(1.0, ct6.
Ub());
82 Assert.Equal(0.0, x.
Lb());
83 Assert.Equal(100.0, x.
Ub());
86 Assert.Equal(0.0, y.
Lb());
87 Assert.Equal(100.0, y.
Ub());
103 Assert.Equal(-2.0, ct4.
Lb());
104 Assert.Equal(-2.0, ct4.
Ub());
116 Assert.Equal(0.0, x.
Lb());
117 Assert.Equal(100.0, x.
Ub());
120 Assert.Equal(0.0, y.
Lb());
121 Assert.Equal(100.0, y.
Ub());
136 Assert.Equal(-14.0, ct4.
Lb());
137 Assert.Equal(-14.0, ct4.
Ub());
142 Assert.Equal(-8.0, ct5.
Lb());
143 Assert.Equal(-8.0, ct5.
Ub());
155 Assert.Equal(0.0, x.
Lb());
156 Assert.Equal(100.0, x.
Ub());
159 Assert.Equal(0.0, y.
Lb());
160 Assert.Equal(100.0, y.
Ub());
169 Assert.Equal(5.0, ct2.
Lb());
170 Assert.Equal(5.0, ct2.
Ub());
175 Assert.Equal(9.0, ct3.
Lb());
176 Assert.Equal(9.0, ct3.
Ub());
179 Assert.True(!(x != x));
180 Assert.True((x != y));
181 Assert.True(!(x == y));
193 Assert.Equal(0.0, x.
Lb());
194 Assert.Equal(100.0, x.
Ub());
197 Assert.Equal(0.0, y.
Lb());
198 Assert.Equal(100.0, y.
Ub());
200 Constraint ct1 = solver.
Add(2 * (x + 3) + 5 * (y + x - 1) >= 3);
203 Assert.Equal(2.0, ct1.
Lb());
204 Assert.Equal(
double.PositiveInfinity, ct1.
Ub());
206 Constraint ct2 = solver.
Add(2 * (x + 3) + 5 * (y + x - 1) <= 3);
209 Assert.Equal(
double.NegativeInfinity, ct2.
Lb());
210 Assert.Equal(2.0, ct2.
Ub());
212 Constraint ct3 = solver.
Add(2 * (x + 3) + 5 * (y + x - 1) >= 3 - x - y);
215 Assert.Equal(2.0, ct3.
Lb());
216 Assert.Equal(
double.PositiveInfinity, ct3.
Ub());
218 Constraint ct4 = solver.
Add(2 * (x + 3) + 5 * (y + x - 1) <= -x - y + 3);
221 Assert.Equal(
double.NegativeInfinity, ct4.
Lb());
222 Assert.Equal(2.0, ct4.
Ub());
244 Assert.Equal(-8.0, ct3.
Lb());
245 Assert.Equal(-8.0, ct3.
Ub());
257 Assert.Equal(0.0, x.
Lb());
258 Assert.Equal(100.0, x.
Ub());
261 Assert.Equal(0.0, y.
Lb());
262 Assert.Equal(100.0, y.
Ub());
278 output.WriteLine($
"Number of variables = {solver.NumVariables()}");
279 output.WriteLine($
"Number of constraints = {solver.NumConstraints()}");
285 output.WriteLine(
"The problem does not have an optimal solution!");
289 output.WriteLine(
"Solution:");
292 output.WriteLine($
"{var.Name()} = {var.SolutionValue()}");
294 output.WriteLine($
"Optimal objective value = {solver.Objective().Value()}");
295 output.WriteLine(
"");
296 output.WriteLine(
"Advanced usage:");
297 output.WriteLine($
"Problem solved in {solver.WallTime()} milliseconds");
298 output.WriteLine($
"Problem solved in {solver.Iterations()} iterations");
303 output.WriteLine($
"{var.Name()}: reduced cost {var.ReducedCost()}");
306 double[] activities = solver.ComputeConstraintActivities();
309 output.WriteLine($
"{ct.Name()}: dual value = {ct.DualValue()}",
310 $
" activity = {activities[ct.Index()]}");
316 void RunLinearProgrammingExample(in String problemType)
318 output.WriteLine($
"------ Linear programming example with {problemType} ------");
351 void RunMixedIntegerProgrammingExample(in String problemType)
353 output.WriteLine($
"------ Mixed integer programming example with {problemType} ------");
381 void RunBooleanProgrammingExample(in String problemType)
383 output.WriteLine($
"------ Boolean programming example with {problemType} ------");
410 RunLinearProgrammingExample(
"GLOP");
411 RunLinearProgrammingExample(
"GLPK_LP");
412 RunLinearProgrammingExample(
"CLP");
413 RunLinearProgrammingExample(
"GUROBI_LP");
415 RunMixedIntegerProgrammingExample(
"GLPK");
416 RunMixedIntegerProgrammingExample(
"CBC");
417 RunMixedIntegerProgrammingExample(
"SCIP");
418 RunMixedIntegerProgrammingExample(
"SAT");
420 RunBooleanProgrammingExample(
"SAT");
421 RunBooleanProgrammingExample(
"BOP");
427 output.WriteLine(
"testSetHintAndSolverGetters");
450 Assert.Equal(constraints.Length, 2);
452 Assert.Equal(variables.Length, 2);
478 Assert.Equal(27, (objective + anew).SolutionValue(), precision: 9);