Show / Hide Table of Contents

    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
    System.Object
    VariableCollection
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    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 unique among all VariableCollections that are used in the given model. If name IsNullOrWhiteSpace, a base64 index will be generated automatically.

    VariableCollection.DebugNameGenerator debugNameGenerator

    A delegate that takes an object[] as input and produces a System.Text.StringBuilder as output. The generator will be used when NameHandling is true. The string that is produced by the StringBuilder will be prepended to the unique variable name. The objective is to make the generated Model more readable, especially when trying to fix bugs. By default, the NameHandling is set to false in order to reduce the amount of RAM required to store variable names.

    VariableCollection.BoundGenerator lowerBoundGenerator

    A generator function for the lower bound. If null is passed, 0 will be used as default lower bound for every variable.

    VariableCollection.BoundGenerator upperBoundGenerator

    A generator function for the upper bound. If null is passed, double.PositiveInfinity will be used as default upper bound for every non-binary variable. For variables, 1 will be used as upper bound.

    VariableCollection.VariableTypeGeneratorDelegate variableTypeGenerator
    VariableCollection.BranchingPriorityGenerator branchingPriorityGenerator

    The branching priority generator. Non-null result of the generator function will be passed as branching priority to the SolverBase, if different priorities are supported.

    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
    IVariableCollection.ExistingIndices

    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
    IVariableCollection.IndexValidationStyle

    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 index

    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
    IVariableCollection.Name

    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
    IVariableCollection.ValidIndices

    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
    IVariableCollection.Variables

    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
    IVariableCollection.VariableTypeGenerator

    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 index is not yet known.

    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
    IVariableCollection.IsVariableForIndexInstanciated(Object[])

    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)

    Implements
    IVariableCollection.SetVariableValues(IDictionary<String, Double>)

    Extension Methods

    ReflectionHelper.GetFieldValue(Object, String)
    ReflectionHelper.SetFieldValue(Object, String, Object)
    ExtensionMethods.Clone<T>(T)
    ExtensionMethods.ThrowIfArgumentIsNull<T>(T, String)
    Back to top Copyright © OPTANO GmbH generated with DocFX
    Privacy Policy | Impressum – Legal Notice