Comments (17)
@schlichtanders In general, if you can avoid creating discontinuous variables for an optimization model, this will significantly improve solution performance. I don't think you will want to use the modulo function over an optimization variable, though. I may be wrong, but it sounds like your optimization model could be formulated better, which can reduce the combinatorics. If you can provide the simplest form of your model, we can discuss if it is necessary to support mixed-integer constraints inside disjuncts. However, the theory here for reformulating a disjunctive program to mip would need to be reviewed, especially in the case of the Hull
reformulation. Also, Indicator
reformulation would fail, but you could still do BigM
.
As a note to us devs @pulsipher @hdavid16: https://johnhooker.tepper.cmu.edu/milpmodeling2.pdf has some theory on mixed-integer disjunct constraints in Chapter 3, but it is not clear if this extends to nonlinear systems.
from disjunctiveprogramming.jl.
@hdavid16 can you give an example how to distinguish the day and the time-of-the-day without using Integer variables?
I haven't tested this code, but here's a quick example:
using DisjunctiveProgramming
m=GDPModel()
@variable(m,0<=start[1:2])
@variable(m,0<=finish[1:2])
@variable(m,0<=duration[1:2])
@variable(m,precedence[1:2],Logical) #precedence relation
@variable(m,start_day[1:10,1:2],Logical) #day task 1 or 2 starts (between 1 and 10)
#duration constraint
@constraint(m,[i in 1:2],duration[i] = finish[i] - start[i])
#disjunction to establish precedence between task 1 or task 2
@constraint(m,finish[1] <= start[2],Disjunct(precedence[1])) #task 1 goes first
@constraint(m,finish[2] <= start[1],Disjunct(precedence[2])) #task 2 goes first
@disjunction(m,precedence)
#disjunction to select what day each task starts
@constraint(m,[i in 1:10, j in 1:2], (i + 9/24) <= start[j] <= (i + 18/24), Disjunct(start_day[i,j])) #task j must be between 9:00 and 18:00 on the day it starts
@disjunction(m,[j in 1:2], start_day[:,j])
from disjunctiveprogramming.jl.
It may often be beneficial to have more variables (https://or.stackexchange.com/questions/3209/how-to-choose-between-high-number-of-binary-variables-or-fewer-number-of-integer). However, we will look into supporting this feature.
from disjunctiveprogramming.jl.
Hi @schlichtanders, can you please provide a short code example of what you would like to model exactly?
Most GDP reformulation techniques theoretically require that the constraints inside of disjunctions only contain continuous variables to be exact. This is why we enforce that condition. With a concrete example, we can try and see if there is a workaround.
from disjunctiveprogramming.jl.
Thank you for your help.
Here an example definition which throws the error Disjunct constraints cannot contain binary or integer variables.
using Jump
using DisjunctiveProgramming
n = 2
seconds_per_day = 24*60*60
model = GDPModel(HiGHS.Optimizer)
@variable(model, 0 <= start[1:n]) # this could also be split similar to durations
# unixepochs duration definition
@variable(model, 0 <= duration_days[1:n], Int)
@variable(model, 0 <= duration_secondsofday[1:n] <= seconds_per_day)
@expression(model, duration, seconds_per_day .* duration_days .+ duration_secondsofday)
# @variable(model, 0 <= duration)
# unixepochs end duration
@expression(model, finish, start .+ duration)
# disjunction
@variable(model, Y[1:2], Logical)
@constraint(model, finish[1] <= start[2], Disjunct(Y[1]))
@constraint(model, finish[2] <= start[1], Disjunct(Y[2]))
@disjunction(model, Y)
from disjunctiveprogramming.jl.
Why not define a variable finish
that is continuous and constrained to be greater than the start
variable of its same index? Can you elaborate why you are defining the number of days and adding a float to it instead of just having the start, finish, and duration variables be continuous and nonnegative?
from disjunctiveprogramming.jl.
Sure, it is about saving some constraints.
I need to know the number of days of the duration for some other constraints of mine. I could extract these from the difference between finish
and start
by some extra variables and constraints (using something like modulo).
Alternatively, I can put them into the definition like done, and avoid the extra constraints, which hopefully simplifys the model overall. But this approach fails when using Disjuncts
from disjunctiveprogramming.jl.
As a note to us devs @pulsipher @hdavid16: https://johnhooker.tepper.cmu.edu/milpmodeling2.pdf has some theory on mixed-integer disjunct constraints in Chapter 3, but it is not clear if this extends to nonlinear systems.
Based on this theory, we could potentially relax the requirement that all variables are continuous and provide an opt-out keyword that users would have to enable to disable the check at their own risk if the model is nonlinear.
from disjunctiveprogramming.jl.
Yes. However, I think there are many cases where a mixed integer constraint can be avoided in a disjunct, especially if it is being added to a continuous variable as in days + seconds.
from disjunctiveprogramming.jl.
I am now falling back to the following modulo MIP rewrite from JuMP Tips&Tricks
https://jump.dev/JuMP.jl/stable/tutorials/linear/tips_and_tricks/#Modulo
from disjunctiveprogramming.jl.
@schlichtanders feel free to share the simplest version of your model and we can discuss if this is necessary.
from disjunctiveprogramming.jl.
Based on this theory, we could potentially relax the requirement that all variables are continuous and provide an opt-out keyword that users would have to enable to disable the check at their own risk if the model is nonlinear.
@pulsipher if we decide to relax this, we will need to review the code for the BigM and Hull reformulations as any binaries (from nested disjuncts) are currently not disaggregated and binary bounds are also ignored when calculating tight M values (also for nested case)
from disjunctiveprogramming.jl.
@schlichtanders feel free to share the simplest version of your model and we can discuss if this is necessary.
There is actually not so much more to it.
Concretely, I have multiple time intervals which I want to make non-overlapping. I am using Disjuncts for this to model both possibilities that one interval is before or after the other.
In addition I would like to restrict the time-of-the-day of a respective interval, e.g. to start after 09:00 and end before 18:00 of an arbitrary day.
The modelling is a bit different than above, but also comes down to having an integer variable for the days.
from disjunctiveprogramming.jl.
@pulsipher if we decide to relax this, we will need to review the code for the BigM and Hull reformulations as any binaries (from nested disjuncts) are currently not disaggregated and binary bounds are also ignored when calculating tight M values (also for nested case)
Making it work for BigM should be straightforward at least.
from disjunctiveprogramming.jl.
@schlichtanders based on your description, I would greatly discourage using integer variables as they are not necessary. Using proper variable bounds and constraint definitions should allow you to model this as a linear GDP which will be more performant than if you start introducing integer variables.
from disjunctiveprogramming.jl.
@hdavid16 can you give an example how to distinguish the day and the time-of-the-day without using Integer variables?
from disjunctiveprogramming.jl.
Thank you very much for sharing this approach.
In terms of variables and constraints it adds a massive amount of extra constraints compared to the modulus version using Integer variables. I don't know about the precise implications for performance, but I guess that using Integer Variables in Disjuncts could still be an attractive alternative.
from disjunctiveprogramming.jl.
Related Issues (20)
- Have `@disjunction` automatically add exactly one constraints with a keyword argument HOT 10
- Add a short alias for `LogicalVariable`
- Replace DisjunctConstraint with Disjunct
- Support the new `:=` logical constraint syntax used by JuMP HOT 1
- Generalize to `AbstractModel`s
- Restore `JuMP.` prefixes HOT 2
- Add printing for references
- Support `JuMP.value` for `LogicalVariableRef`
- Support Methods to Query and Modify Disjunct Constraints
- Support Cardinality Constraints with Logical Expressions HOT 2
- Add Summarizing Printing Methods
- Update the disjunction macro to use new JuMP extension API HOT 3
- Is it possible to save a Logical variable if I have a disjunction of merely two alternatives? HOT 6
- Having a set of logical variables Y, is it possible to constraint them all to be equal? HOT 7
- Handle printing empty disjuncts HOT 1
- Error ... is not a valid logical variable reference. HOT 2
- [Documentation Request] What does `@disjunction(model, Y, exactly1=false)` actually do? HOT 15
- Is it possible to use this package to optimize the selection of indices for a vector? HOT 2
- Support cardinality clauses within more complex logic HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from disjunctiveprogramming.jl.