Orx.MathProg Namespace

 

Classes

Constraint Constraint of a mathematical model.
ConstraintExpr A constraint expression which is composed of three parts:
  • lhs: a linear mathematical expression
  • relation: <= or >= or ==
  • rhs: a linear mathematical expression
ForAllSets Forall sets expression of a constraint defining its expansion.

Consider for instance the following big-m constraint.

C#
Constraint xyRelation =
    key("x-y relation")
    | "capacity of a location can be used only if it is opened"
    | forall(p)
    | x[p] <= M * y[p];
where "p" is a set defining the potential locations. This constraint will be generated for each element of the set "p"; i.e., for each potential location.
MathExpr A linear mathematical expression.
MathModel A methematical model, which is composed of:
  • a set of constraints, and

Below is a complete definition of a multi commodity minimum cost network flow problem on an adjacency graph.

C#
// sets
Set j = Set("j").Represents("a node of the network").HasElementsUntil(data.NumNodes);
Set i = Set("i").Represents("nodes which have an edge into node j").DependsOn(j).HasElements(j => data.TailsOf(j));
Set k = Set("k").Represents("nodes which have an edge from node j").DependsOn(j).HasElements(j => data.HeadsOf(j));
Set c = Set("c").Represents("a commodity to be transported").HasElementsUntil(data.NumCommodities);

// parameters
ParD2 capacity = Parameter("cap").Represents("capacity of arc (j,k)").HasIndices(j, k).HasValues(data.GetEdgeCapacity);
ParD2 nodeBalance = Parameter("b").Represents("equal to (negative of) demand of commodity c if j is its (source) sink node").HasIndices(c, j).HasValues(data.GetNodeBalance);
ParD3 cost = Parameter("cost").Represents("cost of unit flow of commodity c on arc (j, k)").HasIndices(j, k, c).HasValues(1);

// variables
VarD3 f = Variable("f").Represents("flow of commodity c on arc (j,k)").HasIndices(j, k, c).IsContinuous().IsNonnegative();

// constraints
Constraint conFlowBal = key("flowBal")
    | "flow balance constraint at node j"
    | forall(j)
    | sum(over(c, i), f[i, j, c]) - sum(over(c, k), f[j, k, c]) == nodeBalance[c, j];

Constraint conCapacity = key("capacity")
    | "capacity constraint of arc (j, k)"
    | forall(j, k)
    | sum(over(c), f[j, k, c]) <= capacity[j, k]; 

// objective
Objective totalCost = key("minFlowCost")
    | "minimize total flow cost"
    | minimize
    | sum(over(c, j, k), cost[j, k, c] * f[j, k, c]);

// mathematical model
var model =
    MathModel.New("multi-commodity mcnf problem")
    .Represents("multi commodity minimum cost network flow problem")
    .WithObjective(totalCost)
    .HasConstraints(conFlowBal, conCapacity);
MathProgExtensions Necessary extensions methods for enabling mathematical programming.
Objective An objective function of a mathematical program. It is composed of two parts:
  • a linear mathematical expression, and
  • a direction (minimize or maximize).
The following are some examples of objective functions:
C#
// i, j: nodes
// x[i, j]: arc flow variable
// cost[i, j]: unit flow cost on arc (i,j)
// fixedCost[i]: fixed cost of including node i in the network
Objective minFlowCost = minimize | sum(over(i, j), cost[i, j] * x[i, j]);
Objective minTotalCost = minimize | sum(over(i, j), cost[i, j] * x[i, j]) + sum(over(i), fixedCost[i] * y[i]);

// p: person; t: task
// utility[p, t]: utility of person p when assigned to task t
// fitness[p, t]: fitness of person p's skills to task t
// revenue[t]: revenue of completing task t
// x[p, t]: 1 if person p is assigned to task t; 0 o/w
MathExpr totalUtility = sum(over(p, t), utility[p, t] * x[p, t]);
MathExpr totalFitness = sum(over(p, t), fitness[p, t] * x[p, t]);
MathExpr totalRevenue = sum(over(p, t), revenue[t] * x[p, t]);

double weightUtility = 0.40;
double weightFitness = 0.35;
double weightRevenue = 0.25;

Objective weighted = maximize
                    | weightUtility * totalUtility + weightFitness * totalFitness + weightRevenue * totalRevenue
ParD0 A 0-dimensional (scalar) parameter symbol.

Parameters represents constants for the mathematical model, values of which can lazily be evaluated.

ParD1 A 1-dimensional (array) parameter symbol.

Parameters represents constants for the mathematical model, values of which can lazily be evaluated.

ParD2 A 2-dimensional (array) parameter symbol, having two indices.

Parameters represents constants for the mathematical model, values of which can lazily be evaluated.

ParD3 A 3-dimensional (array) parameter symbol, having three indices.

Parameters represents constants for the mathematical model, values of which can lazily be evaluated.

