Class GurobiSolver
A wrapper class to access Gurobi
as a solver
Inherited Members
Namespace: OPTANO.Modeling.Optimization.Solver.Gurobi80
Assembly: Optimization.Solver.Gurobi80.dll
Syntax
public class GurobiSolver : GenericSolverBase<GurobiSolverConfiguration>, ISolver, ICanSolve<Model, Solution>, IAbortable, ICanManipulateANativeSolver, IDisposable, IStatus<StatusInfo>
Constructors
GurobiSolver(GurobiSolverConfiguration)
Initializes a new instance of the GurobiSolver class. This solver utilizes the native multiobjective optimization
of Gurobi 8.0.
Tries to acquire a Gurobi License
. If this fails, a Gurobi.GRBException is thrown.
In order to use the GurobiSolver in your project, make sure to reference the GurobiXX.NET.dll
from your gurobi installation folder ('..\gurobiXX\win64\bin\GurobiXX.NET.dll')
Declaration
public GurobiSolver(GurobiSolverConfiguration configuration = null)
Parameters
Type | Name | Description |
---|---|---|
GurobiSolverConfiguration | configuration | The configuration. |
Fields
GetUserVariablePartition
Property can be used to assign a callback function in which the GRBVar.Partition for a variable can be specified. The returned value will be assigned to the GRBVar without further validation. Make sure to read the documentation carefully, before using this feature: http://www.gurobi.com/documentation/8.0/refman/partition.html#attr:Partition
Declaration
public Func<Variable, int> GetUserVariablePartition
Field Value
Type | Description |
---|---|
System.Func<Variable, System.Int32> |
Methods
Abort()
If this solver instance
Declaration
public override void Abort()
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | If this solver instance does not support aborting. |
AddConstraint(Constraint)
The add constraint.
Declaration
[Obsolete("Consider using batch method AddConstraints.", false)]
protected void AddConstraint(Constraint constraint)
Parameters
Type | Name | Description |
---|---|---|
Constraint | constraint | The constraint. |
AddConstraints(IEnumerable<Constraint>)
Declaration
protected void AddConstraints(IEnumerable<Constraint> constraintsEnumerable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Constraint> | constraintsEnumerable |
AddObjective(Objective)
The add single objective method is not supported for GurobiSolver 8.0
Declaration
protected override void AddObjective(Objective objective)
Parameters
Type | Name | Description |
---|---|---|
Objective | objective | The objective. |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.NotSupportedException | This operation is |
BuildSolverModelAdapterSpecific(Int32)
Solves the specified CurrentModel.
If specified in CopySolutionToModel, the results of a solved Model will automatically
be written in the OPTANO.Modeling's Variables.
Declaration
protected override void BuildSolverModelAdapterSpecific(int prioLevel = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prioLevel | The priority level to solve for. |
Overrides
CanExportFile(FileInfo, ExportTime, Boolean)
True, if ModelOutputFile is not null and has any extension.
Declaration
protected override bool CanExportFile(FileInfo outputFile, ExportTime exportTime, bool printHints = false)
Parameters
Type | Name | Description |
---|---|---|
System.IO.FileInfo | outputFile | The file to check. |
ExportTime | exportTime | Export before or after solve. |
System.Boolean | printHints | Indicates whether to print hints. |
Returns
Type | Description |
---|---|
System.Boolean | The System.Boolean. |
Overrides
ClearLastModel()
Deletes the internal datastructures of this SolverBase instance.
Declaration
public override void ClearLastModel()
Overrides
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If this SolverBase instance |
Dispose(Boolean)
Disposes this instance of the GurobiSolver.
Frees the Gurobi License
.
Declaration
protected void Dispose(bool freeManagedObjectsAlso)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | freeManagedObjectsAlso | True, if managed objects such as the Gurobi.GRBEnv should be disposed as well. |
DisposeCustom()
Disposes this instance of Frees the Gurobi License
Declaration
protected override void DisposeCustom()
Overrides
ExportFileSolverSpecific(FileInfo)
Export the model solver specific.
Declaration
protected override void ExportFileSolverSpecific(FileInfo outputFile)
Parameters
Type | Name | Description |
---|---|---|
System.IO.FileInfo | outputFile |
Overrides
Finalize()
Finalizes an instance of the GurobiSolver class.
Frees the Gurobi License
Declaration
protected void Finalize()
GetSubOptimalSolution(Int32)
The get sub optimal solution.
Declaration
public Dictionary<string, double> GetSubOptimalSolution(int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | The index of the solution that is queried. |
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Double> | The solution values, identified by Name. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown, if there are less than |
ReadParameterFileAfterConfiguration()
Declaration
public void ReadParameterFileAfterConfiguration()
RebuildSolverModelAdapterSpecific(Int32)
Empty rebuild method, as Gurobi Solver can handle resolves.
Declaration
protected override void RebuildSolverModelAdapterSpecific(int prioLevel = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prioLevel | Not used for native multi objective solver. |
Overrides
RemoveConstraint(String)
Removes the Constraint with Name ==
name
.
Declaration
protected override void RemoveConstraint(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the Constraint to remove. |
Overrides
ResolveAdapterSpecific(Int32, IDictionary<Variable, Double>)
Performs a Gurobi specific resolve for the CurrentModel. Make sure that this method is only called, in case of an actual resolve. Otherwise, the internal Gurobi.GRBModel will throw an Gurobi.GRBException.
Declaration
protected override Solution ResolveAdapterSpecific(int prioLevel = 0, IDictionary<Variable, double> variableValues = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prioLevel | The priority level to solve for. |
System.Collections.Generic.IDictionary<Variable, System.Double> | variableValues | The start values. |
Returns
Type | Description |
---|---|
Solution | The Solution. |
Overrides
SetBranchingPriorityAdapterSpecific()
Set the BranchingPriority for all variables. Expects Gurobi.GRBModel to be up to date. Updates the Gurobi.GRBModel afterwards.
Declaration
protected override void SetBranchingPriorityAdapterSpecific()
Overrides
SetConfigurationAdapterSpecific()
Sets the solver configuration. This includes all values specified in GurobiSolverConfiguration and the following values:
The values for MIPGap
, MIPGapAbs
, and TimeLimit
are taken from the base SolverConfiguration and set every time when this method is executed.
Before, the values only were set when the user specifically specified any value other than 0.
Declaration
protected override void SetConfigurationAdapterSpecific()
Overrides
SolveAdapterSpecific(Int32, IDictionary<Variable, Double>)
Solves the specified CurrentModel.
If specified in CopySolutionToModel, the results of a solved Model will automatically
be written in the OPTANO.Modeling's Variables.
Declaration
protected override Solution SolveAdapterSpecific(int prioLevel = 0, IDictionary<Variable, double> variableValues = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prioLevel | This parameter is ignored for solvers that have a native support for multiple objectives. |
System.Collections.Generic.IDictionary<Variable, System.Double> | variableValues | The starting values to pass as |
Returns
Type | Description |
---|---|
Solution | The Solution. Before accessing the VariableValues, make sure that the Model is Feasible and the Solution is Feasible or Optimal. |
Overrides
Events
Status
The status callback during the solution process.
Declaration
public event Action<StatusInfo> Status
Event Type
Type | Description |
---|---|
System.Action<StatusInfo> |