Open
Conversation
Member
|
I'm a bit too far away from this at the moment, to be able to easily review. @KristianJensen can you take a look? |
Midnighter
reviewed
Jul 18, 2024
Member
There was a problem hiding this comment.
I'm not experienced with the dual problem representation, so I can't review for correctness at the moment. However, I do trust you on that part.
My take on the code is the following:
- I know you prefer efficiency, but I think logically it would be clearer to first check the model for validity, i.e., loop through constraints and variables at the beginning and raise an exception before any modifications are made.
- In the spirit of other functions, should this one be called
add_fast_dual? Since it adds constraints and variables rather than returning a copy of the original model with modifications? - In addition to moving out validation, I would also introduce helper functions. One that handles a constraint and another that handles a variable. Perhaps a third that works on the objective. It would improve the structure and readability.
So in semi-pseudo code:
for constr in model.constraints:
check_valid_constraint(constr)
for var in model.variables:
check_valid_variable(var)
for constr in model.constraints:
add_dual_constraint(constr)
for var in model.variables:
add_dual_variable(var)
add_dual_objective(model.objective)| The coefficients for the new dual objective. | ||
|
|
||
| """ | ||
| logger.info("adding dual variables") |
Member
There was a problem hiding this comment.
Either remove this, or lower the log level to debug, in my opinion.
Suggested change
| logger.info("adding dual variables") | |
| logger.debug("adding dual variables") |
| "Non-linear problems are not supported: " + str(constraint) | ||
| ) | ||
| if constraint.lb is None and constraint.ub is None: | ||
| logger.debug("skipped free constraint %s" % constraint.name) |
Member
There was a problem hiding this comment.
Here, I'm wondering if it is better to have it at warning level?
| for vid, coef in dual_objective.items() | ||
| if coef != 0 | ||
| } | ||
| logger.info("dual model has {} terms in objective".format(len(coefs))) |
Member
There was a problem hiding this comment.
Suggested change
| logger.info("dual model has {} terms in objective".format(len(coefs))) | |
| logger.info("dual model has %d terms in objective", len(coefs)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This moves the fast dual methods from MICOM into optlang. This provides a quicker setup for primal/dual problems and multi-objective optimization.
Why?
convert_linear_problem_to_dualanyway