Class Model
Represents a mathematical model
Inheritance
Inherited Members
Namespace: OPTANO.Modeling.Optimization
Assembly: Optimization.dll
Syntax
[DataContract]
[Serializable]
public class Model : ICanRegisterSolvers, ICanTrackPropertyChangesInVariables, ICanTrackPropertyChangesInConstraints
Constructors
Model()
Initializes a new instance of the Model class.
Declaration
public Model()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Model requires Current != |
Model(String)
Initializes a new instance of the Model class.
Declaration
public Model(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The model name. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Model requires Current != |
Properties
AreAllConstraintsLinear
Have all constraints in this model instance linear expressions?
Declaration
public bool AreAllConstraintsLinear { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
AreAllVariablesBinary
Are all variables in this model instance of type Binary?
A Binary variable is a special case of an Integer variable, where the bounds are in the range of [0, 1]
.
Declaration
public bool AreAllVariablesBinary { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
AreAllVariablesContinuous
Are variables in this model instance of type Continuous?
Declaration
public bool AreAllVariablesContinuous { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
AreAllVariablesInteger
Are all variables in this model instance of type Integer?
Declaration
public bool AreAllVariablesInteger { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Constraints
Constraints in this model instance.
Declaration
public IEnumerable<Constraint> Constraints { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Constraint> |
ConstraintsCount
Gets the count of constraints in this model instance.
Declaration
public int ConstraintsCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsMultiObectiveModel
Declaration
public bool IsMultiObectiveModel { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsMultiStageModel
Gets a value indicating whether this Model contains multiple optimization stages.
Declaration
public bool IsMultiStageModel { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsObjectiveLinear
Has the objective in this model instance a linear expression
Declaration
public bool IsObjectiveLinear { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Name
Name of this model instance.
Declaration
[DataMember]
public string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String |
NotifySolversIfModelChanges
If set to true
(standard value), will communicate the changes made to this model directly to all solver instances that have previously solved this model.
Declaration
public bool NotifySolversIfModelChanges { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Objective
Objectives for this model instance.
Declaration
[Obsolete("Please consider using the AddObjective function in order to enable support for multiobjective optimization.", false)]
public Objective Objective { get; set; }
Property Value
Type | Description |
---|---|
Objective |
Objectives
Gets the objectives.
Declaration
public IEnumerable<Objective> Objectives { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Objective> |
ObjectivesCount
Gets the count of objectives in this model instance.
Declaration
public int ObjectivesCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ObjectiveStagesCount
Gets the count of objective stages in this model instance.
Declaration
public int ObjectiveStagesCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ObjectiveStagesOrdered
Gets the objective stages in optimization order. I.e. the objective with highest priority is returned first.
Declaration
public IEnumerable<int> ObjectiveStagesOrdered { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32> |
OperatorConstraints
Gets the Operator Constraints in this model instance. The OperatorConstraints will be transformed into supported constraints before a model is passed to the solver.
Declaration
public IEnumerable<OperatorConstraint> OperatorConstraints { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<OperatorConstraint> |
PriorityLevels
Gets the distinct set of priority levels, ordered descending.
Declaration
public IEnumerable<int> PriorityLevels { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32> |
SOS1Sets
Sets of S1 variables in this model instance.
The Value
of each entry indicates the weight for the variable in its SOS.
Declaration
public IEnumerable<Dictionary<Variable, double>> SOS1Sets { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.Dictionary<Variable, System.Double>> |
SOS2Sets
Sets of S2 variables in this model instance.
The Value
of each entry indicates the weight for the variable in its SOS.
It is used to determine the variable ordering in a SOS of type S2.
Declaration
public IEnumerable<Dictionary<Variable, double>> SOS2Sets { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.Dictionary<Variable, System.Double>> |
SOS3Sets
Sets of S3 variables in this model instance.
The Value
of each entry indicates the weight for the variable in its SOS.
Declaration
public IEnumerable<Dictionary<Variable, double>> SOS3Sets { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.Dictionary<Variable, System.Double>> |
UnhandledVariables
Gets all variables that are not handled by the variable collection that are registered to this model.
Declaration
public IEnumerable<Variable> UnhandledVariables { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Variable> | The set of unhandled variables. |
VariableCollections
The get variable collection enumerator.
Declaration
public IEnumerable<VariableCollection> VariableCollections { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<VariableCollection> | The System.Collections.IEnumerable. An enumerable, that contains all variable collections that are registered to this model |
Variables
Variables in this model instance.
Declaration
public IEnumerable<Variable> Variables { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Variable> |
VariablesCount
Gets the count of variables in this model instance.
Declaration
public int VariablesCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
VariablesRemovedDuringPreProcessing
Returns the variables that were removed during pre-processing. Can be null, if ComputeRemovedVariables is disabled, or if the chosen Solver does not support the computation.
Declaration
public IEnumerable<Variable> VariablesRemovedDuringPreProcessing { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Variable> |
VariableStatistics
Gets additional variable statistics for all variables that are registered to this model. Refer to the Model Feature section that is described in the OPTANO.Modeling User Documentation for further information.
Declaration
public HashSet<VariableStatisticRow> VariableStatistics { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.HashSet<VariableStatisticRow> | The System.Collections.Generic.HashSet<T>. All variable statistics |
Methods
Abs(Expression, Double)
Returns an Expression object respresenting the absolute value of the specified expression.
Declaration
public static Expression Abs(Expression expression, double bigM = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
Expression | expression | The expression. |
System.Double | bigM | Large number, only used if the bounds of the variables of the expressions are non-finite |
Returns
Type | Description |
---|---|
Expression | An expression that represents the |
Abs(Term, Double)
Returns an Expression object respresenting the absolute value of the specified expression.
Declaration
public static Expression Abs(Term expression, double bigM = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
Term | expression | The expression. |
System.Double | bigM | Large number, only used if the bounds of the variables of the expressions are non-finite |
Returns
Type | Description |
---|---|
Expression | An expression that represents the |
AddAlternativeConstraintGroups(IEnumerable<Constraint>, IEnumerable<Constraint>, Double)
Adds two groups of constraints. Either group1 or group2 or both have to be fulfilled in a valid solution
Declaration
public void AddAlternativeConstraintGroups(IEnumerable<Constraint> group1, IEnumerable<Constraint> group2, double bigM)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Constraint> | group1 | The one group of constraints |
System.Collections.Generic.IEnumerable<Constraint> | group2 | The other group of constraints |
System.Double | bigM | The big M to use in reformulation |
AddAlternativeConstraints(Dictionary<Constraint, Double>)
Adds constraints that are OR concatenated. That means that at least one of these constraints have to be fulfilled. For every constraint l<=exp<=u in constraints this method will add the following two constraints to your model:
-exp-bigM*(1-z1)<=-l
and
exp-bigM*(1-z1)<=u
,
where z
is a binary variable indicating that this constraint is active (has to be fulfilled).
Since this will happen for every constraint in the list of constraints, the binary variables z will be summed up in one additional constraint, such that expression.Sum(z1,...,zn)>=1
For each constraint you will have to provide a bigM
value.
Declaration
public void AddAlternativeConstraints(Dictionary<Constraint, double> constraintBigMPairs)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<Constraint, System.Double> | constraintBigMPairs | The constraints and a |
AddAlternativeConstraints(IEnumerable<Constraint>)
Adds constraints that are OR concatenated. That means that at least one of these constraints have to be fulfilled. For every constraint l<=exp<=u in constraints this method will add the following two constraints to your model:
-exp-bigM*(1-z1)<=-l
and
exp-bigM*(1-z1)<=u
,
where z
is a binary variable indicating that this constraint is active (has to be fulfilled).
Since this will happen for every constraint in the list of constraints, the binary variables z will be summed up in one additional constraint, such that Expression.Sum(z1,...,zn)>=1
The bigM
will be computed for you, but this can only happen when you provide finite
bounds on all variables that are used in your constraints.
Declaration
public void AddAlternativeConstraints(IEnumerable<Constraint> constraints)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Constraint> | constraints |
AddConstraint(Constraint)
Adds constraint
to this model instance if it is consistent.
You need to make sure that the name of the constraint is unique.
Declaration
public void AddConstraint(Constraint constraint)
Parameters
Type | Name | Description |
---|---|---|
Constraint | constraint | Constraint to add, constraint may not be null |
AddConstraint(Constraint, String)
Adds constraint
to this model instance if it is consistent.
You need to make sure that the name of the constraint is unique.
Declaration
public void AddConstraint(Constraint constraint, string name)
Parameters
Type | Name | Description |
---|---|---|
Constraint | constraint | Constraint to add, constraint may not be null |
System.String | name | The unique name for this constraint. If the name is |
AddConstraint(OperatorConstraint)
Adds operatorConstraint
to the OperatorConstraints in the model.
Declaration
public void AddConstraint(OperatorConstraint operatorConstraint)
Parameters
Type | Name | Description |
---|---|---|
OperatorConstraint | operatorConstraint | The OperatorConstraint (Not, Or, Where). |
AddConstraint(String, Double, Double, Expression)
Adds a new Constraint to this model instance if it is consistent.
Declaration
public Constraint AddConstraint(string name, double lowerBound, double upperBound, Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The unique name for this constraint. If the name is |
System.Double | lowerBound | Lower bound (left hand side) of the new constraint. |
System.Double | upperBound | Upper bound (right hand side) of the new constraint. |
Expression | expression | Expression of the new constraint. |
Returns
Type | Description |
---|---|
Constraint | The newly created Constraint. |
AddConstraintIfRelevant(Constraint)
Adds the given constraint
if IsRelevant(Constraint).
Declaration
public bool AddConstraintIfRelevant(Constraint constraint)
Parameters
Type | Name | Description |
---|---|---|
Constraint | constraint | The constraint to add. |
Returns
Type | Description |
---|---|
System.Boolean |
|
AddConstraintIfRelevant(Constraint, String)
Adds the given constraint
if IsRelevant(Constraint).
Declaration
public bool AddConstraintIfRelevant(Constraint constraint, string name)
Parameters
Type | Name | Description |
---|---|---|
Constraint | constraint | The constraint to add. |
System.String | name | The name for the constraint. If null, a new name will be generated. |
Returns
Type | Description |
---|---|
System.Boolean |
|
AddConstraints(IEnumerable<Constraint>)
Adds a set of constraint to this model instance if it is consistent.
Declaration
public void AddConstraints(IEnumerable<Constraint> constraints)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Constraint> | constraints | Set of constraints to add. |
AddObjective(Objective, String)
Adds another objective to this model.
Make sure to only use multiple objectives, if the SolverBase that you use implements the interface OPTANO.Modeling.Optimization.Solver.Interfaces.ICanManipulateANativeSolver. Other solvers only support a single objective.
Declaration
public void AddObjective(Objective objective, string name = null)
Parameters
Type | Name | Description |
---|---|---|
Objective | objective | The objective. |
System.String | name | The name for the objective or null, if the current Name should be used. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
System.InvalidOperationException | The |
AddRelevantConstraints(IEnumerable<Constraint>)
Adds all constraints that fulfill IsRelevant(Constraint).
Declaration
public int AddRelevantConstraints(IEnumerable<Constraint> constraints)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Constraint> | constraints |
Returns
Type | Description |
---|---|
System.Int32 | The number of added, relevant constraints. |
AddSOS(Dictionary<Variable, Double>, SOSType)
Adds an SOS Constraint of the given SOSType.
Declaration
public void AddSOS(Dictionary<Variable, double> variables, SOSType type)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<Variable, System.Double> | variables | The variables with a weight in the SOS for every variable. The weight is used to determine the ordering of variables in S2. Variables in the SOS 2 will be ordered ascending by weight.
|
SOSType | type | The SOS type. |
AddSOS1(Dictionary<Variable, Double>)
Adds an SOS1 constraint. At most one variable in this set may have a value > 0.
Declaration
public void AddSOS1(Dictionary<Variable, double> variables)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<Variable, System.Double> | variables | The variables with a weight factor for every variable in the SOS.
|
AddSOS2(Dictionary<Variable, Double>)
Adds an SOS2 constraint. The variables in this set will be ordered ascending by the given weight. At most 2 directly ascending variables in this set may have a value > 0.
Declaration
public void AddSOS2(Dictionary<Variable, double> variables)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<Variable, System.Double> | variables | The variables with a weight factor for every variable in the SOS. Variables in the SOS 2 will be ordered ascending by weight.
|
AddSOS3(Dictionary<Variable, Double>)
Adds an SOS3 constraint. Alle variables need to be Binary. Exactly one of the variables in this set needs to be > 0.
Declaration
public void AddSOS3(Dictionary<Variable, double> variables)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<Variable, System.Double> | variables | The variables with a weight factor for every variable in the SOS.
|
AddVariable(Variable)
Adds variable
to this model instance if it is consistent.
Declaration
public void AddVariable(Variable variable)
Parameters
Type | Name | Description |
---|---|---|
Variable | variable | Variable to add. |
AddVariables(IEnumerable<Variable>)
Adds a set of variables to this model instance if it is consistent.
Declaration
public void AddVariables(IEnumerable<Variable> variables)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Variable> | variables | Set of variables to add. |
Ceil(Expression)
Returns an Expression object respresenting the ceil roundoff of the specified expression.
Declaration
public static Expression Ceil(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
Expression | expression | The expression. |
Returns
Type | Description |
---|---|
Expression | An expression that represents the |
Clear()
Removes all variables, constraints, objectives and scenarios from this model instance.
Declaration
public void Clear()
ContainsConstraint(String)
Contains this model instance a constraint named name
?
Declaration
public bool ContainsConstraint(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the constraint to search for. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsVariable(String)
Contains this model instance a variable named name
?
Declaration
public bool ContainsVariable(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the variable to search for. |
Returns
Type | Description |
---|---|
System.Boolean |
|
DeepClone()
Creates a deep clone of this model by serializing and deserializing it.
Declaration
public Model DeepClone()
Returns
Type | Description |
---|---|
Model | The cloned Model. |
DenseOrderIndexForPrioLevel(Int32)
Gets the position of the given priority level in the sorted list of all priority levels (by optimization order), or 0 if the level is not found.
Declaration
public int DenseOrderIndexForPrioLevel(int prioLevel)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | prioLevel | The priority level. |
Returns
Type | Description |
---|---|
System.Int32 | The position-index of the priority level during the (multi-objective) optimization. |
Floor(Expression)
Returns an Expression object respresenting the floor roundoff of the specified expression.
Declaration
public static Expression Floor(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
Expression | expression | The expression. |
Returns
Type | Description |
---|---|
Expression | An expression that represents the |
GetBranchingPriority(String)
The get branching priority.
Declaration
public int? GetBranchingPriority(string variableName)
Parameters
Type | Name | Description |
---|---|---|
System.String | variableName | The variable name. |
Returns
Type | Description |
---|---|
System.Nullable<System.Int32> | The branching priority.
If no priority is specified, |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Exception is thrown if the model does not know a variable with name |
GetConstraint(String)
Returns the constraint named name
, or null
if this model instance contains no such constraint.
Declaration
public Constraint GetConstraint(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the constraint to search for. |
Returns
Type | Description |
---|---|
Constraint | The specified Constraint |
GetObjective(String)
Gets the Objective with name name
Declaration
public Objective GetObjective(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The objective name. This can either be the Name that was used for the Objective when it was added to the Model, OR the base64-name that was generated by the OPTANO.Modeling Framework. |
Returns
Type | Description |
---|---|
Objective | The Objective. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
GetPrioLevelByDenseOrderIndex(Int32)
Gets the n-th priority level, when sorted in optimization order.
Returns 0, if zeroBasedIndex
>= ObjectiveStagesCount.
Declaration
public int GetPrioLevelByDenseOrderIndex(int zeroBasedIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | zeroBasedIndex | The index n (zero-based). |
Returns
Type | Description |
---|---|
System.Int32 | The n-th priority level. |
GetVariable(String)
Returns the variable named name
, or null
if this model instance contains no such variable.
Declaration
public Variable GetVariable(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the variable to search for. |
Returns
Type | Description |
---|---|
Variable | The variable with Name equal to |
GetVariableNameToLongNameMapping()
Declaration
public Dictionary<string, string> GetVariableNameToLongNameMapping()
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.String> |
Max(IEnumerable<Expression>, Double)
Returns an Expression object representing the maximum of the specified expresssions.
Declaration
public static Expression Max(IEnumerable<Expression> expressions, double bigM)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Expression> | expressions | The expressions. |
System.Double | bigM | Large number, only used if the bounds of the variables of the expressions are non-finite |
Returns
Type | Description |
---|---|
Expression | An expression that represents the |
Min(IEnumerable<Expression>, Double)
Returns an Expression object respresenting the minimum of the specified expressions.
Declaration
public static Expression Min(IEnumerable<Expression> expressions, double bigM)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Expression> | expressions | The expressions. |
System.Double | bigM | Large number, only used if the bounds of the variables of the expressions are non-finite |
Returns
Type | Description |
---|---|
Expression | An expression that represents the |
Read(Stream, FileType)
Reads the specified file in the specified format and adds the content to the current model. Note that variable collections will be not restored. All variables will be UnhandledVariables instead.
Declaration
public void Read(Stream filestream, FileType fileType = FileType.MPS)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | filestream | The filestream. |
FileType | fileType | The file type ( |
RemoveConstraint(String)
Removes the Constraint or OperatorConstraint named name
from this model instance, or does nothing if this model instance contains no such constraint.
Declaration
public void RemoveConstraint(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the constraint to remove. |
RemoveConstraints(IEnumerable<String>)
Removes a set of constraints from this model instance.
Declaration
public void RemoveConstraints(IEnumerable<string> names)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.String> | names | Names of the constraints to remove. |
RemoveObjective(Objective)
Removes the given objective
.
Declaration
public void RemoveObjective(Objective objective)
Parameters
Type | Name | Description |
---|---|---|
Objective | objective | The objective to remove. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
RemoveObjective(String)
Removes the Objective with name name
Declaration
public void RemoveObjective(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The objective name. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
RemoveVariable(String)
Removes the variable named name
from this model instance, or does nothing if this model instance contains no such variable.
Declaration
public void RemoveVariable(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the variable to remove. |
RemoveVariables(IEnumerable<String>)
Removes a set of variables from this model instance.
Declaration
public void RemoveVariables(IEnumerable<string> names)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.String> | names | Names of the variables to remove. |
SetBranchingPriority(String, Nullable<Int32>)
Sets the branching priority for the given variable.
Declaration
public void SetBranchingPriority(string variableName, int? priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | variableName | The variable name. |
System.Nullable<System.Int32> | priority | The branching priority.
Priority must be greater or equal than |
UpdateVariablesFromModelContent(Dictionary<Variable, Double>)
Collects variables from Constraints (etc.) and adds them to the Variables.
This is triggered automatically
during Solve(Model, Dictionary<Variable, Double>), when Lazy is active.
Declaration
public void UpdateVariablesFromModelContent(Dictionary<Variable, double> variableValues = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<Variable, System.Double> | variableValues | Optional start values. |
Write(Stream, FileType)
Writes the model to the specified filestream.
Declaration
public void Write(Stream filestream, FileType fileType)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | filestream | The filestream. |
FileType | fileType | Type of the file. |