Skip to content

Commit

Permalink
sanitize node identifiers before mpbn conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pauleve committed Jan 22, 2024
1 parent c307a17 commit 100e857
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bonesis0/asp_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,30 @@ def bounded_nb_clauses(d):
def obs_to_facts(pstate, obsid):
return [asp.Function("obs", [obsid, n, 2*v-1]) for (n,v) in pstate.items()]

def sanitize_identifier(nodeid):
if isinstance(nodeid, str):
nodeid = nodeid.replace("-","_")
else:
nodeid = f"x{nodeid}"
return nodeid

def dnfs_of_facts(fs, ns=""):
bn = {}
clause_func = f"{ns}clause"
constant_func = f"{ns}constant"
for d in fs:
if d.name == clause_func:
(i,cid,lit,sign) = list(map(py_of_symbol, d.arguments))
i = sanitize_identifier(i)
lit = sanitize_identifier(lit)
if i not in bn:
bn[i] = []
if cid > len(bn[i]):
bn[i] += [set() for j in range(cid-len(bn[i]))]
bn[i][cid-1].add((sign,lit))
elif d.name == constant_func and len(d.arguments) == 2:
(i,v) = list(map(py_of_symbol, d.arguments))
i = sanitize_identifier(i)
bn[i] = v == 1
return bn

Expand Down

0 comments on commit 100e857

Please sign in to comment.