concretizer: simplify "fact" method (#21148)
The "fact" method before was dealing with multiple facts
registered per call, which was used when we were emitting
grounded rules from knowledge of the problem instance.
Now that the encoding is changed we can simplify the method
to deal only with a single fact per call.
(cherry picked from commit ba42c36f00
)
This commit is contained in:
parent
a59fcd60f5
commit
94bb37c107
@ -210,19 +210,6 @@ def print_cores(self):
|
|||||||
*sorted(str(symbol) for symbol in core))
|
*sorted(str(symbol) for symbol in core))
|
||||||
|
|
||||||
|
|
||||||
def _normalize(body):
|
|
||||||
"""Accept an AspAnd object or a single Symbol and return a list of
|
|
||||||
symbols.
|
|
||||||
"""
|
|
||||||
if isinstance(body, clingo.Symbol):
|
|
||||||
args = [body]
|
|
||||||
elif hasattr(body, 'symbol'):
|
|
||||||
args = [body.symbol()]
|
|
||||||
else:
|
|
||||||
raise TypeError("Invalid typee: ", type(body))
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
def _normalize_packages_yaml(packages_yaml):
|
def _normalize_packages_yaml(packages_yaml):
|
||||||
normalized_yaml = copy.copy(packages_yaml)
|
normalized_yaml = copy.copy(packages_yaml)
|
||||||
for pkg_name in packages_yaml:
|
for pkg_name in packages_yaml:
|
||||||
@ -280,19 +267,14 @@ def newline(self):
|
|||||||
|
|
||||||
def fact(self, head):
|
def fact(self, head):
|
||||||
"""ASP fact (a rule without a body)."""
|
"""ASP fact (a rule without a body)."""
|
||||||
symbols = _normalize(head)
|
symbol = head.symbol() if hasattr(head, 'symbol') else head
|
||||||
self.out.write("%s.\n" % ','.join(str(a) for a in symbols))
|
|
||||||
|
|
||||||
atoms = {}
|
self.out.write("%s.\n" % str(symbol))
|
||||||
for s in symbols:
|
|
||||||
atoms[s] = self.backend.add_atom(s)
|
|
||||||
|
|
||||||
self.backend.add_rule(
|
atom = self.backend.add_atom(symbol)
|
||||||
[atoms[s] for s in symbols], [], choice=self.cores
|
self.backend.add_rule([atom], [], choice=self.cores)
|
||||||
)
|
|
||||||
if self.cores:
|
if self.cores:
|
||||||
for s in symbols:
|
self.assumptions.append(atom)
|
||||||
self.assumptions.append(atoms[s])
|
|
||||||
|
|
||||||
def solve(
|
def solve(
|
||||||
self, solver_setup, specs, dump=None, nmodels=0,
|
self, solver_setup, specs, dump=None, nmodels=0,
|
||||||
|
Loading…
Reference in New Issue
Block a user