Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileFormats.CBF] use add_constrained_variables when reading #2476

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
40 changes: 16 additions & 24 deletions src/FileFormats/CBF/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,40 +133,32 @@ end
function _read_PSDVAR(io::IO, model::Model, data::_CBFReadData)
for _ in 1:_read(io, Int)
side_dim = _read(io, Int)
cone_dim = div(side_dim * (side_dim + 1), 2)
psd_vars_k = MOI.add_variables(model, cone_dim)
push!(data.psd_vars, psd_vars_k)
MOI.add_constraint(
model,
MOI.VectorOfVariables(psd_vars_k),
MOI.PositiveSemidefiniteConeTriangle(side_dim),
)
set = MOI.PositiveSemidefiniteConeTriangle(side_dim)
x, _ = MOI.add_constrained_variables(model, set)
push!(data.psd_vars, x)
end
return
end

function _read_VAR(io::IO, model::Model, data::_CBFReadData)
num_var, num_lines = _read(io, Int, Int)
append!(data.scalar_vars, MOI.add_variables(model, num_var))
var_idx = 0
_, num_lines = _read(io, Int, Int)
for _ in 1:num_lines
cone_str, cone_dim = _read(io, String, Int)
set = _cbf_to_moi_cone(data, cone_str, cone_dim)
if cone_str == "F"
var_idx += cone_dim
continue # Free cones (no constraint).
end
indices = 1:cone_dim
if cone_str == "EXP" || cone_str == "EXP*"
indices = (3:-1:1)
# Free cones (no constraint).
append!(data.scalar_vars, MOI.add_variables(model, cone_dim))
elseif cone_str == "EXP" || cone_str == "EXP*"
# The convention in CBF is the reverse of MOI, so we cannot use
# add_constrained_variables.
x = MOI.add_variables(model, 3)
append!(data.scalar_vars, x)
MOI.add_constraint(model, MOI.VectorOfVariables(reverse(x)), set)
else
x, _ = MOI.add_constrained_variables(model, set)
append!(data.scalar_vars, x)
end
MOI.add_constraint(
model,
MOI.VectorOfVariables(data.scalar_vars[var_idx.+indices]),
_cbf_to_moi_cone(data, cone_str, cone_dim),
)
var_idx += cone_dim
end
@assert var_idx == num_var
return
end

Expand Down
Loading