Giter Site home page Giter Site logo

Need to delete NLconstraint after reformulating its respective perspective function when using CHR about disjunctiveprogramming.jl HOT 7 CLOSED

hdavid16 avatar hdavid16 commented on June 29, 2024
Need to delete NLconstraint after reformulating its respective perspective function when using CHR

from disjunctiveprogramming.jl.

Comments (7)

blegat avatar blegat commented on June 29, 2024 1

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

from disjunctiveprogramming.jl.

blegat avatar blegat commented on June 29, 2024 1

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.

from disjunctiveprogramming.jl.

odow avatar odow commented on June 29, 2024 1

we've discussed that offline

Ah cool. Just checking

from disjunctiveprogramming.jl.

odow avatar odow commented on June 29, 2024

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

from disjunctiveprogramming.jl.

hdavid16 avatar hdavid16 commented on June 29, 2024

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

from disjunctiveprogramming.jl.

hdavid16 avatar hdavid16 commented on June 29, 2024

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

from disjunctiveprogramming.jl.

odow avatar odow commented on June 29, 2024

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.

from disjunctiveprogramming.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.