Skip to content

[FileFormats.CBF] improve heuristic for when to write variable cones #2494

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

Merged
merged 1 commit into from
May 3, 2024
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: 3 additions & 1 deletion src/FileFormats/CBF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@
is_variable_cone = false
break
end
push!(data.variables_with_domain, xi)
end
str = _cone_string(data, S)
if !is_variable_cone
_add_function(data, f, S)
set = MOI.get(model, MOI.ConstraintSet(), ci)
push!(data.cones, (str, MOI.dimension(set)))
else
for xi in f.variables
push!(data.variables_with_domain, xi)
end

Check warning on line 163 in src/FileFormats/CBF/write.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/CBF/write.jl#L161-L163

Added lines #L161 - L163 were not covered by tests
push!(data.variable_cones, (f.variables, str))
end
end
Expand Down
47 changes: 47 additions & 0 deletions test/FileFormats/CBF/CBF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,53 @@ function test_write_variable_cones()
return
end

function test_write_variable_cones_with_conflicting_sets()
model = CBF.Model()
x, _ = MOI.add_constrained_variables(model, MOI.Nonnegatives(2))
y = MOI.add_variable(model)
f = MOI.VectorOfVariables([y, x[2]])
# The choice of Nonnegatives and Nonpositives is explicitly chosen because
# Nonnegatives are parsed before Nonpositives, and it tests that we can skip
# over a function containing `y`, and then constrain it in a later set.
MOI.add_constraint(model, f, MOI.Nonnegatives(2))
MOI.add_constraint(model, MOI.VectorOfVariables([y]), MOI.Nonpositives(1))
g = 1.0 * x[1] + 2.0 * x[2] + 3.0 * y
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{typeof(g)}(), g)
io = IOBuffer()
write(io, model)
seekstart(io)
@test read(io, String) == """
VER
3

OBJSENSE
MIN

VAR
3 2
L+ 2
L- 1

CON
2 1
L+ 2

OBJACOORD
3
0 1.0
1 2.0
2 3.0

ACOORD
2
0 2 1.0
1 1 1.0

"""
return
end

function test_roundtrip_ExponentialCone()
model = CBF.Model()
x, _ = MOI.add_constrained_variables(model, MOI.ExponentialCone())
Expand Down
Loading