Exemple #1
0
    def __init__(self,
                 ls: Union[Atom, Boolean, List[Atom], List[Boolean]] = None):
        new_typeset, loc = CoreMovement.process_input(ls)

        new_typeset, loc = CoreMovement.process_input(ls)
        lor = list(loc)
        lor.reverse()
        n = len(loc)

        f = []
        """F(l1), F(l2), ...,F(ln)"""
        for l in loc:
            f.append(L.f_(l))
        """F(l1) & F(l2) & ... & F(ln)"""
        f1 = L.and_(f)

        f2 = []
        """1..n-1   !l_{i+1} U l_{i}"""
        for i, l in enumerate(loc[:n - 1]):
            f = L.u_(L.not_(loc[i + 1]), loc[i])
            f2.append(f)
        f2 = L.and_(f2)

        f3 = []
        """1..n-1   !l_{i} U l_{i} & X(!l_{i} U l_{i+1})"""
        for i, l in enumerate(loc[:n - 1]):
            f = L.u_(L.not_(loc[i]),
                     L.and_([loc[i],
                             L.x_(L.u_(L.not_(loc[i]), loc[i + 1]))]))
            f3.append(f)
        f3 = L.and_(f3)

        new_formula = L.and_([f1, f2, f3])

        super().__init__(formula=(new_formula, new_typeset))
Exemple #2
0
    def __init__(self, ls: Union[List[Atom], List[Boolean]] = None):

        new_typeset, loc = CoreMovement.process_input(ls)
        lor = list(loc)
        lor.reverse()
        n = len(loc)

        f1 = Logic.f_(lor[0])

        if len(ls) == 1:
            super().__init__(formula=(Logic.g_(f1), new_typeset))
            return
        """GF(l1 & F(l2 & ... F(ln))))"""
        for l in lor[1:]:
            f2 = Logic.and_([l, f1])
            f1 = Logic.f_(f2)
        f1 = Logic.g_(f1)

        f2 = []
        """1..n-1   !l_{i+1} U l_{i}"""
        for i, l in enumerate(loc[:n - 1]):
            f = Logic.u_(Logic.not_(loc[i + 1]), loc[i])
            f2.append(f)
        f2 = Logic.and_(f2)

        f3 = []
        """1..n   G(l_{(i+1)%n} -> X((!l_{(i+1)%n} U l_{i})))"""
        for i, l in enumerate(loc):
            f = Logic.g_(
                Logic.implies_(
                    loc[(i + 1) % n],
                    Logic.x_(Logic.u_(Logic.not_(loc[(i + 1) % n]), loc[i]))))
            f3.append(f)
        f3 = Logic.and_(f3)

        if len(loc) > 2:
            f4 = []
            """1..n   G(l_{(i+1)%n} -> X((!l_{(i+1)%n} U l_{i})))"""
            for i, l in enumerate(loc):
                f = Logic.g_(
                    Logic.implies_(
                        loc[i],
                        Logic.x_(Logic.u_(Logic.not_(loc[i]),
                                          loc[(i + 1) % n]))))
                f4.append(f)
            f4 = Logic.and_(f4)
            new_formula = Logic.and_([f1, f2, f3, f4])
        else:
            new_formula = Logic.and_([f1, f2, f3])

        super().__init__(formula=(new_formula, new_typeset))
Exemple #3
0
    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)
Exemple #4
0
    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))
Exemple #5
0
 def formula(self, type: FormulaType = FormulaType.SATURATED) -> (str, Typeset):
     expression, typeset = self.__base_formula
     if type == FormulaType.SATURATED:
         if self.__saturation is None:
             expression, typeset = self.__base_formula
         else:
             expression, typeset = LogicTuple.implies_(self.__saturation.formula(), self.__base_formula,
                                                       brackets=True)
     if self.negated:
         return Logic.not_(expression), typeset
     return expression, typeset
Exemple #6
0
    def check_satisfiability(formula: Tuple[str, Typeset]) -> bool:

        expression, typeset = formula

        if not isinstance(expression, str) or not isinstance(typeset, Typeset):
            raise AttributeError

        if expression == "TRUE":
            return True

        if expression == "FALSE":
            return False

        variables = Nuxmv.__convert_to_nuxmv(typeset)
        """Write the NuSMV file"""
        with open(Nuxmv.smvfile, 'w') as ofile:

            ofile.write('MODULE main\n')

            ofile.write('VAR\n')

            for v in list(set(variables)):
                ofile.write(f"\t{v};\n")

            ofile.write('\n')
            ofile.write('LTLSPEC ')
            ofile.write(str(Logic.not_(expression)))

            ofile.write('\n')

        try:
            output = subprocess.check_output(
                ['nuXmv', Nuxmv.smvfile],
                encoding='UTF-8',
                stderr=subprocess.DEVNULL).splitlines()

            output = [
                x for x in output
                if not (x[:3] == '***' or x[:7] == 'WARNING' or x == '')
            ]
            for line in output:
                if line[:16] == '-- specification':
                    if 'is false' in line:
                        print("\t\t\tSAT-YES:\t" + str(expression))
                        return True
                    elif 'is true' in line:
                        print("\t\t\tSAT-NO :\t" + str(expression))
                        return False

        except Exception as e:
            with open(Nuxmv.smvfile, 'r') as fin:
                print(fin.read())
            raise e
Exemple #7
0
    def __init__(self, l: Union[Specification, Boolean]):
        new_typeset, l = Trigger.process_uni_input(l)

        f = Logic.g_(Logic.not_(l))

        super().__init__(formula=(f, new_typeset))