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

Revert removal of _try_constrain_variables_on_creation #2520

Merged
merged 1 commit into from
Jun 24, 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
72 changes: 72 additions & 0 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,75 @@
end

MOI.empty!(model::ModelFilter) = MOI.empty!(model.inner)

###
### These methods are deprecated, but unfortunately, they are used by a number
### of downstream packages and JuMP extensions.
###

function _try_constrain_variables_on_creation(

Check warning on line 699 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L699

Added line #L699 was not covered by tests
dest::MOI.ModelLike,
src::MOI.ModelLike,
index_map::IndexMap,
::Type{S},
) where {S<:MOI.AbstractVectorSet}
not_added = MOI.ConstraintIndex{MOI.VectorOfVariables,S}[]
for ci_src in

Check warning on line 706 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L705-L706

Added lines #L705 - L706 were not covered by tests
MOI.get(src, MOI.ListOfConstraintIndices{MOI.VectorOfVariables,S}())
f_src = MOI.get(src, MOI.ConstraintFunction(), ci_src)
if !allunique(f_src.variables)

Check warning on line 709 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L708-L709

Added lines #L708 - L709 were not covered by tests
# Can't add it because there are duplicate variables
push!(not_added, ci_src)
elseif any(vi -> haskey(index_map, vi), f_src.variables)

Check warning on line 712 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L711-L712

Added lines #L711 - L712 were not covered by tests
# Can't add it because it contains a variable previously added
push!(not_added, ci_src)

Check warning on line 714 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L714

Added line #L714 was not covered by tests
else
set = MOI.get(src, MOI.ConstraintSet(), ci_src)::S
vis_dest, ci_dest = MOI.add_constrained_variables(dest, set)
index_map[ci_src] = ci_dest
for (vi_src, vi_dest) in zip(f_src.variables, vis_dest)
index_map[vi_src] = vi_dest
end

Check warning on line 721 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L716-L721

Added lines #L716 - L721 were not covered by tests
end
end
return not_added

Check warning on line 724 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L723-L724

Added lines #L723 - L724 were not covered by tests
end

function _try_constrain_variables_on_creation(

Check warning on line 727 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L727

Added line #L727 was not covered by tests
dest::MOI.ModelLike,
src::MOI.ModelLike,
index_map::IndexMap,
::Type{S},
) where {S<:MOI.AbstractScalarSet}
not_added = MOI.ConstraintIndex{MOI.VariableIndex,S}[]
for ci_src in

Check warning on line 734 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L733-L734

Added lines #L733 - L734 were not covered by tests
MOI.get(src, MOI.ListOfConstraintIndices{MOI.VariableIndex,S}())
f_src = MOI.get(src, MOI.ConstraintFunction(), ci_src)
if haskey(index_map, f_src)

Check warning on line 737 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L736-L737

Added lines #L736 - L737 were not covered by tests
# Can't add it because it contains a variable previously added
push!(not_added, ci_src)

Check warning on line 739 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L739

Added line #L739 was not covered by tests
else
set = MOI.get(src, MOI.ConstraintSet(), ci_src)::S
vi_dest, ci_dest = MOI.add_constrained_variable(dest, set)
index_map[ci_src] = ci_dest
index_map[f_src] = vi_dest

Check warning on line 744 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L741-L744

Added lines #L741 - L744 were not covered by tests
end
end
return not_added

Check warning on line 747 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L746-L747

Added lines #L746 - L747 were not covered by tests
end

function _copy_free_variables(dest::MOI.ModelLike, index_map::IndexMap, vis_src)
if length(vis_src) == length(index_map.var_map)
return # All variables already added

Check warning on line 752 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L750-L752

Added lines #L750 - L752 were not covered by tests
end
x = MOI.add_variables(dest, length(vis_src) - length(index_map.var_map))
i = 1
for vi in vis_src
if !haskey(index_map, vi)
index_map[vi] = x[i]
i += 1

Check warning on line 759 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L754-L759

Added lines #L754 - L759 were not covered by tests
end
end
@assert i == length(x) + 1
return

Check warning on line 763 in src/Utilities/copy.jl

View check run for this annotation

Codecov / codecov/patch

src/Utilities/copy.jl#L761-L763

Added lines #L761 - L763 were not covered by tests
end
Loading