Class SolveResult
- Namespace
- OptalCP
- Assembly
- OptalCP.dll
Holds the solution, objective, statistics, and solve status after solving.
public class SolveResult
- Inheritance
-
SolveResult
- Inherited Members
Remarks
The result returned by Model.Solve or Solver.Solve.
Contains comprehensive information about the solve:
Solution data:
- SolveResult.Solution: The best solution found (or
Noneif no solution exists) - SolveResult.Objective: The objective value of the best solution
- SolveResult.ObjectiveBound: The proved bound on the objective
Solve statistics:
- SolveResult.NbSolutions: Total number of solutions found
- SolveResult.Proof: Whether optimality or infeasibility was proved
- SolveResult.Duration: Total solve time in seconds
History tracking:
- SolveResult.ObjectiveHistory: When each improving solution was found
- SolveResult.ObjectiveBoundHistory: When each bound improvement was proved
Example:
var model = new Model();
// ... build model ...
var result = model.Solve();
if (result.solution != null) {
Console.WriteLine($"Found solution with objective {result.objective}");
Console.WriteLine($"Best solution found at {result.solutionTime:F2}s");
if (result.proof)
Console.WriteLine("Solution is optimal!");
} else {
if (result.proof)
Console.WriteLine("Problem is infeasible");
else
Console.WriteLine("No solution found within time limit");
}
Properties
ActualWorkers
Number of worker threads actually used during solving.
public int ActualWorkers { get; }
Property Value
- int
Worker count.
Remarks
This is the actual number of workers used by the solver, which may differ from the requested Parameters.nbWorkers if that parameter was not specified (auto-detect) or if the system has fewer cores than requested.
BoundTime
Time of the last objective bound improvement.
public double? BoundTime { get; }
Property Value
- double?
The time in seconds, or None if no bound was proved.
Remarks
The time is measured from the start of the solve, in seconds.
Returns None when no bound was proved during the solve.
Cpu
CPU name detected by the solver.
public string Cpu { get; }
Property Value
- string
CPU model name.
Remarks
Contains the CPU model name as detected by the operating system.
Duration
Total duration of the solve in seconds.
public double Duration { get; }
Property Value
- double
Seconds elapsed.
MemoryUsed
Memory used by the solver in bytes.
public long MemoryUsed { get; }
Property Value
- long
Bytes used.
NbBranches
Total number of branches explored during the solve.
public long NbBranches { get; }
Property Value
- long
Branch count.
NbConstraints
Number of constraints in the model.
public int NbConstraints { get; }
Property Value
- int
Constraint count.
NbFails
Total number of failures encountered during the solve.
public long NbFails { get; }
Property Value
- long
Failure count.
NbIntVars
Number of integer variables in the model.
public int NbIntVars { get; }
Property Value
- int
Integer variable count.
NbIntervalVars
Number of interval variables in the model.
public int NbIntervalVars { get; }
Property Value
- int
Interval variable count.
NbLNSSteps
Total number of Large Neighborhood Search steps.
public long NbLNSSteps { get; }
Property Value
- long
LNS step count.
NbRestarts
Total number of restarts performed during the solve.
public long NbRestarts { get; }
Property Value
- long
Restart count.
NbSolutions
Number of solutions found during the solve.
public int NbSolutions { get; }
Property Value
- int
Solution count.
Objective
Best objective value found (for optimization problems).
public long? Objective { get; }
Property Value
- long?
The objective value, or None if not applicable.
Remarks
The value is None when:
- No objective was specified in the model (no Model.Minimize or Model.Maximize call).
- No solution was found.
- The objective expression has an absent value in the best solution.
ObjectiveBound
Proved bound on the objective value.
public long? ObjectiveBound { get; }
Property Value
- long?
The objective bound, or None if no bound was proved.
Remarks
For minimization problems, this is a lower bound: the solver proved that no solution exists with an objective value less than this bound.
For maximization problems, this is an upper bound: the solver proved that no solution exists with an objective value greater than this bound.
The value is None when no bound was proved or for satisfaction problems.
ObjectiveBoundHistory
History of objective bound improvements during the solve.
public IReadOnlyList<ObjectiveBoundEntry> ObjectiveBoundHistory { get; }
Property Value
- IReadOnlyList<ObjectiveBoundEntry>
Sequence of bound entries, one per bound improvement.
Remarks
Returns a sequence of ObjectiveBoundEntry objects, one for each bound improvement proved during the solve.
Each entry contains:
- ObjectiveBoundEntry.SolveTime: When the bound was proved
- ObjectiveBoundEntry.Value: The bound value
For minimization problems, these are lower bounds. For maximization problems, these are upper bounds. The entries are ordered chronologically by solve time.
ObjectiveHistory
History of objective value improvements during the solve.
public IReadOnlyList<ObjectiveEntry> ObjectiveHistory { get; }
Property Value
- IReadOnlyList<ObjectiveEntry>
Sequence of objective entries, one per solution found.
Remarks
Returns a sequence of ObjectiveEntry objects, one for each solution found during the solve.
Each entry contains:
- ObjectiveEntry.SolveTime: When the solution was found
- ObjectiveEntry.Objective: The objective value of that solution
- ObjectiveEntry.Valid: Whether the solution was verified
The entries are ordered chronologically by solve time.
ObjectiveSense
Objective direction.
public string? ObjectiveSense { get; }
Property Value
- string
'minimize', 'maximize', or None for satisfaction problems.
Remarks
Indicates whether the model was a minimization problem, maximization problem, or a satisfaction problem (no objective).
Proof
Whether the solve ended with a proof (optimality or infeasibility).
public bool Proof { get; }
Property Value
- bool
True if the solve completed with a proof.
Remarks
When True, the solver has either:
- Proved optimality (found a solution within the bounds defined by Parameters.absoluteGapTolerance and Parameters.relativeGapTolerance), or
- Proved infeasibility (no solution exists)
When False, the solve was interrupted (e.g., by time limit) before
a proof could be established.
Solution
The best solution found during the solve.
public Solution? Solution { get; }
Property Value
- Solution
The best solution, or None if no solution was found.
Remarks
For optimization problems, this is the solution with the best objective value. For satisfaction problems, this is the last solution found.
Returns None when no solution was found (the problem may be infeasible
or the solve was interrupted before finding any solution).
SolutionTime
Time when the best solution was found.
public double? SolutionTime { get; }
Property Value
- double?
The time in seconds, or None if no solution was found.
Remarks
The time is measured from the start of the solve, in seconds.
Returns None when no solution was found.
SolutionValid
Whether the best solution was verified.
public bool? SolutionValid { get; }
Property Value
- bool?
True if verified, None if verification was not performed.
Remarks
When parameter Parameters.verifySolutions is set to True (the
default), the solver verifies all solutions found. The verification checks
that all constraints in the model are satisfied and that the objective value
is computed correctly.
Possible values:
None- verification was not performed (parameter was not set)True- the solution was verified and correct
The value can never be False because, in that case, the solver would
stop with an error.
Solver
Solver name and version string.
public string Solver { get; }
Property Value
- string
The solver identification string.
Remarks
Contains the solver name followed by its version number.
Methods
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.