ParD4 A 4-dimensional (array) parameter symbol, having three indices.

Parameters represents constants for the mathematical model, values of which can lazily be evaluated.

Sca A scalar with a constant value in the mathematical programming sense. In other words, its value is known to the mathematical program; although its value might be lazily evaluated from an expression including sets or parameters.

Below is a list of example scalars.

C#
Sca s = 42;
Sca s = 4.2;
Sca s = i; // where i is a .
Sca s = 2 * i;
Sca s = M; // where M is a .
Sca s = demand[i]; // where demand is a .
Sca s = (i * demand[i] + 2) / density[i]; // where density also is a .
Set 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.
Summation Summation of a linear mathematical expression over a set of indices.

Some examples are as follows:

C#
sum(over(i),       y[i])
sum(over(j),       x[i, j])
sum(over(i, j),    cost[i, j] * x[i, j])
sum(over(i, j, c), cost[i, j] * x[i, j, c] + fixed[c] * y[i, j, c])
Summation indices are checked in constructor, and proper errors are provided. The following summation, for instance, leads to an exception due to set k in sum-over expression being unused in the summation expression.
C#
sum(over(i, k), y[i])
SumOverSets Sets to sum over a linear mathematical expression.
Term A linear mathematical term in the form of 'Sca · Var'. For instance:
  • C#
    2 * totalCost
    is a term where totalCost is of type VarD0.
  • C#
    cost[i, j] * x[i, j]
    is a term where cost is of type ParD2 and x is of type VarD2. Note that, given i and j are Sets; x[i, j] is a Var and cost[i, j] is a Sca.
  • C#
    2 * cost[i, j] / (1 + demand[i]) * y[j]
    is also a term. The scalar; i.e., the coefficient can be expressed as mathematical operations. Note that the order is not strict as long as linearity is satisfied. Above term for instance could also be expressed as:
    C#
    2 * cost[i, j] * y[j] / (1 + demand[i])
Var A scalar decision variable. For example:
  • totalCost which is of type VarD0 is also a Var;
  • y[i] representing whether or not item i is added to the knapsack is a Var where y is of type VarD1;
  • x[i, j] representing the amount of flow on arc (i,j) is a Var where x is of type VarD2.
VarD0 A 0-dimensional (scalar) variable symbol.
VarD1 A 1-dimensional (array) variable symbol.
VarD2 A 2-dimensional variable symbol, having two indices.
VarD3 A 3-dimensional variable symbol, having three indices.
VarD4 A 4-dimensional variable symbol, having three indices.

Structures

BoundsD0 Bounds of a 0-dimensional variable, VarD0.
BoundsD1 Bounds of a 1-dimensional variable, VarD1.
BoundsD2 Bounds of a 2-dimensional variable, VarD2.
BoundsD3 Bounds of a 3-dimensional variable, VarD3.
BoundsD4 Bounds of a 4-dimensional variable, VarD4.
ConstrKeyDefnForall Constraint builder state containing key, definition and forall expression.
Obsolete.
Dimension0 Zero-dimensional, scalar.
Dimension1 One-dimensional, vector.
Dimension2 Two-dimensional.
Dimension3 Three-dimensional.
Dimension4 Four-dimensional.
Direction Objective function builder state containing objective direction information.
Obsolete.
ModelBuilderDefinition Mathematical model builder containing key and definition information.
ModelBuilderKey Mathematical model builder containing key information.
ModelBuilderObjective Mathematical model builder containing key, definition and objective information.
ObjKeyDefnDir Objective function builder state containing key and objective direction information.
Obsolete.
ObjOrConstrKeyDefn Objective function or constraint builder state containing key and definition information.
Obsolete.
ParameterBuilderDefinition Parameter builder containing key and definition information.
Obsolete.
ParameterBuilderIndicesDim Parameter builder containing key, definition and indices information.
Obsolete.
ParameterBuilderKey Parameter builder containing key information.
Obsolete.
SetBuilderDefinition Set builder containing set key and definition information.
Obsolete.
SetBuilderDependsDim Set builder containing set key, definition and dependent sets information.
Obsolete.
SetBuilderKey Set builder containing set key information.
Obsolete.
SymbolKey Key of a mathematical programming symbol.
Obsolete.
VariableBuilderDefinition Variable builder containing key and definition information.
Obsolete.
VariableBuilderIndicesDim Variable builder containing key, definition and indices information.
Obsolete.
VariableBuilderKey Variable builder containing key information.
Obsolete.
VariableBuilderTypeDim Variable builder containing key, definition, indices and type information.
Obsolete.

Interfaces

IDimension Marker interface for variable or parameter dimensions.
ISolver Marker interface for solvers.

Enumerations

BoundsType Type of variable bounds.
ConstraintRelation Constraint relation.
ObjectiveDirection Objective function direction: minimize or maximize.
VariableType Variable type.