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

Use dispatch in add single variable constraint #70

Closed
joaquimg opened this issue Feb 28, 2020 · 3 comments
Closed

Use dispatch in add single variable constraint #70

joaquimg opened this issue Feb 28, 2020 · 3 comments

Comments

@joaquimg
Copy link
Member

No description provided.

@guilhermebodin
Copy link
Collaborator

Can we close this? SingleVariable does not exist anymore in the current MOI versions.

@odow
Copy link
Member

odow commented Mar 1, 2024

Closing. This is okay:

function MOI.add_constraint(
model::Optimizer, f::MOI.VariableIndex, s::S
) where {S <: SCALAR_SETS}
info = _info(model, f)
if info.type == BINARY
lower, upper = _bounds(s)
if lower !== nothing
if lower > 1
error("The problem is infeasible")
end
end
if upper !== nothing
if upper < 0
error("The problem is infeasible")
end
end
if lower !== nothing && upper !== nothing
if (lower > 0 && upper < 1)
error("The problem is infeasible")
end
end
end
if S <: MOI.LessThan{Float64}
_throw_if_existing_upper(info.bound, info.type, S, f)
info.bound = info.bound == GREATER_THAN ? LESS_AND_GREATER_THAN : LESS_THAN
elseif S <: MOI.GreaterThan{Float64}
_throw_if_existing_lower(info.bound, info.type, S, f)
info.bound = info.bound == LESS_THAN ? LESS_AND_GREATER_THAN : GREATER_THAN
elseif S <: MOI.EqualTo{Float64}
_throw_if_existing_lower(info.bound, info.type, S, f)
_throw_if_existing_upper(info.bound, info.type, S, f)
info.bound = EQUAL_TO
else
@assert S <: MOI.Interval{Float64}
_throw_if_existing_lower(info.bound, info.type, S, f)
_throw_if_existing_upper(info.bound, info.type, S, f)
info.bound = INTERVAL
end
index = MOI.ConstraintIndex{MOI.VariableIndex, typeof(s)}(f.value)
MOI.set(model, MOI.ConstraintSet(), index, s)
return index
end

@odow odow closed this as completed Mar 1, 2024
@joaquimg
Copy link
Member Author

joaquimg commented Mar 1, 2024

For future note.
We are not closing because single variable does not exist.
The issue is the same but for variable index.
We are closing because it does not seem to be a bottleneck. Although it seems to be against the julia manual performance tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants