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

adding QuickXplain #416

Merged
merged 14 commits into from
Oct 18, 2023
Merged

adding QuickXplain #416

merged 14 commits into from
Oct 18, 2023

Conversation

IgnaceBleukx
Copy link
Collaborator

I implemented the original basic version of the QuickXplain algorithm of Junker:

Junker, Ulrich. "Preferred explanations and relaxations for over-constrained problems." AAAI-2004. 2004.

Copy link
Collaborator

@sourdough-bread sourdough-bread left a comment

Choose a reason for hiding this comment

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

Nice example, small improvements can be added for readibility and being closer to the original algorithm.

examples/advanced/quickxplain.py Show resolved Hide resolved
examples/advanced/quickxplain.py Outdated Show resolved Hide resolved
examples/advanced/quickxplain.py Show resolved Hide resolved
examples/advanced/quickxplain.py Outdated Show resolved Hide resolved
examples/advanced/quickxplain.py Outdated Show resolved Hide resolved
@IgnaceBleukx
Copy link
Collaborator Author

Added quickxplain also to the tools and implemented a naive version.
Should be ready to merge now imo.

Copy link
Collaborator

@sourdough-bread sourdough-bread left a comment

Choose a reason for hiding this comment

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

Some small improvements mostly for readability. Ready to be merged after changes.

from cpmpy.expressions.variables import NDVarArray
from cpmpy.transformations.get_variables import get_variables
from cpmpy.transformations.normalize import toplevel_list


def mus(soft, hard=[], solver="ortools"):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you are proposing improvements to MUS as well, then I would rename variable solver to solvername.

m = Model(hard+[assump.implies(candidates)]) # each assumption variable implies a candidate
s = SolverLookup.get(solver, m)
m = cp.Model(hard + [assump.implies(candidates)]) # each assumption variable implies a candidate
s = cp.SolverLookup.get(solver, m)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some thoughts for readability.
m -> model
s -> solver

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm only proposing changes for the quickXplain algo : )
But I do agree with your proposed improvements, so maybe we can put them in antoher PR?

return [dmap[a] for a in core]


def recurse_explain(soft, hard, delta, solver):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why you recurse_explain (resp. do_recursion) in the tools is embedded and not here ?
Change the function name to be consistent across both files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really, I wanted to stay very close to the original pseudocode of the paper in the example, while the tools-version has some subtle optimizations, plus embedding the recursive call ensures users cannot call the helper function themselves by accident.

tests/test_tools_mus.py Outdated Show resolved Hide resolved
tests/test_tools_mus.py Outdated Show resolved Hide resolved
cpmpy/tools/mus.py Outdated Show resolved Hide resolved
@IgnaceBleukx IgnaceBleukx merged commit 2c380db into master Oct 18, 2023
1 check passed
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