-
Notifications
You must be signed in to change notification settings - Fork 3
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
Need to delete NLconstraint after reformulating its respective perspective function when using CHR #7
Comments
This will require rebuilding the model. We have no immediate plans to implement deletion of nonlinear constraints. |
Yeah... that's what we'll have to do for now. |
Here is a hacky workaround: julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
julia> @variable(model, x)
x
julia> c = @NLconstraint(model, exp(x + 1) <= 2)
exp(x + 1.0) - 2.0 ≤ 0
julia> println(model)
Feasibility
Subject to
exp(x + 1.0) - 2.0 ≤ 0 No suppose I want to replace constraint julia> @variable(model, z)
z
julia> expr = :(exp($x / $z + 1.0) - 2.0)
:(exp(x / z + 1.0) - 2.0)
julia> con = JuMP._NonlinearConstraint(JuMP._NonlinearExprData(model, expr), -Inf, 0.0)
JuMP._NonlinearConstraint(JuMP._NonlinearExprData(JuMP._Derivatives.NodeData[JuMP._Derivatives.NodeData(JuMP._Derivatives.CALL, 2, -1), JuMP._Derivatives.NodeData(JuMP._Derivatives.CALLUNIVAR, 12, 1), JuMP._Derivatives.NodeData(JuMP._Derivatives.CALL, 1, 2), JuMP._Derivatives.NodeData(JuMP._Derivatives.CALL, 5, 3), JuMP._Derivatives.NodeData(JuMP._Derivatives.MOIVARIABLE, 1, 4), JuMP._Derivatives.NodeData(JuMP._Derivatives.MOIVARIABLE, 2, 4), JuMP._Derivatives.NodeData(JuMP._Derivatives.VALUE, 1, 3), JuMP._Derivatives.NodeData(JuMP._Derivatives.VALUE, 2, 1)], [1.0, 2.0]), -Inf, 0.0)
julia> model.nlp_data.nlconstr[c.index.value] = con
JuMP._NonlinearConstraint(JuMP._NonlinearExprData(JuMP._Derivatives.NodeData[JuMP._Derivatives.NodeData(JuMP._Derivatives.CALL, 2, -1), JuMP._Derivatives.NodeData(JuMP._Derivatives.CALLUNIVAR, 12, 1), JuMP._Derivatives.NodeData(JuMP._Derivatives.CALL, 1, 2), JuMP._Derivatives.NodeData(JuMP._Derivatives.CALL, 5, 3), JuMP._Derivatives.NodeData(JuMP._Derivatives.MOIVARIABLE, 1, 4), JuMP._Derivatives.NodeData(JuMP._Derivatives.MOIVARIABLE, 2, 4), JuMP._Derivatives.NodeData(JuMP._Derivatives.VALUE, 1, 3), JuMP._Derivatives.NodeData(JuMP._Derivatives.VALUE, 2, 1)], [1.0, 2.0]), -Inf, 0.0)
julia> println(model)
Feasibility
Subject to
exp(x / z + 1.0) - 2.0 ≤ 0 |
Awesome! Many thanks. I will start using your trick for the constraint reformulation. |
I don't know how much @blegat has tested this or looked into it, but to clarify: doing so is extremely unsupported and may break in any future JuMP release. I'm also unsure if this breaks any internal assumptions JuMP makes around resolving nonlinear models, so this may silently return incorrect solutions. |
I cannot guarantee that this will work, it just seems that it might; we've discussed that offline and tried to worked this through at the INFORMS Annual Meeting. |
Ah cool. Just checking |
This will require rebuilding the model or waiting until delete of an NLconstraint is supported: see jump-dev/JuMP.jl#2355
The text was updated successfully, but these errors were encountered: