Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/indicator_activate_on_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

The `IndicatorActiveOnFalseBridge` replaces an indicator constraint activated
on 0 with a variable ``z_0`` with the constraint activated on 1, with a variable ``z_1``.
It stores the added `variable_index` and added constraints:
It stores the added `variable` and added constraints:
- ``z_1 \\in \\mathbb{B}`` in `zero_one_cons`
- ``z_0 + z_1 == 1`` in `` in `disjunction_cons`
- The added `ACTIVATE_ON_ONE` indicator constraint in `indicator_cons_index`.
Expand All @@ -13,7 +13,7 @@ struct IndicatorActiveOnFalseBridge{
F<:MOI.AbstractVectorFunction,
S<:MOI.AbstractScalarSet,
} <: AbstractBridge
variable_index::MOI.VariableIndex
variable::MOI.VariableIndex
zero_one_cons::MOI.ConstraintIndex{MOI.SingleVariable,MOI.ZeroOne}
disjunction_cons::MOI.ConstraintIndex{
MOI.ScalarAffineFunction{T},
Expand Down
32 changes: 13 additions & 19 deletions src/Bridges/Constraint/indicator_sos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct IndicatorSOS1Bridge{
BC<:MOI.AbstractScalarSet,
MaybeBC<:Union{MOI.ConstraintIndex{MOI.SingleVariable,BC},Nothing},
} <: AbstractBridge
w_variable_index::MOI.VariableIndex
z_variable_index::MOI.VariableIndex
w_variable::MOI.VariableIndex
z_variable::MOI.VariableIndex
affine_func::MOI.ScalarAffineFunction{T}
bound_constraint_index::MaybeBC
sos_constraint_index::MOI.ConstraintIndex{MOI.VectorOfVariables,MOI.SOS1{T}}
Expand Down Expand Up @@ -88,7 +88,7 @@ function MOI.get(
attr::MOI.ConstraintFunction,
b::IndicatorSOS1Bridge{T},
) where {T}
z = b.z_variable_index
z = b.z_variable
terms = [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(one(T), z))]
for affine_term in b.affine_func.terms
push!(terms, MOI.VectorAffineTerm(2, affine_term))
Expand All @@ -102,7 +102,7 @@ function MOI.delete(model::MOI.ModelLike, bridge::IndicatorSOS1Bridge)
end
MOI.delete(model, bridge.sos_constraint_index)
MOI.delete(model, bridge.linear_constraint_index)
MOI.delete(model, bridge.w_variable_index)
MOI.delete(model, bridge.w_variable)
return
end

Expand Down Expand Up @@ -159,7 +159,7 @@ function MOI.get(::IndicatorSOS1Bridge, ::MOI.NumberOfVariables)
end

function MOI.get(b::IndicatorSOS1Bridge, ::MOI.ListOfVariableIndices)
return [b.w_variable_index]
return [b.w_variable]
end

