Giter Site home page Giter Site logo

Is it possible to save a Logical variable if I have a disjunction of merely two alternatives? about disjunctiveprogramming.jl HOT 6 OPEN

schlichtanders avatar schlichtanders commented on August 16, 2024
Is it possible to save a Logical variable if I have a disjunction of merely two alternatives?

from disjunctiveprogramming.jl.

Comments (6)

pulsipher avatar pulsipher commented on August 16, 2024 1

Following up on this, I have run into a use case (the case study behind the FOCAPO-CPC paper) where using one variable significantly improves the performance for a linear model solved with Gurobi (i.e., the pre-solve is not able to reduce the problem size automatically). Hence, I will try to put together a PR soon to try to implement this feature.

from disjunctiveprogramming.jl.

hdavid16 avatar hdavid16 commented on August 16, 2024

Hi @schlichtanders , when adding a disjunction, the Exactly 1 logical variable is selected constraint is added (unless exactly1 = false in the disjunction macro). If you have a disjunction with 2 options, you will have Select exactly 1 option (y1 or y2) which will be formulated to the algebraic constraint y1 + y2 = 1. During presolve, the solver will likely replace y2 with 1-y1, which is essentially what you are describing. That way when y1 = 1 the first disjunct is selected, and when y1 = 0 (meaning y2 = 1) the second disjunct is selected.

So presolve will likely take care of reducing the variables from 2 to 1.

from disjunctiveprogramming.jl.

pulsipher avatar pulsipher commented on August 16, 2024

@hdavid16 I think it may be worth keeping this feature request open to only use one logical variable when there are two disjuncts. For linear/quadratic problems that are compatible with solver like Gurobi I agree that a presolver will likely take care of the redundancy. However, for general MINLP solvers I don't think this will be the case for most solvers. Hence, for nonlinear problems, I think this would be a worthy feature addition.

from disjunctiveprogramming.jl.

hdavid16 avatar hdavid16 commented on August 16, 2024

I don't think we should support it. This would complicate the syntax a bit. How would you define the second disjunct constraint? @constraint(m, x <= b, Disjunct(\neg Y))? We would have to support expressions inside the Disjunct tag. I don't know if it is worth taking such a shortcut.

from disjunctiveprogramming.jl.

pulsipher avatar pulsipher commented on August 16, 2024

I don't think we should support it. This would complicate the syntax a bit.... I don't know if it is worth taking such a shortcut.

I think this feature addition would be more than a convenient shortcut, but rather a way to construct better formulations.

How would you define the second disjunct constraint? @constraint(m, x <= b, Disjunct(\neg Y))? We would have to support expressions inside the Disjunct tag.

It would be a relatively simply feature addition to have Disjunct accept \neg Y and only that. Then we could add a flag to the data structure to know if the negation should be used on the indicator or not.

Alternatively, we could keep the user API the same and instead check when reformulating if there are only 2 disjuncts. If there are then we can reformulate using only one indicator variable instead of two. This could be an opt-in feature, to prevent any surprises.

from disjunctiveprogramming.jl.

hdavid16 avatar hdavid16 commented on August 16, 2024

Yeah, this could be a behind the scenes feature because it will only work if the disjunction is not Nested and the exactly1 relation is enforced on the logical variables. So letting the user do this has some gotchas

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.