clingo-hmknf-test/example.py

34 lines
833 B
Python
Raw Permalink Normal View History

2022-06-29 16:06:09 -06:00
import clingo
2022-06-30 16:55:42 -06:00
PROGRAM = """
2022-06-29 16:06:09 -06:00
#theory o {
kterm {- : 0, unary };
&o/0 : kterm, any
}.
2022-06-30 16:55:42 -06:00
x :- &o{false}.
x :- &o{x}.
y :- &o{y}.
2022-06-29 16:06:09 -06:00
"""
class CheckAtoms:
def init(self, init: clingo.PropagateInit):
2022-06-30 16:55:42 -06:00
symbolic_lits = {atom: init.solver_literal(atom.literal) for atom in init.symbolic_atoms}
theory_lits = {init.solver_literal(atom.literal) for atom in init.theory_atoms}
overlap = tuple(atom for atom, lit in symbolic_lits.items() if lit in theory_lits)
2022-06-29 16:06:09 -06:00
2022-06-30 16:55:42 -06:00
if len(overlap) == 0:
2022-06-29 16:06:09 -06:00
print("There is no solver literal overlap")
else:
print("There is overlap")
2022-06-30 16:55:42 -06:00
print(*(atom.symbol for atom in overlap))
2022-06-29 16:06:09 -06:00
control = clingo.Control(["0"])
control.register_propagator(CheckAtoms())
2022-06-30 16:55:42 -06:00
control.add("base", [], PROGRAM)
2022-06-29 16:06:09 -06:00
control.ground([("base", [])])
control.solve()