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

Need to delete NLconstraint after reformulating its respective perspective function when using CHR #7

Closed
hdavid16 opened this issue May 13, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@hdavid16
Copy link
Owner

This will require rebuilding the model or waiting until delete of an NLconstraint is supported: see jump-dev/JuMP.jl#2355

@hdavid16 hdavid16 added the bug Something isn't working label May 13, 2021
@odow
Copy link
Contributor

odow commented Jun 1, 2021

This will require rebuilding the model. We have no immediate plans to implement deletion of nonlinear constraints.

@hdavid16
Copy link
Owner Author

hdavid16 commented Jun 1, 2021

Yeah... that's what we'll have to do for now.

@blegat
Copy link

blegat commented Oct 27, 2021

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 c by a constraint where x is substituted by x / z where z is a variable. This can be achieved as follows:

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

@hdavid16
Copy link
Owner Author

Awesome! Many thanks. I will start using your trick for the constraint reformulation.

@odow
Copy link
Contributor

odow commented Oct 27, 2021

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.

@blegat
Copy link

blegat commented Oct 27, 2021

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.
At the moment, this issue blocking for this package so it might be worth trying even if it using internal JuMP function and hence might break.

@odow
Copy link
Contributor

odow commented Oct 27, 2021

we've discussed that offline

Ah cool. Just checking

hdavid16 added a commit that referenced this issue Mar 10, 2022
close Quadratic constraints that are modeled using `@constraint` #21
close Big-M for nonlinear constraints #20
close Need to delete NLconstraint after reformulating its respective perspective function when using CHR #7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants