# Optimization Modeling Language (OML)

Solver Foundation includes an algebraic modeling language called Optimization Modeling Language (OML) that is designed exclusively for modeling and solving. The language includes identifiers, comments, string literals, Boolean constants, and arbitrary numeric literals.

## Language Requirements

Identifiers must start with a letter or underscore, and can contain letters, underscores, and digits. Comments include both single line (//) and multiple line (/*...*/) variants. String literals are similar to the C# forms, including verbatim strings such as @"c:\\tmp" and escape sequences such as "Good\tDay\x0D\u000AMate". The Boolean constants are True and False. Arbitrary precision numeric literals can be specified using decimal notation (with or without a decimal point), hexadecimal notation (with a 0x prefix) and exponential notation. By default, numeric literals are translated to an (arbitrary precision) Integer or Rational constant. When a numeric literal is specified with an f or F suffix, the literal is translated to a Float constant. The identifiers Infinity, UnsignedInfinity, and Indeterminate are translated to the following Rational constants: PositiveInfinity, UnsignedInfinity, and Indeterminate.

## Model

A model in OML contains parameters, decisions, goals, and constraints. A model must have at least one Decisions section; all other sections are optional. You can include multiple parameters, decisions, goals, and constraints. A typical model looks like the following:

Model[

Parameters[...],

Decisions[...],

Goals[{Minimize|Maximize}[...]],

Constraints[...]

]

Objectives such as Maximize or Minimize are specified inside goals. If there are multiple objectives, the model is solved sequentially where the optimal value for the first object is found before considering subsequent objectives. In addition, you can specify a constant objective to find a feasible value for the decisions. Order does matter for goals, but other sections can be arbitrarily ordered.

### Parameters[domain, parameters…], Parameters[Sets ,sets…]

The Parameters section can contain single-valued parameters initialized with constant value or indexed parameters bound to data from Excel sheets.

Parameters[Integers, x=5]

Parameters[Reals, indexParam [set1]]

Sets that are used for indexed parameters and decisions are also declared in the Parameters section.

Parameters[Sets, set1, set2]

The values that belong to the set are determined when parameters using the set are data bound. A special type of parameter is a random parameter. Random parameters are either distribution-based or scenario-based. Most random distributions are defined by one or more arguments; for example a uniform distribution has a lower and upper bound. Random parameter arguments can be specified using constant values, or with data binding:

Parameters[UniformDistribution[900, 1000], Demand[Routes]]

Parameters[NormalDistribution, Demand[Routes]]

Scenario-based random parameters are defined by a set of scenarios. Each scenario has an associated probability of occurring and a value. The following Scenarios parameter represents the average speed of a driver along a highway:

Parameters[Scenarios[Reals[0, Infinity]],

Speed = {{0.1, 50}, {0.6, 55}, {0.2, 65}, {0.1, 75} }]

The following table lists the types of random parameters.

Parameter

Description

ScenariosParameter

Scenario-based random parameter.

UniformDistributionParameter

Uniform distribution with specified upper and lower bounds.

NormalDistributionParameter

Normal (Gaussian) distribution.

DiscreteUniformDistributionParameter

Discrete (integer) normal distribution.

ExponentialDistributionParameter

Exponential distribution with specified Poisson process rate.

GeometricDistributionParameter

Geometric distribution with specified Bernoulli trial success rate.

BinomialDistributionParameter

Binomial distribution with specified success rate and number of Bernoulli trials.

LogNormalDistributionParameter

Log-normal distribution.

### Decisions [domain, decisions...]

The Decisions section is used to specify the decisions for a model. All the decisions in a Decisions section have the same domain as indicated by the first argument. Add additional Decisions sections to define decisions with different domains. The following table lists the supported types for decisions.

Type

Description

Reals

Equivalent to Reals[-Infinity, Infinity]. Specifies real valued variables with no upper or lower bound.

Reals[lo, hi]

Specifies real valued variables with lower bound lo and upper bound hi. The lower bound may be -Infinity and the upper bound may be +Infinity.

Integers

Equivalent to Integers[-Infinity, +Infinity]. Specifies integer valued variables with no upper or lower bound.

Integers[lo, hi]

Specifies integer valued variables with lower bound Ceiling[lo] and upper bound Floor[hi]. The lower bound may be -Infinity and the upper bound may be +Infinity.

Booleans

Specifies Boolean valued variables.

Like Parameters, Decisions can be either single-valued or indexed decisions by sets previously declared in a Parameters section.

Decisions [Integers, x]

Decisions [Reals, indexedDecision [set1]]

Recourse decisions are used in stochastic models. Wrap Recourse around the name of a decision to turn it into a recourse decision.

Decisions [Reals, Recourse[x]]

Decisions [Reals, Recourse[indexedDecision [set1]]]

### Constraints[constraints...]

This section is used to specify any number of constraints, separated by commas.

Constraints[

x + y <= 10,

3 <= 2 * x + y <= 15

]

Constraints can be given names, which are used in reports and when exporting to other formats. The -> operator defines a name.

Constraints[

myConstraint -> x + y <= 10,

upperAndLower -> 3 <= 2 * x + y <= 15

]

### Goals[Maximize[objectives…]], Goals[Minimize[objectives…]]

These are used to specify a quantity that should be maximized or minimized.

An objective can be named using a rule, for example:

Goals[ Maximize[ Profit -> revenue – cost ]]

Goals[ Minimize[ Inventory -> produced – sold ]]

If multiple objectives are specified, they are considered in sequence. After an objective’s optimal value is found, the objective is constrained to its optimal value while subsequent objectives are considered. Certain solvers, such as the interior point solver, only use the first goal. The number of goals actually considered by the solver appears in the report.

## Submodels

Submodels encapsulate a set of decisions and constraints in a subproblem that can be instantiated multiple times. During each instantiation, all decisions and constraints are duplicated. A submodel is defined using a nested Model invocation with a label:

point -> Model[ Decisions[Reals, x, y] ]

A submodel is instantiated by defining a decision with the submodel’s name as the domain:

Decisions[point, start]

Individual decisions of a submodel instance are referred to in the outer model using brackets ([]):

start[x] == 3

## Operators

 Operator Description Abs Operator (Solver Foundation) Computes the absolute value of the argument. And Operator (Solver Foundation) Returns true only if all arguments are true. Annotation Operator (Solver Foundation) Adds metadata to a parameter, decision, constraint, or goal. ArcCos Operator (Solver Foundation) Returns the arccosine of the argument. ArcSin Operator (Solver Foundation) Returns the arcsine of the argument. ArcTan Operator (Solver Foundation) Returns the arctangent of the argument. AsInt Operator (Solver Foundation) Returns 1 if the argument is true and 0 if the argument is false. Ceiling Operator (Solver Foundation) Returns the smallest integer that is greater than or equal to the argument. Cos Operator (Solver Foundation) Returns the cosine of the argument. Cosh Operator (Solver Foundation) Returns the hyperbolic cosine of the argument. ElementOf Operator (Solver Foundation) Determines if an expression is contained in a table of expressions. Equal Operator (Solver Foundation) Returns true if all arguments are equal. Exp Operator (Solver Foundation) Returns e raised to the power specified by the argument. FilteredForeach Operator (Solver Foundation) Evaluates an expression for each combination of values of some iterator variables where a condition holds, and returns the results. FilteredSum Operator (Solver Foundation) Evaluates an expression for each combination of values of some iterator variables where a condition holds, and returns the sum results. Floor Operator (Solver Foundation) Returns the largest integer that is less than or equal to the argument. Foreach Operator (Solver Foundation) Evaluates an expression for each possible combination of values of some iterator variables, and returns all the results. Greater Operator (Solver Foundation) Returns true if the first argument is greater than the second argument. GreaterEqual Operator (Solver Foundation) Returns true if the first argument is greater than or equal to the second argument. If Operator (Solver Foundation) Returns the second or third argument, depending on whether the condition is true. Implies Operator (Solver Foundation) Returns true if the first argument is false, the second argument is true, or both. Less Operator (Solver Foundation) Returns true if the first argument is less than the second argument. LessEqual Operator (Solver Foundation) Returns true if the first argument is less than or equal to the second argument. Log Operator (Solver Foundation) Returns the natural (base e) logarithm of the argument. Log10 Operator (Solver Foundation) Returns the base 10 logarithm of the argument. Max Operator (Solver Foundation) Returns the largest argument. Min Operator (Solver Foundation) Returns the smallest argument. Minus Operator (Solver Foundation) Negates the argument. Mod Operator (Solver Foundation) Returns the remainder that results from division. ModTrunc Operator (Solver Foundation) Returns a truncated version of the remainder that results from division. Not Operator (Solver Foundation) Computes the logical inverse of its argument. Or Operator (Solver Foundation) Returns true if any argument is true. Plus Operator (Solver Foundation) Sums the arguments. Power Operator (Solver Foundation) Computes the exponential. Quotient Operator (Solver Foundation) Returns the integer quotient. Recourse Operator (Solver Foundation) Creates a recourse decision. Sin Operator (Solver Foundation) Returns the sine of the argument. Sinh Operator (Solver Foundation) Returns the hyperbolic sine of the argument. Sos1 Operator (Solver Foundation) Adds an SOS1 constraint. Sos2 Operator (Solver Foundation) Adds an SOS2 constraint. Sqrt Operator (Solver Foundation) Returns the square root of the argument. Sum Operator (Solver Foundation) Evaluates an expression for each possible combination of values of some iterator variables, and returns the sum of the results. Tan Operator (Solver Foundation) Returns the tangent of the argument. Tanh Operator (Solver Foundation) Returns the hyperbolic tangent of the argument. Times Operator (Solver Foundation) Computes the product of the arguments. Unequal Operator (Solver Foundation) Returns true if the first argument is not equal to the second argument.