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

Add Case Study: Satisfiability #7

Open
grantjenks opened this issue Jan 14, 2019 · 3 comments
Open

Add Case Study: Satisfiability #7

grantjenks opened this issue Jan 14, 2019 · 3 comments

Comments

@grantjenks
Copy link
Owner

grantjenks commented Jan 14, 2019

"""Satisfiability and Propositional Logic

Consider the following constraints:

– Alice can only meet either on Monday, Wednesday or Thursday
– Bob cannot meet on Wednesday
– Carol cannot meet on Friday
– Dave cannot meet neither on Tuesday nor on Thursday
– Question: When can the meeting take place?

- Encode then into the following Boolean formula:

    (Mon ∨ Wed ∨ Thu) ∧ (¬Wed) ∧ (¬Fri) ∧ (¬Tue ∧ ¬Thu)

The meeting must take place on Monday

"""

import logging
from patternmatching import *

logging.basicConfig(format='%(message)s', level=logging.DEBUG)

options = [
    'monday', 'wednesday', 'thursday', 'X',
    'monday', 'tuesday', 'thursday', 'friday', 'X',
    'monday', 'tuesday', 'wednesday', 'thursday', 'X',
    'monday', 'wednesday', 'friday', 'X',
    True,
]

constraints = (
    padding + anyone * group('alice') + padding + 'X'
    + padding + anyone * group('bob') + padding + 'X'
    + padding + anyone * group('carol') + padding + 'X'
    + padding + anyone * group('dave') + padding + 'X'
    + like(lambda _: bound.alice == bound.bob == bound.carol == bound.dave)
)

assert match(options, constraints)  # <-- FAILS! and I don't know why :(
@grantjenks
Copy link
Owner Author

Idea: make a reduced repro for the bug, duhh!

@grantjenks
Copy link
Owner Author

This is a fine test case but lousy example. It is little more than combinatorial brute force for something that is easily solved in your head. It’s also embarrassingly slow. This may be possible but it’s not worth advertising.

@grantjenks
Copy link
Owner Author

Note that real SAT solvers have optimizers that make them far faster.

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

No branches or pull requests

1 participant