1using System.Reflection;
2using System.Runtime.Loader;
16 private static readonly
object RuntimeGate =
new();
33 "ULSAlgorithms.Solver.Cplex";
37 "ULSAlgorithms CPLEX Adapter";
44 public override ValueTask<SolverAvailabilityInfo>
46 CancellationToken cancellationToken =
default)
48 cancellationToken.ThrowIfCancellationRequested();
55 return ValueTask.FromResult(
59 solverName:
"IBM ILOG CPLEX",
65 cancellationToken.ThrowIfCancellationRequested();
71 Environment.GetEnvironmentVariable(
"PATH") ??
77 installation.RuntimeDirectory,
82 installation.ConcertAssemblyPath);
84 Assembly cplexAssembly =
87 installation.CplexAssemblyPath);
90 cplexAssembly.GetType(
96 Activator.CreateInstance(cplexType);
100 throw new InvalidOperationException(
101 "ILOG.CPLEX.Cplex could not be instantiated.");
110 BindingFlags.Instance |
111 BindingFlags.Public)?
117 discovery.Diagnostics
120 "The ILOG.Concert and ILOG.CPLEX managed " +
121 "assemblies were loaded successfully.",
122 "ILOG.CPLEX.Cplex was instantiated successfully."
126 return ValueTask.FromResult(
130 solverName:
"IBM ILOG CPLEX",
131 solverVersion: version,
133 installation.RootDirectory,
135 installation.CplexAssemblyPath,
137 installation.RuntimeDirectory,
139 "CPLEX environment creation succeeded.",
140 diagnostics: diagnostics));
147 BindingFlags.Instance |
150 types: Type.EmptyTypes,
157 catch (Exception exception)
159 Exception effective =
162 return ValueTask.FromResult(
166 solverName:
"IBM ILOG CPLEX",
181 Environment.SetEnvironmentVariable(
188 private static Assembly LoadAssemblyIfNeeded(
193 AppDomain.CurrentDomain
198 assembly.GetName().Name,
200 StringComparison.OrdinalIgnoreCase));
203 AssemblyLoadContext.Default.LoadFromAssemblyPath(
204 Path.GetFullPath(path));
207 private static void PrependPath(
212 string.IsNullOrWhiteSpace(currentPath)
218 Environment.SetEnvironmentVariable(
Result of searching the current machine for IBM ILOG CPLEX.
CplexInstallationInfo? Installation
Gets the selected compatible installation.
IReadOnlyList< string > Diagnostics
Gets discovery diagnostics.
Locates compatible IBM ILOG CPLEX installations without a compile-time reference to ILOG....
static CplexInstallationDiscoveryResult Discover()
Finds the newest compatible CPLEX installation visible to the process.
override string AdapterId
Gets the stable adapter identifier.
override ValueTask< SolverAvailabilityInfo > CheckAvailabilityAsync(CancellationToken cancellationToken=default)
Performs the adapter-specific machine discovery / load / license check.
override SolverKind SolverKind
Gets the concrete solver targeted by this adapter.
CplexSolverAdapter()
Initializes the CPLEX adapter.
override string AdapterName
Gets the adapter display name.
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.
Describes solver availability and the installation selected by an adapter.
record CplexInstallationInfo(string VersionFamily, string RootDirectory, string RuntimeDirectory, string ConcertAssemblyPath, string CplexAssemblyPath, string DiscoverySource)
Describes one compatible IBM ILOG CPLEX installation.
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.
@ MpsExport
MPS-format export.
@ OptimalityGapReporting
Best-bound and optimality-gap reporting.
@ MixedIntegerLinearProgramming
Mixed-integer linear programming.
@ Interruption
Cooperative interruption.
@ SearchStatistics
Search-node and iteration statistics.