Set Class

A set / index to be used in constraints' forall expressions, summations' sum over expressions and finally as indices of variables and parameters having a dimension >= 1.

A set is constructed using builder pattern that can be initiated by Set(String) function. The following example demonstrates construction of sets.

C#
Set j = Set("j").Represents("Nodes of the network.").HasElementsUntil(data.NumNodes);
Set i = Set("i").Represents("Tails of edges incoming to j").DependsOn(j).HasElements(data.TailsOf);
Set k = Set("k").Represents("Heads of edges outgoing from j").DependsOn(j).HasElements(data.HeadsOf);

// or definitions can be omitted; however, they might be useful in automatically generated LaTex, html or text documentations.
Set j = Set("j").HasElementsUntil(data.NumNodes);
Set i = Set("i").DependsOn(j).HasElements(data.TailsOf);
Set k = Set("k").DependsOn(j).HasElements(data.HeadsOf);

The following flow balance constraint demonstrates the usage of the sets.

C#
Set i = ...;
Set j = ...;
VarD2 x = ...; // arc flow variable
ParD1 supply = ...; // parameter representing the supply at each node

Constraint flowBal = forall(i)
                    | sum(over(j), x[i, j]) == sum(over(j), x[j, i]) + supply[i];
Here, the sets i and j have the following functionalities:
  • forall(i): Used in constraint's forall expression to define the set of constraints to be created; a constraint will be created for every value of i.
  • over(j): Used in summation's sum-over expression to define the expressions to be summed; an expression will be created for every value of j.
  • x[i, j]: Used to represent the scalar variable from the two-dimensional variable symbol x. Note that x is of type VarD2 and requires two indices to scalarize. It is also possible to use expressions as indices such as "x[0, 0]", "x[i + j, 0]", "x[i, i]", etc. The values of the sets are lazy and are replaced by the value generated either by a summation's sum-over sets expression or by a constraint's forall sets expression. Here, value of i will be set by "forall(i)" expression of the constraint and j will be set by "over(j)" expression of the summation.
  • demand[i]: Similar to the scalarization of the variable; here the set i is used as the scalarization of "supply" which is of type ParD1.

Definition

Namespace: Orx.MathProg
Assembly: Orx.MathProg (in Orx.MathProg.dll) Version: 1.0.0
C#
public class Set
Inheritance
Object    Set

Properties

Key Key of the set.

Methods

Alias Creates and returns an alias of the set.

Alias allows to reuse a set definition in different places; such as i and j in the following flow balance constraint example.

C#
int numNodes = 10;
Set i = Set("i").Represents("A node of the network").HasElementsUntil(numNodes);
Set j = i.Alias();

Constraint flowBal = forall(i)
                    | sum(over(j), x[i, j]) == sum(over(j), x[j, i]) + supply[i];
Alias(String) Creates and returns an alias of the set; however with a new key (recommended).

Alias allows to reuse a set definition in different places; such as i and j in the following flow balance constraint example.

C#
int numNodes = 10;
Set i = Set("i").Represents("A node of the network").HasElementsUntil(numNodes);
Set j = i.Alias("j");

Constraint flowBal = forall(i)
                    | sum(over(j), x[i, j]) == sum(over(j), x[j, i]) + supply[i];
Equals
(Inherited from Object)
Finalize
(Inherited from Object)
GetHashCode
(Inherited from Object)
GetSummary Returns a summary information about the set; useful for debugging.
GetType
(Inherited from Object)
MemberwiseClone
(Inherited from Object)
ToString
(Inherited from Object)

Operators

Addition(Double, Set) Adds two scalars one of which is implicitly created from a set, and returns the resulting scalar.
Addition(Set, Set) Adds two scalars that are implicitly created from the sets, and returns the resulting scalar.
Addition(Set, Double) Adds two scalars one of which is implicitly created from a set, and returns the resulting scalar.
Division(Double, Set) Divides one scalar by another scalar, one of which is implicitly created from a set, and returns the resulting scalar.
Division(Set, Set) Divides a scalar by another which are implicitly created from the sets, and returns the resulting scalar.
Division(Set, Double) Divides one scalar by another scalar, one of which is implicitly created from a set, and returns the resulting scalar.
Multiply(Double, Set) Multiplies two scalars one of which is implicitly created from a set, and returns the resulting scalar.
Multiply(Set, Set) Multiplies two scalars that are implicitly created from the sets, and returns the resulting scalar.
Multiply(Set, Double) Multiplies two scalars one of which is implicitly created from a set, and returns the resulting scalar.
Subtraction(Double, Set) Subtracts one scalar from another scalar, one of which is implicitly created from a set, and returns the resulting scalar.
Subtraction(Set, Set) Substracts a scalar from another which are implicitly created from the sets, and returns the resulting scalar.
Subtraction(Set, Double) Subtracts one scalar from another scalar, one of which is implicitly created from a set, and returns the resulting scalar.
UnaryNegation(Set) Implicitly converts the set to a scalar which will take its value lazily; and negates the scalar.

Fields

Definition Definition of the set.
GeneratorDefinition Definition of the function that generates the set's elements.

See Also