1using System.Reflection;
12 private static readonly SemaphoreSlim RuntimeGate =
28 "ULSAlgorithms.Solver.Xpress";
32 "ULSAlgorithms Xpress Adapter";
39 public override async ValueTask<SolverAvailabilityInfo>
41 CancellationToken cancellationToken =
default)
43 cancellationToken.ThrowIfCancellationRequested();
54 catch (Exception exception)
70 solverName:
"FICO Xpress MP",
73 "Optimizer.dll was not found. Define XPRESSDIR or set " +
74 "ULSALGORITHMS_XPRESS_OPTIMIZER_ASSEMBLY."
78 await RuntimeGate.WaitAsync(
105 solverName:
"FICO Xpress MP",
106 solverVersion: version,
108 ResolveInstallationDirectory(
113 Environment.GetEnvironmentVariable(
117 "XPRS.Init completed successfully.",
120 $
"FICO Xpress Optimizer runtime loaded from " +
121 $
"'{resolvedPath}'.",
122 "XPRS.Init completed successfully, including " +
123 "native runtime/license initialization."
133 catch (OperationCanceledException)
137 catch (Exception exception)
139 Exception effective =
149 RuntimeGate.Release();
161 solverName:
"FICO Xpress MP",
163 ResolveInstallationDirectory(
168 Environment.GetEnvironmentVariable(
171 diagnostics: [diagnostic]);
174 private static string ResolveInstallationDirectory(
177 if (
string.IsNullOrWhiteSpace(path) ||
181 StringComparison.OrdinalIgnoreCase) ||
185 StringComparison.OrdinalIgnoreCase))
187 return Environment.GetEnvironmentVariable(
192 return Path.GetDirectoryName(path) ??
196 private static object? TryGetStaticProperty(
198 params
string[] names)
200 foreach (
string name
in names)
202 PropertyInfo?
property =
205 BindingFlags.Public |
206 BindingFlags.Static |
207 BindingFlags.IgnoreCase);
209 if (property is not
null)
211 return property.GetValue(
null);
217 BindingFlags.Public |
218 BindingFlags.Static |
219 BindingFlags.IgnoreCase);
221 if (field is not
null)
223 return field.GetValue(
null);
230 private static void InvokeXpressInit(
233 MethodInfo? withArgument =
239 if (withArgument is not
null)
247 MethodInfo? withoutArgument =
253 if (withoutArgument is not
null)
255 withoutArgument.Invoke(
261 throw new MissingMethodException(
266 private static void InvokeStatic(
269 params
object?[] arguments)
276 throw new MissingMethodException(
285 private static void TryInvokeStatic(
288 params
object?[] arguments)
308 private static MethodInfo? FindStaticMethod(
315 BindingFlags.Public |
322 StringComparison.OrdinalIgnoreCase) &&
323 method.GetParameters().Length ==
static Exception Unwrap(Exception exception)
Unwraps reflection invocation exceptions.
static SolverAvailabilityStatus ClassifyFailure(Exception exception)
Maps an exception to a stable availability state.
OptimizationSolverAdapterBase(params SolverCapability[] capabilities)
Initializes an adapter with its supported capabilities.
Locates and loads the optional FICO Xpress Optimizer managed assembly.
static ? Assembly TryLoad(out string resolvedPath)
Loads an already loaded Optimizer assembly, an explicitly located assembly, or an assembly resolvable...
override async ValueTask< SolverAvailabilityInfo > CheckAvailabilityAsync(CancellationToken cancellationToken=default)
Performs the adapter-specific machine discovery / load / license check.
XpressSolverAdapter()
Initializes the Xpress adapter.
override SolverKind SolverKind
Gets the concrete solver targeted by this adapter.
override string AdapterName
Gets the adapter display name.
override string AdapterId
Gets the stable adapter identifier.
Describes solver availability and the installation selected by an adapter.
SolverAvailabilityStatus
Describes whether a solver can currently be used on the current computer.
SolverCapability
Identifies an optional capability exposed by an optimization-solver adapter.
@ LinearProgramming
Continuous linear programming.
@ LpExport
LP-format export.
@ OptimalityGapReporting
Best-bound and optimality-gap reporting.
@ MixedIntegerLinearProgramming
Mixed-integer linear programming.
@ SearchStatistics
Search-node and iteration statistics.
SolverKind
Identifies a mathematical optimization solver that can be used by solver-backed ULS algorithms.