function MOI.get(
Expand Down Expand Up @@ -231,16 +231,10 @@ function MOI.get(
attr::MOI.ConstraintPrimal,
bridge::IndicatorSOS1Bridge,
)
zvalue = MOI.get(
model,
MOI.VariablePrimal(attr.result_index),
bridge.z_variable_index,
)
wvalue = MOI.get(
model,
MOI.VariablePrimal(attr.result_index),
bridge.w_variable_index,
)
zvalue =
MOI.get(model, MOI.VariablePrimal(attr.result_index), bridge.z_variable)
wvalue =
MOI.get(model, MOI.VariablePrimal(attr.result_index), bridge.w_variable)
lin_primal_start = MOI.get(model, attr, bridge.linear_constraint_index)
return [zvalue, lin_primal_start - wvalue]
end
Expand All @@ -250,8 +244,8 @@ function MOI.get(
attr::MOI.ConstraintPrimalStart,
bridge::IndicatorSOS1Bridge,
)
zstart = MOI.get(model, MOI.VariablePrimalStart(), bridge.z_variable_index)
wstart = MOI.get(model, MOI.VariablePrimalStart(), bridge.w_variable_index)
zstart = MOI.get(model, MOI.VariablePrimalStart(), bridge.z_variable)
wstart = MOI.get(model, MOI.VariablePrimalStart(), bridge.w_variable)
lin_primal_start = MOI.get(model, attr, bridge.linear_constraint_index)
return [zstart, lin_primal_start - wstart]
end
Expand All @@ -264,8 +258,8 @@ function MOI.set(
) where {T}
zvalue = value[1]
lin_start = value[2]
MOI.set(model, MOI.VariablePrimalStart(), bridge.z_variable_index, zvalue)
wstart = MOI.get(model, MOI.VariablePrimalStart(), bridge.w_variable_index)
MOI.set(model, MOI.VariablePrimalStart(), bridge.z_variable, zvalue)
wstart = MOI.get(model, MOI.VariablePrimalStart(), bridge.w_variable)
wstart = wstart === nothing ? zero(T) : wstart
return MOI.set(
model,
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/quad_to_soc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function matrix_from_quadratic_terms(
index_to_variable_map = Dict{Int,MOI.VariableIndex}()
n = 0
for term in terms
for variable in (term.variable_index_1, term.variable_index_2)
for variable in (term.variable_1, term.variable_2)
if !(variable in keys(variable_to_index_map))
n += 1
variable_to_index_map[variable] = n
Expand All @@ -123,8 +123,8 @@ function matrix_from_quadratic_terms(
J = Int[]
V = T[]
for term in terms
i = variable_to_index_map[term.variable_index_1]
j = variable_to_index_map[term.variable_index_2]
i = variable_to_index_map[term.variable_1]
j = variable_to_index_map[term.variable_2]
push!(I, i)
push!(J, j)
push!(V, term.coefficient)
Expand Down
27 changes: 11 additions & 16 deletions src/Bridges/Constraint/semi_to_binary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ is replaced by:
"""
mutable struct SemiToBinaryBridge{T,S<:SemiSets{T}} <: AbstractBridge
semi_set::S
variable_index::MOI.VariableIndex
binary_variable_index::MOI.VariableIndex
variable::MOI.VariableIndex
binary_variable::MOI.VariableIndex
binary_constraint_index::MOI.ConstraintIndex{MOI.SingleVariable,MOI.ZeroOne}
lower_bound_index::MOI.ConstraintIndex{
MOI.ScalarAffineFunction{T},
Expand Down Expand Up @@ -131,12 +131,12 @@ function MOI.set(
MOI.modify(
model,
bridge.upper_bound_index,
MOI.ScalarCoefficientChange(bridge.binary_variable_index, -set.upper),
MOI.ScalarCoefficientChange(bridge.binary_variable, -set.upper),
)
MOI.modify(
model,
bridge.lower_bound_index,
MOI.ScalarCoefficientChange(bridge.binary_variable_index, -set.lower),
MOI.ScalarCoefficientChange(bridge.binary_variable, -set.lower),
)
return
end
Expand All @@ -146,7 +146,7 @@ function MOI.get(
attr::MOI.ConstraintFunction,
b::SemiToBinaryBridge{T},
) where {T}
return MOI.SingleVariable(b.variable_index)
return MOI.SingleVariable(b.variable)
end

function MOI.delete(model::MOI.ModelLike, bridge::SemiToBinaryBridge)
Expand All @@ -156,7 +156,7 @@ function MOI.delete(model::MOI.ModelLike, bridge::SemiToBinaryBridge)
MOI.delete(model, bridge.upper_bound_index)
MOI.delete(model, bridge.lower_bound_index)
MOI.delete(model, bridge.binary_constraint_index)
MOI.delete(model, bridge.binary_variable_index)
MOI.delete(model, bridge.binary_variable)
return
end

Expand All @@ -168,7 +168,7 @@ function MOI.get(
return MOI.get(
model,
MOI.VariablePrimal(attr.result_index),
bridge.variable_index,
bridge.variable,
)
end

Expand All @@ -185,7 +185,7 @@ function MOI.get(
attr::MOI.ConstraintPrimalStart,
bridge::SemiToBinaryBridge,
)
return MOI.get(model, MOI.VariablePrimalStart(), bridge.variable_index)
return MOI.get(model, MOI.VariablePrimalStart(), bridge.variable)
end

function MOI.set(
Expand All @@ -194,14 +194,9 @@ function MOI.set(
bridge::SemiToBinaryBridge{T},
value,
) where {T}
MOI.set(model, MOI.VariablePrimalStart(), bridge.variable_index, value)
MOI.set(model, MOI.VariablePrimalStart(), bridge.variable, value)
bin_value = ifelse(iszero(value), 0.0, 1.0)
MOI.set(
model,
MOI.VariablePrimalStart(),
bridge.binary_variable_index,
bin_value,
)
MOI.set(model, MOI.VariablePrimalStart(), bridge.binary_variable, bin_value)
MOI.set(
model,
MOI.ConstraintPrimalStart(),
Expand All @@ -224,7 +219,7 @@ function MOI.get(::SemiToBinaryBridge, ::MOI.NumberOfVariables)
end

function MOI.get(b::SemiToBinaryBridge, ::MOI.ListOfVariableIndices)
return [b.binary_variable_index]
return [b.binary_variable]
end

function MOI.get(
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ function modify_bridged_change(
for t in func.terms
coefs =
[(i, coef * t.coefficient) for (i, coef) in change.new_coefficients]
MOI.modify(b, obj, MOI.MultirowChange(t.variable_index, coefs))
MOI.modify(b, obj, MOI.MultirowChange(t.variable, coefs))
end
end
function modify_bridged_change(
Expand All @@ -1470,7 +1470,7 @@ function modify_bridged_change(
end
for t in func.terms
coef = t.coefficient * change.new_coefficient
MOI.modify(b, obj, MOI.ScalarCoefficientChange(t.variable_index, coef))
MOI.modify(b, obj, MOI.ScalarCoefficientChange(t.variable, coef))
end
end
function MOI.modify(
Expand Down
8 changes: 4 additions & 4 deletions src/FileFormats/CBF/CBF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function Base.write(io::IO, model::Model)
println(io, "OBJACOORD")
println(io, length(obj_function.terms))
for t in obj_function.terms
println(io, t.variable_index.value - 1, " ", t.coefficient)
println(io, t.variable.value - 1, " ", t.coefficient)
end
println(io)
end
Expand Down Expand Up @@ -220,7 +220,7 @@ function Base.write(io::IO, model::Model)
acoord,
(
num_rows + 4 - t.output_index,
t.scalar_term.variable_index.value,
t.scalar_term.variable.value,
t.scalar_term.coefficient,
),
)
Expand All @@ -235,7 +235,7 @@ function Base.write(io::IO, model::Model)
acoord,
(
num_rows + t.output_index,
t.scalar_term.variable_index.value,
t.scalar_term.variable.value,
t.scalar_term.coefficient,
),
)
Expand Down Expand Up @@ -316,7 +316,7 @@ function Base.write(io::IO, model::Model)
hcoord,
(
length(psd_side_dims),
t.scalar_term.variable_index.value,
t.scalar_term.variable.value,
i,
j,
t.scalar_term.coefficient,
Expand Down
2 changes: 1 addition & 1 deletion src/FileFormats/LP/LP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function write_function(
print_shortest(io, abs(term.coefficient))
end

print(io, " ", variable_names[term.variable_index])
print(io, " ", variable_names[term.variable])
end
end
return
Expand Down
6 changes: 3 additions & 3 deletions src/FileFormats/MOF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function moi_to_object(
)
return OrderedObject(
"coefficient" => foo.coefficient,
"variable" => name_map[foo.variable_index],
"variable" => name_map[foo.variable],
)
end

Expand All @@ -150,8 +150,8 @@ function moi_to_object(
)
return OrderedObject(
"coefficient" => foo.coefficient,
"variable_1" => name_map[foo.variable_index_1],
"variable_2" => name_map[foo.variable_index_2],
"variable_1" => name_map[foo.variable_1],
"variable_2" => name_map[foo.variable_2],
)
end

Expand Down
2 changes: 1 addition & 1 deletion src/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function extract_terms(
multiplier::Float64 = 1.0,
)
for term in func.terms
variable_name = v_names[term.variable_index]
variable_name = v_names[term.variable]
push!(
coefficients[variable_name],
(row_name, multiplier * term.coefficient),
Expand Down
12 changes: 6 additions & 6 deletions src/FileFormats/SDPA/SDPA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function Base.write(io::IO, model::Model{T}) where {T}

num_vars = MOI.get(model, MOI.NumberOfVariables())
println(io, num_vars)
function _check_variable_index(vi::MOI.VariableIndex)
function _check_variable(vi::MOI.VariableIndex)
if vi.value > num_vars
error(
"Non-contiguous variable indices not supported. This might " *
Expand Down Expand Up @@ -147,8 +147,8 @@ function Base.write(io::IO, model::Model{T}) where {T}
)
end
for term in obj.terms
_check_variable_index(term.variable_index)
c[term.variable_index.value] = term.coefficient
_check_variable(term.variable)
c[term.variable.value] = term.coefficient
end
if sense == MOI.MAX_SENSE
for i in eachindex(c)
Expand Down Expand Up @@ -194,8 +194,8 @@ function Base.write(io::IO, model::Model{T}) where {T}
end
end
for term in func.terms
vi = term.scalar_term.variable_index
_check_variable_index(vi)
vi = term.scalar_term.variable
_check_variable(vi)
α = term.scalar_term.coefficient
if !iszero(α)
_print_entry(vi.value, block, psd, term.output_index, α)
Expand Down Expand Up @@ -270,7 +270,7 @@ function Base.read!(io::IO, model::Model{T}) where {T}
if startswith(line, '"')
continue
end
# The lines starting with * should also be skipped
# The lines starting with * should also be skipped
# according to http://plato.asu.edu/ftp/sdpa_format.txt.
if startswith(line, '*')
# Exceptions for integer variables
Expand Down
20 changes: 8 additions & 12 deletions src/Test/UnitTests/basic_constraint_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,20 @@ end
variables(func::MOI.SingleVariable) = func.variable
variables(func::MOI.VectorOfVariables) = func.variables
function variables(func::MOI.ScalarAffineFunction)
return Set(term.variable_index for term in func.terms)
return Set(term.variable for term in func.terms)
end
function variables(func::MOI.VectorAffineFunction)
return Set(term.scalar_term.variable_index for term in func.terms)
return Set(term.scalar_term.variable for term in func.terms)
end
function variables(func::MOI.ScalarQuadraticFunction)
return Set(term.variable_index for term in func.affine_terms) ∪
Set(term.variable_index_1 for term in func.quadratic_terms)
return Set(term.variable_index_2 for term in func.quadratic_terms)
return Set(term.variable for term in func.affine_terms) ∪
Set(term.variable_1 for term in func.quadratic_terms)
return Set(term.variable_2 for term in func.quadratic_terms)
end
function variables(func::MOI.VectorQuadraticFunction)
return Set(term.scalar_term.variable_index for term in func.affine_terms) ∪
Set(
term.scalar_term.variable_index_1 for term in func.quadratic_terms
)
return Set(
term.scalar_term.variable_index_2 for term in func.quadratic_terms
)
return Set(term.scalar_term.variable for term in func.affine_terms) ∪
Set(term.scalar_term.variable_1 for term in func.quadratic_terms)
return Set(term.scalar_term.variable_2 for term in func.quadratic_terms)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/Test/contlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T}
if config.query
# Test that the modification of v has not affected the model
vars = map(
t -> t.variable_index,
t -> t.variable,
MOI.get(model, MOI.ConstraintFunction(), c).terms,
)
@test vars == [v[1], v[2]] || vars == [v[2], v[1]]
Expand Down
Loading