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
Feature request: solve relaxation #1611
Comments
Make sure it's clear this means integer relaxation |
For reference, here's a version of code to relax integrality that handles the most typical cases. # model is a JuMP.Model
for v in all_variables(model)
if is_integer(v)
unset_integer(v)
# If applicable, also round the lower and upper bounds if they're not integer.
elseif is_binary(v)
unset_binary(v)
if has_lower_bound(v) && and lower_bound(v) > 0
set_lower_bound(v, 1)
else
set_lower_bound(v, 0)
end
if has_upper_bound(v) && and upper_bound(v) < 1
set_upper_bound(v, 0)
else
set_upper_bound(v, 1)
end
set_upper_bound(v, 1)
end
# If applicable, also handle semi-integer and semicontinuous.
end |
I'd really like to use this in one of my projects (and it's one of the things that's preventing me from rolling out a |
A better approach is a You could have something like (in JuMP): struct IntegralityCache
# anything that is needed
end
function relax_integrality(model::Model)::IntegralityCache
# things here
end
function enforce_integrality(model::Model, integrality_cache::IntegralityCache)
# things here
end Then, in user-code, it would look like integrality_cache= relax_integrality(model)
optimize!(model)
@show objective_value(model)
enforce_integrality(model, integrality_cache) See here for inspiration: That code doesn't handle semi-continuous/integer variables, or special ordered sets though. You will probably need something like: for (F, S) in list_of_constraint_types(model)
if S <: MOI.Seminteger
for constraint_index in all_constraints(model, F, S)
# relax semi-integer integrality
end
end
end To begin with, there is no need to write these functions inside JuMP. It's probably easier to develop in a separate script. Once you have something working, make a pull request, and we can workshop the tests and documentation :) |
I wouldn't mind if the initial version throws an error on semi-integer, semi-continuous and SOS (but is structured in a way that makes it possible to support them later). These these sets are used relatively rarely. |
I am very late for this, but I used exactly this workaround on my code. If there is interest this code can copied to inside a JuMP/MOI utility or spawn a very small package. |
This is on the milestone for 1.0, we'd like it in JuMP. PR welcome! |
For those following along, I've extracted a permalink to (what I think is) the code @henriquebecker91 is pointing to. See |
Oh sorry, I often remember to point to a specific repository/tree state, so what the link points does not change when I change the file. If my code is of any use for you, please make use of it, it is Unlicensed (Public Domain declaration), and so compatible with whatever license you use (even proprietary/commercial use). Unfortunately, I am late with my PhD stuff, and probably will be in a hurry until this year's end. After I finish my PhD, I would like to contribute more, but for now patching bugs in |
"Continuous relaxation" should only mean that constraints of the form
+1: IMO the "continuous relaxation" of such constraints is not always well-defined |
Try telling that to the stream of users we'll get asking why the relaxation of |
That depends on what we mean by "relaxation", right? |
Which part of the code snippet were you objecting to? |
I was objecting to
and to elseif is_binary(v)
unset_binary(v)
if has_lower_bound(v) && and lower_bound(v) > 0
set_lower_bound(v, 1)
else
set_lower_bound(v, 0)
end
if has_upper_bound(v) && and upper_bound(v) < 1
set_upper_bound(v, 0)
else
set_upper_bound(v, 1)
end
set_upper_bound(v, 1)
end which would strengthen, e.g., For the binary case, since JuMP allows users to specify bounds on top of the if is_binary(v)
unset_binary(v)
lb = has_lower_bound(v) ? lower_bound(v) : -Inf
ub = has_upper_bound(v) ? upper_bound(v) : Inf
set_lower_bound(v, max(0.0, lb))
set_upper_bound(v, min(1.0, ub))
end |
* Utility for relaxing integrality Closes #1611 * typo fix * error on semi-integer and semi-continuous
Like 0.18's
relaxation=True
flag tosolve()
.The text was updated successfully, but these errors were encountered: