コード例 #1
0
ファイル: __init__.py プロジェクト: pierg/crome
    def formula(
        self,
        formulatype: FormulaOutput = FormulaOutput.CNF
    ) -> Union[Tuple[str, Typeset], Tuple[List[str], Typeset]]:
        """Generate the formula"""

        if formulatype == FormulaOutput.CNF:
            return LogicTuple.and_([
                LogicTuple.or_([atom.formula() for atom in clause],
                               brakets=True) for clause in self.cnf
            ],
                                   brackets=False)

        if formulatype == FormulaOutput.ListCNF:
            return [
                Logic.or_([atom.string for atom in clause])
                for clause in self.cnf
            ], self.typeset

        if formulatype == FormulaOutput.DNF:
            return LogicTuple.or_([
                LogicTuple.and_([atom.formula() for atom in clause],
                                brackets=True) for clause in self.dnf
            ],
                                  brakets=False)
コード例 #2
0
ファイル: __init__.py プロジェクト: pierg/crome
    def extract_mutex_rules(typeset: Typeset, output=None) -> Union[Atom, Tuple[List[str], Typeset]]:
        """Extract Mutex rules from the Formula"""

        rules_str = []
        rules_typeset = Typeset()

        for mutex_group in typeset.mutex_types:
            or_elements = []
            if len(mutex_group) > 1:
                for mutex_type in mutex_group:
                    neg_group = mutex_group.symmetric_difference({mutex_type})
                    and_elements = [mutex_type.name]
                    for elem in neg_group:
                        and_elements.append(Logic.not_(elem.name))
                    or_elements.append(Logic.and_(and_elements, brackets=True))
                rules_str.append(Logic.g_(Logic.or_(or_elements, brackets=False)))
                rules_typeset |= Typeset(mutex_group)

        if len(rules_str) == 0:
            return None

        if output is not None and output == FormulaOutput.ListCNF:
            return rules_str, rules_typeset

        return Atom(formula=(Logic.and_(rules_str, brackets=True), rules_typeset), kind=AtomKind.MUTEX_RULE)
コード例 #3
0
ファイル: triggers_modified.py プロジェクト: pierg/crome
    def __init__(self, pre: Union[Atom, Boolean],
                 post: Union[Atom, Boolean],
                 active: Union[Atom, Boolean],
                 context: Union[Atom, Boolean] = None):
        new_typeset, pre, post, context, active = Trigger.process_bin_contextual_input(pre, post, context, active)

        c = Logic.and_([context, active])
        f = Logic.u_(Logic.or_([Logic.and_([c, pre]), Logic.not_(c)]), Logic.and_([c, post]))
        super().__init__(formula=(f, new_typeset))
コード例 #4
0
ファイル: __init__.py プロジェクト: pierg/crome
    def extract_adjacency_rules(typeset: Typeset, output=None) -> Union[Atom, Tuple[List[str], Typeset]]:
        """Extract Adjacency rules from the Formula"""

        rules_str = []
        rules_typeset = Typeset()

        for key_type, set_adjacent_types in typeset.adjacent_types.items():
            if isinstance(key_type, Boolean):
                """G(a -> X(b | c | d))"""
                rules_str.append(
                    Logic.g_(Logic.implies_(key_type.name, Logic.x_(Logic.or_([e.name for e in set_adjacent_types])))))
                rules_typeset |= Typeset({key_type})
                rules_typeset |= Typeset(set_adjacent_types)

        if len(rules_str) == 0:
            return None

        if output is not None and output == FormulaOutput.ListCNF:
            return rules_str, rules_typeset

        return Atom(formula=(Logic.and_(rules_str, brackets=True), rules_typeset), kind=AtomKind.ADJACENCY_RULE)