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

Support Logical Complements #118

Merged
merged 4 commits into from
Oct 4, 2024
Merged

Support Logical Complements #118

merged 4 commits into from
Oct 4, 2024

Conversation

pulsipher
Copy link
Collaborator

@pulsipher pulsipher commented Oct 1, 2024

This PR closes #106. It does so by adding the logical_complement keyword argument when creating logical variables. For instance, we can have:

@variable(model, Y1, Logical) # binary_variable(Y1) returns a single binary
@variable(model, Y2, Logical, logical_complement = Y1) # binary_variable(Y2) = 1 - binary_variable(Y1)

These logical variables can then be used as normal to build disjunctions, but the underlying binary expressions avoid adding an unnecessary variable.

This works with all reformulations, but currently has the limitation that logical variables used inside nested disjunctions cannot be logical complements.

@pulsipher pulsipher added the enhancement New feature or request label Oct 1, 2024
@pulsipher pulsipher requested a review from hdavid16 October 1, 2024 04:22
@pulsipher
Copy link
Collaborator Author

Later on, we could add the syntax:

@variable(model, Y1, Logical)
@variable(model, Y2 == ¬Y1, Logical) 

to make it more symbolic, but that can wait for another PR.

src/reformulate.jl Outdated Show resolved Hide resolved
src/variables.jl Outdated Show resolved Hide resolved
src/variables.jl Outdated Show resolved Hide resolved
src/variables.jl Outdated Show resolved Hide resolved
src/variables.jl Outdated Show resolved Hide resolved
src/variables.jl Outdated Show resolved Hide resolved
Copy link
Owner

@hdavid16 hdavid16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for putting this together. Added some minor comments. We can merge after they are addressed.

@pulsipher
Copy link
Collaborator Author

pulsipher commented Oct 3, 2024

Thanks, I have addressed the comments. The restriction on not specifying the fix or start value is to avoid conflicts with the variable it is the complement of.

Copy link
Owner

@hdavid16 hdavid16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to say "Fix its logical complement instead". Using "Try" makes it sound like that might not work. Also complement should be spelled with an e everywhere (not an i...we don't like compliments XD)

@pulsipher
Copy link
Collaborator Author

I think it would be better to say "Fix its logical complement instead". Using "Try" makes it sound like that might not work. Also complement should be spelled with an e everywhere (not an i...we don't like compliments XD)

Done.

@pulsipher pulsipher changed the title Support Logical Compliments Support Logical Complements Oct 3, 2024
Copy link
Owner

@hdavid16 hdavid16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks!

@pulsipher pulsipher merged commit 7bbee0c into master Oct 4, 2024
4 checks passed
@pulsipher pulsipher deleted the invert_logical branch October 4, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to save a Logical variable if I have a disjunction of merely two alternatives?
2 participants