LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SolverEnvironmentVariableCatalog.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
5
7
8/// <summary>
9/// Provides the default catalog of solver-specific environment
10/// variables inspected during solver discovery.
11/// </summary>
12/// <remarks>
13/// The catalog contains generic, non-version-specific variable
14/// names. Applications may supplement it with additional
15/// version-specific or organization-specific definitions.
16/// </remarks>
18{
19 private static readonly IReadOnlyList<
21 CreateDefinitions();
22
23 /// <summary>
24 /// Gets all default environment-variable definitions.
25 /// </summary>
26 public static IReadOnlyList<
28 Definitions;
29
30 /// <summary>
31 /// Gets the default environment-variable definitions
32 /// associated with a solver.
33 /// </summary>
34 /// <param name="solverKind">
35 /// Concrete solver kind.
36 /// </param>
37 /// <returns>
38 /// Definitions associated with the selected solver.
39 /// </returns>
40 /// <exception cref="ArgumentOutOfRangeException">
41 /// Thrown when <paramref name="solverKind"/> is
42 /// <see cref="SolverKind.Unknown"/> or
43 /// <see cref="SolverKind.Automatic"/>.
44 /// </exception>
45 public static IReadOnlyList<
47 SolverKind solverKind)
48 {
49 if (solverKind is
50 SolverKind.Unknown or
51 SolverKind.Automatic)
52 {
53 throw new ArgumentOutOfRangeException(
54 nameof(solverKind),
55 solverKind,
56 "A concrete solver kind is required.");
57 }
58
59 return Definitions
60 .Where(
61 definition =>
62 definition.SolverKind ==
63 solverKind)
64 .OrderBy(
65 definition =>
66 definition.Priority)
67 .ThenBy(
68 definition =>
69 definition.VariableName,
70 StringComparer.OrdinalIgnoreCase)
71 .ToArray();
72 }
73
74 /// <summary>
75 /// Gets a definition by environment-variable name.
76 /// </summary>
77 /// <param name="variableName">
78 /// Environment-variable name.
79 /// </param>
80 /// <returns>
81 /// Matching definition, or <see langword="null"/> when the
82 /// name is not included in the default catalog.
83 /// </returns>
84 /// <exception cref="ArgumentException">
85 /// Thrown when <paramref name="variableName"/> is empty.
86 /// </exception>
88 string variableName)
89 {
90 if (string.IsNullOrWhiteSpace(
91 variableName))
92 {
93 throw new ArgumentException(
94 "An environment-variable name is required.",
95 nameof(variableName));
96 }
97
98 return Definitions.FirstOrDefault(
99 definition =>
100 string.Equals(
101 definition.VariableName,
102 variableName.Trim(),
103 StringComparison.OrdinalIgnoreCase));
104 }
105
106 private static IReadOnlyList<
108 CreateDefinitions()
109 {
110 return new[]
111 {
113 SolverKind.Cplex,
114 "CPLEX_STUDIO_DIR",
115 "IBM ILOG CPLEX Optimization Studio " +
116 "installation directory.")
117 {
118 Priority =
119 10
120 },
121
122 new SolverEnvironmentVariableDefinition(
123 SolverKind.Gurobi,
124 "GUROBI_HOME",
125 "Gurobi Optimizer installation directory.")
126 {
127 Priority =
128 10
129 },
130
131 new SolverEnvironmentVariableDefinition(
132 SolverKind.Gurobi,
133 "GRB_LICENSE_FILE",
134 "Gurobi license file or license-server " +
135 "configuration.")
136 {
137 IsLicenseVariable =
138 true,
139
140 Priority =
141 20
142 },
143
144 new SolverEnvironmentVariableDefinition(
145 SolverKind.Xpress,
146 "XPRESSDIR",
147 "FICO Xpress installation directory.")
148 {
149 Priority =
150 10
151 },
152
153 new SolverEnvironmentVariableDefinition(
154 SolverKind.Xpress,
155 "XPAUTH_PATH",
156 "FICO Xpress authorization or license path.")
157 {
158 IsLicenseVariable =
159 true,
160
161 Priority =
162 20
163 }
164 };
165 }
166}
Provides the default catalog of solver-specific environment variables inspected during solver discove...
static ? SolverEnvironmentVariableDefinition Find(string variableName)
Gets a definition by environment-variable name.
static IReadOnlyList< SolverEnvironmentVariableDefinition > ForSolver(SolverKind solverKind)
Gets the default environment-variable definitions associated with a solver.
static IReadOnlyList< SolverEnvironmentVariableDefinition > All
Gets all default environment-variable definitions.
Describes a solver-specific environment variable that may identify an installation directory,...
SolverKind
Identifies a supported mathematical optimization solver.
Definition SolverKind.cs:12