Skip to content

Commit

Permalink
MathOptInterface -> MOI
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquim Garcia committed Nov 30, 2023
1 parent 95a24ce commit 1ab21af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions docs/src/Examples/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ for x_i in x
end
```

Now, let's consider 3 `MathOptInterface.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`:
Now, let's consider 3 `MOI.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`:

```@example moi1
w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0))
Expand Down Expand Up @@ -146,12 +146,12 @@ We declare the variable `x` as in a typical `JuMP` model:
@variable(model, x[i = 1:2] >= 0)
```

Now, let's consider 3 `MathOptInterface.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`:
Now, let's consider 3 `MOI.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`:

```@example jump1
@variable(model, y in MathOptInterface.Parameter(0.0))
@variable(model, z in MathOptInterface.Parameter(0.0))
@variable(model, w in MathOptInterface.Parameter(0.0))
@variable(model, y in MOI.Parameter(0.0))
@variable(model, z in MOI.Parameter(0.0))
@variable(model, w in MOI.Parameter(0.0))
```

Let's add the constraints. Notice that we treat parameters the same way we treat variables when writing the model:
Expand Down Expand Up @@ -246,9 +246,9 @@ const POI = ParametricOptInterface
model = Model(() -> ParametricOptInterface.Optimizer(HiGHS.Optimizer()))
@variable(model, x[i = 1:3] >= 0)
@variable(model, p1[i = 1:3] in MathOptInterface.Parameter(0.0))
@variable(model, p2[i = 1:3] in MathOptInterface.Parameter.([1, 10, 45]))
@variable(model, p3[i = 1:3] in MathOptInterface.Parameter.(ones(3)))
@variable(model, p1[i = 1:3] in MOI.Parameter(0.0))
@variable(model, p2[i = 1:3] in MOI.Parameter.([1, 10, 45]))
@variable(model, p3[i = 1:3] in MOI.Parameter.(ones(3)))
```

## JuMP Example - Dealing with parametric expressions as variable bounds
Expand All @@ -267,7 +267,7 @@ model = direct_model(POI.Optimizer(HiGHS.Optimizer()))
@constraint(model, x >= p)
```

Since parameters are treated like variables JuMP lowers this to MathOptInterface as `x - p >= 0` which is not a variable bound but a linear constraint.This means that the current representation of this problem at the solver level is:
Since parameters are treated like variables JuMP lowers this to MOI as `x - p >= 0` which is not a variable bound but a linear constraint.This means that the current representation of this problem at the solver level is:

```math
\begin{align}
Expand Down Expand Up @@ -343,7 +343,7 @@ MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MAX_SENSE)
obj_func = MOI.ScalarQuadraticFunction(
[MOI.ScalarQuadraticTerm(1.0, x, x)
MOI.ScalarQuadraticTerm(1.0, y, y)],
MathOptInterface.ScalarAffineTerm{Float64}[],
MOI.ScalarAffineTerm{Float64}[],
0.0,
)
MOI.set(
Expand Down
8 changes: 4 additions & 4 deletions docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ optimizer = POI.Optimizer(HiGHS.Optimizer())

### Parameters

A `MathOptInterface.Parameter` is a set used to define a variable with a fixed value that
can be changed by the user. It is analogous to `MathOptInterface.EqualTo`, but can be used
A `MOI.Parameter` is a set used to define a variable with a fixed value that
can be changed by the user. It is analogous to `MOI.EqualTo`, but can be used
by special methods like the ones in this package to remove the fixed variable from the
optimization problem. This permits the usage of multiplicative parameters in lienar models
and might speedup solves since the number of variables is reduced.

### Adding a new parameter to a model

To add a parameter to a model, we must use the `MOI.add_constrained_variable()` function, passing as its arguments the model and a `MathOptInterface.Parameter` with its given value:
To add a parameter to a model, we must use the `MOI.add_constrained_variable()` function, passing as its arguments the model and a `MOI.Parameter` with its given value:

```julia
y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0))
```

### Changing the parameter value

To change a given parameter's value, access its `VariableIndex` and set it to the new value using the `MathOptInterface.Parameter` structure.
To change a given parameter's value, access its `VariableIndex` and set it to the new value using the `MOI.Parameter` structure.

```julia
MOI.set(optimizer, POI.ParameterValue(), y, MOI.Parameter(2.0))
Expand Down

0 comments on commit 1ab21af

Please sign in to comment.