LotSizingDataModel.Solver.Cplex 2.0.1
IBM ILOG CPLEX adapter and installation discovery integration.
Loading...
Searching...
No Matches
CplexNativeSmokeTest.cs
Go to the documentation of this file.
1using System;
2using NativeCplex = global::ILOG.CPLEX.Cplex;
3using ILOG.Concert;
4
6
7/// <summary>
8/// Runs a minimal native CPLEX optimization to validate managed
9/// assemblies, native libraries, and license availability.
10/// </summary>
11/// <remarks>
12/// The test solves:
13/// <code>
14/// minimize x
15/// subject to x &gt;= 1
16/// x &gt;= 0.
17/// </code>
18/// The expected solution is <c>x = 1</c> with objective value
19/// <c>1</c>.
20/// </remarks>
21public static class CplexNativeSmokeTest
22{
23 /// <summary>
24 /// Executes the native smoke test.
25 /// </summary>
26 /// <returns>
27 /// Native smoke-test result.
28 /// </returns>
30 {
31 NativeCplex? cplex = null;
32
33 try
34 {
35 cplex = new NativeCplex();
36
37 INumVar x =
38 cplex.NumVar(
39 0.0,
40 double.MaxValue,
41 "x");
42
43 cplex.AddMinimize(
44 x,
45 "minimize_x");
46
47 cplex.AddGe(
48 x,
49 1.0,
50 "x_at_least_one");
51
52 bool solved =
53 cplex.Solve();
54
55 if (!solved)
56 {
58 false,
59 cplex.Version,
60 cplex.GetStatus().ToString(),
61 null,
62 null,
63 "CPLEX loaded correctly but did not return a " +
64 "solution for the smoke-test model.");
65 }
66
67 double xValue =
68 cplex.GetValue(x);
69
70 double objectiveValue =
71 cplex.ObjValue;
72
73 bool expectedSolution =
74 Math.Abs(xValue - 1.0) <= 1e-7 &&
75 Math.Abs(objectiveValue - 1.0) <= 1e-7;
76
78 expectedSolution,
79 cplex.Version,
80 cplex.GetStatus().ToString(),
81 objectiveValue,
82 xValue,
83 expectedSolution
84 ? "CPLEX native smoke test succeeded."
85 : "CPLEX solved the model but returned an " +
86 "unexpected result.");
87 }
88 catch (System.Exception exception)
89 {
91 false,
92 cplex?.Version ?? string.Empty,
93 string.Empty,
94 null,
95 null,
96 exception.ToString());
97 }
98 finally
99 {
100 cplex?.End();
101 }
102 }
103}
global::ILOG.CPLEX.Cplex NativeCplex
Runs a minimal native CPLEX optimization to validate managed assemblies, native libraries,...
static CplexNativeSmokeTestResult Run()
Executes the native smoke test.
Represents the result of a minimal native CPLEX smoke test.