Model

# Model

## Creating a `Model`

``````Model(optimizer)
``````

Create a new `Model`, representing an optimization problem to be solved by the optimizer `optimizer` (a `MathOptInterface.AbstractOptimizer`).

source

## Creating Decision variables

``````Variable(m)
``````

Create a new decision variable (`Variable`) associated with the model.

source

## Adding constraints and an objective function

Add a constraint to the model using operators `==`, `<=`, `>=`, or `in`/`∈`.

`in`/`∈` may only be used for single variables with a right hand side that is one of:

• `ℤ` or `Integers`
• `{0, 1}` or `ZeroOne`

Examples

The constraint `x >= zeros(2)` can be added to a model as follows:

``````julia> x = [Variable(model) for i = 1 : 2];

julia> @constraint(model, x >= zeros(2))``````

The constraint that variable `x[1]` should be an integer can be expressed using:

``julia> @constraint(model, x[1] ∈ ℤ)``
source

Set the objective function of the model.

Examples

Let `model` be a `Model` instance. The objective 'minimize x ⋅ x' can be added as follows:

``````julia> x = [Variable(model) for i = 1 : 2];

julia> @objective model Minimize x ⋅ x;``````
source
``````setobjective!(m, sense, expr)
``````

Set the objective function and optimization sense (`Minimize` or `Maximize`).

source

## Solving

``````solve!(m)
``````

Solve the model `m`. (Re-)evaluate constraint and objective expressions, update the optimizer's internal representation of the problem, and start the optimization procedure.

source
``````setdirty!(model)
``````

Mark all parameters associated with the model as 'dirty' (out of date), meaning they must be updated upon their next evaluation.

source
``````initialize!(m)
``````

Copy the problem to be solved to the optimizer.

Users should generally not need to call this function directly, as it is automatically called the first time `solve!` is called on a `Model`.

source

Re-evaluate the expressions used to build the constraints and objective function of `Model` `m`.

Users should generally not need to call this function directly, as it is automatically called in `solve!`.

source

## Accessing solver results

``````value(m, x)
``````

Return the value of variable `x` as determined by the optimizer.

source
``````objectivevalue(m)
``````

Return the value of the objective function at the solution found by the optimizer.

source
``````terminationstatus(m)
``````

Return the termination status of the solver.

source
``````primalstatus(m)
``````

Return information regarding the primal of the problem.

source
``````dualstatus(m)
``````

Return information regarding the dual of the problem.

source