Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 1.58 KB

variables.md

File metadata and controls

70 lines (52 loc) · 1.58 KB
CurrentModule = MathOptInterface
DocTestSetup = quote
    import MathOptInterface as MOI
end
DocTestFilters = [r"MathOptInterface|MOI"]

Variables

Add a variable

Use add_variable to add a single variable.

julia> x = MOI.add_variable(model)
MOI.VariableIndex(1)

add_variable returns a VariableIndex type, which is used to refer to the added variable in other calls.

Check if a VariableIndex is valid using is_valid.

julia> MOI.is_valid(model, x)
true

Use add_variables to add a number of variables.

julia> y = MOI.add_variables(model, 2)
2-element Vector{MathOptInterface.VariableIndex}:
 MOI.VariableIndex(2)
 MOI.VariableIndex(3)

!!! warning The integer does not necessarily correspond to the column inside an optimizer.

Delete a variable

Delete a variable using delete.

julia> MOI.delete(model, x)

julia> MOI.is_valid(model, x)
false

!!! warning Not all ModelLike models support deleting variables. A DeleteNotAllowed error is thrown if this is not supported.

Variable attributes

The following attributes are available for variables:

Get and set these attributes using get and set.

julia> MOI.set(model, MOI.VariableName(), x, "var_x")

julia> MOI.get(model, MOI.VariableName(), x)
"var_x"