forked from potassco/eclingo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_preprocessor.pu
More file actions
33 lines (26 loc) · 1.14 KB
/
Copy path_preprocessor.pu
File metadata and controls
33 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import Set
import clingo
from clingo import Symbol
from eclingo.config import AppConfig
class Preprocessor:
def __init__(self, config: AppConfig, control: clingo.Control) -> None:
self._control = control
self._config = config
self._epistemic_to_test_mapping = self._control.epistemic_to_test_mapping
self.facts = set(self._control.facts())
self._epistemic_facts = self._generate_epistemic_facts(
self._epistemic_to_test_mapping, self.facts
)
def __call__(self):
self._add_epistemic_facts_to_control()
def _generate_epistemic_facts(self, epistemic_to_test, facts) -> Set[Symbol]:
epistemic_facts: Set[Symbol] = set()
for epistemic_literal, test_literal in epistemic_to_test.items():
if test_literal in facts:
epistemic_facts.add(epistemic_literal)
return epistemic_facts
def _add_epistemic_facts_to_control(self):
with self._control.symbolic_backend() as backend:
for fact in self._epistemic_facts:
backend.add_rule([fact], [], [], False)
# self._control.cleanup()