MathModel Class

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);

Definition

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

Methods

Equals
(Inherited from Object)
Finalize
(Inherited from Object)
GetHashCode
(Inherited from Object)
GetModelHtml Creates and returns the html documentation of the mathematical model.
GetModelLaTeX Creates and returns the LaTeX documentation of the mathematical model.
GetModelMarkdown Creates and returns the markdown documentation of the mathematical model.
GetType
(Inherited from Object)
LogToConsole Logs the mathematical model to the console.
MemberwiseClone
(Inherited from Object)
New Creates a new mathematical model builder.
ToString
(Inherited from Object)
WithAdditionalConstraint Creates a new mathematical model from this model by adding the given constraint.
WriteModelHtml Creates an html documentation of the mathematical model.
WriteModelLaTeX Creates a LaTeX documentation of the mathematical model.
WriteModelMarkdown Creates a markdown documentation of the mathematical model.

Fields

Definition Definition of the mathematical model; or of the modelled problem.
Name Name of the mathematical model; or of the modelled problem.

See Also