Created
March 8, 2017 13:22
-
-
Save 5nizza/f6c7c92d3182fd42797ab699accd1ece to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spot | |
import buddy | |
from typing import Set | |
from helpers.str_utils import remove_from_str | |
from interfaces.automata import Label, LABEL_TRUE | |
from interfaces.expr import Signal | |
def parse_bdd(bdd:buddy.bdd, d:spot.bdd_dict) -> Set[Label]: | |
""" Special cases: empty set for false, {LABEL_TRUE} for true """ | |
s = spot.bdd_format_set(d, bdd) | |
# s is like: <cancel:0, grant:0, req:0, go:0><cancel:1, grant:0, req:1, go:0> | |
if s == 'F': | |
return set() | |
if s == 'T': | |
return {LABEL_TRUE} | |
cube_tokens = s.split('><') | |
cube_tokens = map(lambda ct: remove_from_str(ct, '>< '), cube_tokens) | |
cube_labels = set() | |
for ct in cube_tokens: | |
# cancel:0, grant:0, req:0, go:0 | |
lit_tokens = ct.split(',') | |
lit_tokens = map(lambda lt: remove_from_str(lt, ', '), lit_tokens) | |
lbl = Label((Signal(sig_name), bool(int(sig_val))) | |
for sig_name, sig_val in | |
map(lambda tok: tok.split(':'), lit_tokens)) | |
cube_labels.add(lbl) | |
return cube_labels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment