-
Notifications
You must be signed in to change notification settings - Fork 53
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
Move fast dual method from MICOM #252
base: master
Are you sure you want to change the base?
Conversation
I'm a bit too far away from this at the moment, to be able to easily review. @KristianJensen can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either remove this, or lower the log level to debug, in my opinion.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.info("dual model has {} terms in objective".format(len(coefs))) | |
logger.info("dual model has %d terms in objective", len(coefs)) |
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_dual
anyway