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

Move fast dual method from MICOM #252

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cdiener
Copy link
Member

@cdiener cdiener commented May 2, 2023

  • description of feature/fix
  • tests added/passed
  • add an entry to the next release

This moves the fast dual methods from MICOM into optlang. This provides a quicker setup for primal/dual problems and multi-objective optimization.

Why?

  • easier licensing
  • method is not specific to MICOM
  • code was originally adapted from convert_linear_problem_to_dual anyway

@Midnighter
Copy link
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?

Copy link
Member

@Midnighter Midnighter left a 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:

  1. 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.
  2. 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?
  3. 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")
Copy link
Member

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.

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)
Copy link
Member

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)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.info("dual model has {} terms in objective".format(len(coefs)))
logger.info("dual model has %d terms in objective", len(coefs))

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.

2 participants