1using System.Diagnostics;
20 public async ValueTask<LinearModelSolveResult>
SolveAsync(
24 CancellationToken cancellationToken =
default)
26 ArgumentNullException.ThrowIfNull(model);
27 ArgumentNullException.ThrowIfNull(selection);
28 ArgumentNullException.ThrowIfNull(options);
33 throw new ArgumentException(
34 "The supplied selection does not target Gurobi.",
41 if (
string.IsNullOrWhiteSpace(executable) ||
42 !File.Exists(executable))
47 "The selected Gurobi executable is no longer available.");
79 await _runner.RunAsync(
82 $
"ResultFile={solutionPath}",
92 process.CombinedOutput;
95 File.Exists(solutionPath);
97 IReadOnlyDictionary<int, double> values =
117 $
"gurobi_cl exit code: {process.ExitCode}.",
122 catch (OperationCanceledException)
134 [
"Gurobi execution was cancelled by the caller."],
139 catch (Exception exception)
150 exception.GetType().Name,
170 "infeasible or unbounded",
171 StringComparison.OrdinalIgnoreCase))
177 "model is infeasible",
178 StringComparison.OrdinalIgnoreCase))
184 "model is unbounded",
185 StringComparison.OrdinalIgnoreCase))
191 "optimal solution found",
192 StringComparison.OrdinalIgnoreCase) ||
195 StringComparison.OrdinalIgnoreCase))
206 ? LinearModelSolveStatus.Unknown
210 private static LinearModelSolveResult Failure(
212 SolverSelectionResult selection,
215 return new LinearModelSolveResult(
218 new SolverExecutionInfo(selection),
222 "Executable unavailable",
Runs a solver command-line process with cancellation and captured output.
Configures one solver-backed execution of a portable linear model.
bool KeepTemporaryFiles
Gets or sets whether temporary model/solution/log artifacts are retained.
Result of executing a solver-independent linear or mixed-integer model.
Parses solver text solutions using portable variable names v_<id>.
static IReadOnlyDictionary< int, double > ParseFile(string path)
Parses a text solution file.
Writes a conservative LP representation understood by all four supported execution backends.
void Write(LinearModel model, string path)
Writes the supplied model to an LP file.
Executes portable LP/MILP models through the official gurobi_cl executable.
SolverKind SolverKind
Gets the concrete solver implemented by this executor.
async ValueTask< LinearModelSolveResult > SolveAsync(LinearModel model, SolverSelectionResult selection, LinearModelSolveOptions options, CancellationToken cancellationToken=default)
Executes one portable model using an already selected solver.
static LinearModelSolveResult BuildSolutionResult(LinearModel model, SolverSelectionResult selection, LinearModelSolveOptions options, LinearModelSolveStatus proposedStatus, IReadOnlyDictionary< int, double > returnedValues, bool hasCandidateSolution, TimeSpan duration, string nativeStatus, IEnumerable< string > diagnostics, string artifactDirectory)
static string CreateArtifactDirectory(SolverKind solverKind, LinearModelSolveOptions options)
static string LastMeaningfulLine(string text)
static void DeleteArtifactsUnlessRetained(string directory, LinearModelSolveOptions options)
static void ExportModelIfRequested(string generatedModelPath, LinearModelSolveOptions options)
Immutable solver-independent linear or mixed-integer linear model.
string Name
Gets the model name.
string NativeLibraryPath
Gets the native library or executable path, when applicable.
Serializable-style immutable snapshot of the solver selected for one solver-backed ULS execution.
Describes the outcome of optimization-solver selection.
SolverKind SelectedSolver
Gets the selected solver kind, or Unknown when none was selected.
SolverAvailabilityInfo? Availability
Gets machine-availability information for the selected solver.
Executes the portable LinearModel with one concrete solver.
LinearModelSolveStatus
Describes the termination state of a solver-backed portable linear model.
record ExternalSolverProcessResult(int ExitCode, string StandardOutput, string StandardError)