Skip to content

Instantly share code, notes, and snippets.

@rmela
Last active August 18, 2024 19:33
Show Gist options
  • Save rmela/a031f3f3fca92d3b5db1c473bdd3ca94 to your computer and use it in GitHub Desktop.
Save rmela/a031f3f3fca92d3b5db1c473bdd3ca94 to your computer and use it in GitHub Desktop.
Solution to frietkot problem
# solution to the Frietkot problem https://people.cs.kuleuven.be/~tias.guns/frietkot/ using pysat
from pysat.solvers import Solver
MAYONNAISE = 1
KETCHUP = 2
CURRY = 3
ANDALOUSE = 4
SAMURAI = 5
nora = [MAYONNAISE, KETCHUP ]
leander = [ -SAMURAI , MAYONNAISE ]
benjamin = [ -ANDALOUSE , -CURRY , -SAMURAI]
behrouz = [KETCHUP , CURRY , ANDALOUSE ]
guy = [ -KETCHUP , CURRY , ANDALOUSE ]
daan = [ -KETCHUP , -CURRY , ANDALOUSE ]
celine = [ -SAMURAI ]
anton = [ MAYONNAISE , -CURRY , -ANDALOUSE ]
danny = [ -MAYONNAISE , KETCHUP , ANDALOUSE , SAMURAI ]
luc = [ -MAYONNAISE , SAMURAI]
friends = [
nora,
leander,
benjamin,
behrouz,
guy,
daan,
celine,
anton,
danny,
luc
]
solver = Solver(name='m22')
for friend in friends:
solver.add_clause(clause=friend)
solver.solve()
print(solver.get_model())
# prints -1, 2, -3, 4, -5 -- which is
# !mayonnaise, ketchup, !curry_ketchup, andalouse, !samurai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment