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

GDP => MINLP Transformation #3082

Merged
merged 19 commits into from
Feb 14, 2024
Merged

GDP => MINLP Transformation #3082

merged 19 commits into from
Feb 14, 2024

Conversation

michaelbynum
Copy link
Contributor

Summary/Motivation:

This PR adds a GDP transformation to convert a GDP to a MINLP by converting f(x) <= 0 on a disjunct to f(x)*y <= 0.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link
Contributor

@bernalde bernalde left a comment

Choose a reason for hiding this comment

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

@michaelbynum you are reading our minds! We were just discussing about this transformation with @emma58 @jsiirola and @ZedongPeng
The code looks great, but since we have the chance of creating a new reformulation, should we use it to give it a good name? GDP to MINLP is not specific enough (as BM and Hull might do that as well). How about binary multiplication? Short and descriptive!

@michaelbynum
Copy link
Contributor Author

Great suggestion! I like it!

Copy link

codecov bot commented Jan 12, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (42fa578) 88.28% compared to head (4206794) 88.31%.
Report is 134 commits behind head on main.

Files Patch % Lines
pyomo/gdp/plugins/binary_multiplication.py 98.64% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3082      +/-   ##
==========================================
+ Coverage   88.28%   88.31%   +0.03%     
==========================================
  Files         832      833       +1     
  Lines       92307    94881    +2574     
==========================================
+ Hits        81495    83798    +2303     
- Misses      10812    11083     +271     
Flag Coverage Δ
linux 86.22% <98.66%> (+0.18%) ⬆️
osx 75.69% <98.66%> (+0.13%) ⬆️
other 86.43% <98.66%> (+0.19%) ⬆️
win 83.65% <98.66%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@emma58 emma58 left a comment

Choose a reason for hiding this comment

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

Thanks so much for doing this, @michaelbynum! A few comments (most of which are my mistakes propagating, sorry...), but this generally looks good.

pyomo/gdp/plugins/gdp_to_minlp.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/gdp_to_minlp.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/gdp_to_minlp.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/gdp_to_minlp.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/binary_multiplication.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/binary_multiplication.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/binary_multiplication.py Outdated Show resolved Hide resolved
Comment on lines +84 to +86
rhs = 1 if parent_disjunct is None else parent_disjunct.binary_indicator_var
if obj.xor:
xorConstraint[index] = or_expr == rhs
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately (and this is my fault too), this isn't actually correct... It assumes that nested indicator variables are local, which is not necessarily true. The safest thing for now is to always set the rhs to 1 and to put the exactly-one constraint on the parent block (and transform from leaf to root, which I think you're already doing).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your point with putting the exactly-one constraint on the parent block (instead of the root disjunct's parent block) is that the exactly-one constraint needs to be transformed again if it is for a nested disjunction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm misunderstanding what the "root disjunct" is...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is putting the exactly-one constraint on the parent disjunct equivalent?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. It should be on the parent disjunct so that it does get transformed again.

pyomo/gdp/tests/test_binary_multiplication.py Outdated Show resolved Hide resolved
pyomo/gdp/tests/test_binary_multiplication.py Outdated Show resolved Hide resolved
@michaelbynum
Copy link
Contributor Author

Thanks for all the feedback, @emma58.

Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

Two really minor things, but nothing to prevent merging

pyomo/gdp/plugins/binary_multiplication.py Outdated Show resolved Hide resolved
pyomo/gdp/plugins/binary_multiplication.py Show resolved Hide resolved
@emma58
Copy link
Contributor

emma58 commented Feb 14, 2024

OK, what I just pushed should address @jsiirola's and @mrmundt's comments. If tests pass, we should merge!

@blnicho blnicho requested a review from mrmundt February 14, 2024 18:26
@blnicho blnicho merged commit 15e6e4a into Pyomo:main Feb 14, 2024
31 checks passed
@michaelbynum michaelbynum deleted the gdp_minlp branch February 25, 2024 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants