Class VariableCollection
This is essentially a helper class that allows you to model your Variables more intuitively.
It groups Variables with the same meaning.
In a mathematical model a VariableCollection is represented by a single symbol (like x); a variable by a symbol with indices (like x_{i,j}).
Some (optional) generators are used to calculate parameters for each of the VariableCollection's variable:
DebugNameGenerator
LowerBoundGenerator
UpperBoundGenerator
BranchingPriorityGenerator
Inheritance
Inherited Members
Namespace: OPTANO.Modeling.Optimization
Assembly: Optimization.dll
Syntax
[Serializable]
public class VariableCollection : IInternalVariableCollection, IVariableCollection
Constructors
VariableCollection(Model, String, VariableCollection.DebugNameGenerator, VariableCollection.BoundGenerator, VariableCollection.BoundGenerator, VariableCollection.VariableTypeGeneratorDelegate, VariableCollection.BranchingPriorityGenerator, VariableCollection.BranchingDirectionGenerator, IEnumerable[])
Initializes a new instance of the VariableCollection class.
Declaration
public VariableCollection(Model model, string name = "", VariableCollection.DebugNameGenerator debugNameGenerator = null, VariableCollection.BoundGenerator lowerBoundGenerator = null, VariableCollection.BoundGenerator upperBoundGenerator = null, VariableCollection.VariableTypeGeneratorDelegate variableTypeGenerator = null, VariableCollection.BranchingPriorityGenerator branchingPriorityGenerator = null, VariableCollection.BranchingDirectionGenerator branchingDirectionGenerator = null, params IEnumerable[] sets)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model | The model. |
| System.String | name | The name for this variable collection.
It must be |
| VariableCollection.DebugNameGenerator | debugNameGenerator | A delegate that takes an |
| VariableCollection.BoundGenerator | lowerBoundGenerator | A generator function for the lower bound.
If |
| VariableCollection.BoundGenerator | upperBoundGenerator | A generator function for the upper bound.
If |
| VariableCollection.VariableTypeGeneratorDelegate | variableTypeGenerator | |
| VariableCollection.BranchingPriorityGenerator | branchingPriorityGenerator | The branching priority generator.
Non- |
| VariableCollection.BranchingDirectionGenerator | branchingDirectionGenerator | The branching direction generator. |
| System.Collections.IEnumerable[] | sets | The index sets. |
Fields
_branchingDirectionGenerator
The branching direction generator.
Declaration
[NonSerialized]
protected VariableCollection.BranchingDirectionGenerator _branchingDirectionGenerator
Field Value
| Type | Description |
|---|---|
| VariableCollection.BranchingDirectionGenerator |
_branchingPriorityGenerator
The branching priority generator.
Declaration
[NonSerialized]
protected VariableCollection.BranchingPriorityGenerator _branchingPriorityGenerator
Field Value
| Type | Description |
|---|---|
| VariableCollection.BranchingPriorityGenerator |
_name
The name.
Declaration
protected readonly string _name
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
ExistingIndices
Gets the existing indices.
Declaration
public IEnumerable<object[]> ExistingIndices { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.Object[]> | The System.Collections.IEnumerable with all already known indices. I.e. all indices that have already been used to access this VariableCollection. |
Implements
ExistingVariables
Gets the set of all existing (i.e. already created) variables.
Declaration
public IEnumerable<Variable> ExistingVariables { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Variable> |
IndexValidationStyle
Gets or sets the IndexValidationStyle.
Changes the behavior of a VariableCollection. If set to true the VariableCollection will validate if an index belongs to the sets the VariableCollection is based on.
The check is computationally expensive and should only be performed when you debug a model.
If the style is changed to Heuristic, new hash sets will be generated from the current index sets. Otherwise, the hash sets will be cleared.
Declaration
public IndexValidationStyle IndexValidationStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| IndexValidationStyle |
Implements
Item[Object[]]
Gets the Variable with the specified index.
If the VariableCollection never was accessed with the index, a new variable will be generated.
Declaration
public Variable this[params object[] index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object[] | index | The index for the Variable that should be accessed. |
Property Value
| Type | Description |
|---|---|
| Variable | The variable for the given |
Name
Gets the name for this variable collection.
It must be unique among all VariableCollections that are used in a single Model.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Implements
ValidIndices
Gets an System.Collections.Generic.IEnumerable<T> that iterates over all valid index combinations for this VariableCollection.
Declaration
public IEnumerable<object[]> ValidIndices { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.Object[]> | The valid indices. |
Implements
Variables
Gets an System.Collections.IEnumerable that contains all existing Variables in this VariableCollection.
I.e. all variables that were generated when this VariableCollection was accessed with the variables index.
Declaration
public IEnumerable<Variable> Variables { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Variable> | The variables. |
Implements
VariableTypeGenerator
Gets a generator delegate that takes an index as input and returns the VariableType for the respective Variable.
Declaration
public VariableCollection.VariableTypeGeneratorDelegate VariableTypeGenerator { get; }
Property Value
| Type | Description |
|---|---|
| VariableCollection.VariableTypeGeneratorDelegate |
Implements
Methods
CreateAllVariables()
Creates all variables that can possibly be created based on the elements currently in the sets. Be aware, this might create a major bunch of variables. It is usally used for internal testing.
Declaration
public IEnumerable<Variable> CreateAllVariables()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Variable> | All variables in this VariableCollection. |
GetLongNameFromIndex(Object[])
If the model uses short names, the long name is generated from the given index.
Else, the name of the variable for the given index is returned.
Declaration
public string GetLongNameFromIndex(object[] index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object[] | index | The index. If the variable for the index has not been created yet, an exception will be thrown. |
Returns
| Type | Description |
|---|---|
| System.String | The System.String. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Thrown, if the |
IsVariableForIndexInstanciated(Object[])
Checks if a variable was created for the given index.
Declaration
public bool IsVariableForIndexInstanciated(params object[] index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object[] | index | The index. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True, if a variable was created. |
Implements
SetVariableValues(IDictionary<String, Double>)
Sets the Value for each Variable in this VariableCollection to the corresponding value in the values. The matching happens by string comparison with the Name.
Values will only be updated for Variables that are known to this VariableCollection. Other System.Collections.KeyValuePairs will be ignored. The same is true for Variables in this Collection, for which no matching element is contained in the values.
Declaration
public void SetVariableValues(IDictionary<string, double> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IDictionary<System.String, System.Double> | values | The values for the variables (e.g. coming from a Solution) |