# Model

## Creating a `Model`

`Parametron.Model`

— Type.```
Model(optimizer)
```

Create a new `Model`

, representing an optimization problem to be solved by the optimizer `optimizer`

(a `MathOptInterface.AbstractOptimizer`

).

## Creating Decision variables

`Parametron.Functions.Variable`

— Method.```
Variable(m)
```

Create a new decision variable (`Variable`

) associated with the model.

## Adding constraints and an objective function

`Parametron.@constraint`

— Macro.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] ∈ ℤ)`

`Parametron.@objective`

— Macro.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;
```

`Parametron.setobjective!`

— Function.```
setobjective!(m, sense, expr)
```

Set the objective function and optimization sense (`Minimize`

or `Maximize`

).

## Solving

`Parametron.solve!`

— Function.```
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.

`Parametron.setdirty!`

— Function.```
setdirty!(model)
```

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

`Parametron.initialize!`

— Function.```
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`

.

`Parametron.update!`

— Function.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!`

.

## Accessing solver results

`Parametron.value`

— Function.```
value(m, x)
```

Return the value of variable `x`

as determined by the optimizer.

`Parametron.objectivevalue`

— Function.```
objectivevalue(m)
```

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

`Parametron.terminationstatus`

— Function.```
terminationstatus(m)
```

Return the termination status of the solver.

`Parametron.primalstatus`

— Function.```
primalstatus(m)
```

Return information regarding the primal of the problem.

`Parametron.dualstatus`

— Function.```
dualstatus(m)
```

Return information regarding the dual of the problem.