1using System.Text.RegularExpressions;
29 "ULSAlgorithms.Solver.CoinOrCbc";
33 "ULSAlgorithms COIN-OR CBC Adapter";
40 public override async ValueTask<SolverAvailabilityInfo>
42 CancellationToken cancellationToken =
default)
44 cancellationToken.ThrowIfCancellationRequested();
46 string executablePath =
47 ResolveExecutablePath();
49 if (
string.IsNullOrWhiteSpace(executablePath))
54 solverName:
"COIN-OR CBC",
57 "cbc executable was not found. Put it on PATH, define " +
58 "CBC_HOME/COINOR_HOME, or set " +
59 "ULSALGORITHMS_CBC_EXECUTABLE."
66 await _probe.RunAsync(
78 FirstMeaningfulLine(output) ??
79 $
"cbc exited with code {processResult.ExitCode}.");
85 solverName:
"COIN-OR CBC",
89 Path.GetDirectoryName(executablePath) ??
94 "Open-source solver; no runtime license required.",
97 $
"CBC executable detected at '{executablePath}'.",
98 FirstMeaningfulLine(output) ??
99 "CBC process probe completed successfully."
102 catch (OperationCanceledException)
106 catch (Exception exception)
115 string executablePath,
121 solverName:
"COIN-OR CBC",
123 Path.GetDirectoryName(executablePath) ??
127 diagnostics: [diagnostic]);
130 private static string ResolveExecutablePath()
134 "ULSALGORITHMS_CBC_EXECUTABLE",
135 "LOTSIZING_CBC_EXECUTABLE"
142 Path.Combine(
"bin",
"cbc.exe"),
143 Path.Combine(
"bin",
"cbc"),
148 EnumerateLocalCandidates());
151 private static IEnumerable<string>
152 EnumerateLocalCandidates()
156 AppContext.BaseDirectory,
157 Environment.CurrentDirectory
160 foreach (
string root
in roots)
163 Path.Combine(root,
"cbc.exe");
166 Path.Combine(root,
"cbc");
193 private static string ParseVersion(
197 VersionRegex().Match(text ??
string.Empty);
200 ? match.Groups[1].Value
204 private static string? FirstMeaningfulLine(
210 StringSplitOptions.RemoveEmptyEntries |
211 StringSplitOptions.TrimEntries)
216 @"Version:\s*([0-9]+(?:\.[0-9]+){1,3})",
217 RegexOptions.IgnoreCase |
218 RegexOptions.CultureInvariant)]
219 private static partial Regex VersionRegex();
override string AdapterName
Gets the adapter display name.
override SolverKind SolverKind
Gets the concrete solver targeted by this adapter.
override string AdapterId
Gets the stable adapter identifier.
override async ValueTask< SolverAvailabilityInfo > CheckAvailabilityAsync(CancellationToken cancellationToken=default)
Performs the adapter-specific machine discovery / load / license check.
CoinOrCbcSolverAdapter()
Initializes the CBC adapter.
OptimizationSolverAdapterBase(params SolverCapability[] capabilities)
Initializes an adapter with its supported capabilities.
Locates optional native-solver command-line executables without requiring their SDKs at compile time.
static string Resolve(IEnumerable< string > explicitExecutableEnvironmentVariables, IEnumerable< string > homeEnvironmentVariables, IEnumerable< string > relativeExecutablePaths, IEnumerable< string > pathExecutableNames, IEnumerable< string >? directCandidates=null)
Resolves an executable from explicit environment variables, installation-home hints,...
Executes short solver command-line probes and captures their output.
Captured result of a short external solver process probe.
string CombinedOutput
Gets stdout and stderr as one diagnostic string.
int ExitCode
Gets the native process exit code.
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.
@ Interruption
Cooperative interruption.
@ SearchStatistics
Search-node and iteration statistics.
SolverKind
Identifies a mathematical optimization solver that can be used by solver-backed ULS algorithms.