Example #1
0
 def can_provide_for(self, other):
     """Check if the set of behaviours is smaller or equal in the other set of behaviours but on the types"""
     variables = self.variables + other.variables
     proposition = Implies(self.formula, other.formula)
     for v in variables.list:
         proposition = proposition.replace(v.name, v.port_type)
     return check_validity(variables.get_nusmv_types(), proposition)
Example #2
0
 def __rshift__(self, other: 'LTL') -> 'LTL':
     """>> self
     Returns a new LTL that is the result of self -> other (implies)"""
     return LTL(
         formula=Implies(self.formula, other.formula),
         variables=Variables(self.variables | other.variables)
     )
Example #3
0
def get_controller(assumptions: str, guarantees: str, ins: str,
                   outs: str) -> Tuple[str, float]:
    try:
        print("Formatting TRUE as true for strix")
        assumptions = assumptions.replace("TRUE", "true")
        guarantees = guarantees.replace("TRUE", "true")
        params = ' -k --dot -f "' + Implies(
            assumptions,
            guarantees) + '" --ins="' + ins + '" --outs="' + outs + '"'
        command = strix_path + params
        print("\n\nRUNNING COMMAND:\n\n" + command + "\n\n")
        start_time = time.time()
        result = []
        timeout = 3600
        try:
            result = subprocess.check_output([strix_path + params],
                                             shell=True,
                                             timeout=timeout,
                                             encoding='UTF-8').split()
            # result = subprocess.check_output([strix_path + params], shell=True, encoding='UTF-8').split()
        except subprocess.TimeoutExpired as e:
            print("TIMEOUT for synthesis, more than 100 sec")
            raise SynthesisException("timeout", timeout=timeout)
        except Exception as e:
            print("EXCEPTION OCCURRED:\n" + str(e))
            print("FINISH EXCEPTION\n\n")
            raise SynthesisException("out_of_memory")
        exec_time = time.time() - start_time
        if result[0] == "REALIZABLE":
            dot_format = ""
            for i, line in enumerate(result):
                if "digraph" not in line:
                    continue
                else:
                    dot_format = "".join(result[i:])
                    break
            return dot_format, exec_time
        if result[0] == "UNREALIZABLE":
            return "UNREALIZABLE", exec_time
        else:
            print("\n\nSTRIX RESPONSE:\n\n")
            for l in result:
                print(l)
            raise Exception("Unknown strix response: " + result[0])
    except Exception as e:
        raise e
Example #4
0
def is_realizable(assumptions: str, guarantees: str, ins: str,
                  outs: str) -> bool:
    try:
        params = ' --realizability -f "' + Implies(
            assumptions,
            guarantees) + '" --ins="' + ins + '" --outs="' + outs + '"'
        command = strix_path + params
        print("\n\nRUNNING COMMAND:\n\n" + command + "\n\n")
        stdoutdata = subprocess.getoutput(command).splitlines()
        if stdoutdata[0] == "REALIZABLE":
            return True
        if stdoutdata[0] == "UNREALIZABLE":
            return False
        else:
            raise Exception("Unknown strix response: " + stdoutdata[0])
    except Exception as e:
        raise e
Example #5
0
def extract_saturated_guarantees_from(
        goals: Union[CGTGoal, List[CGTGoal]]) -> List[str]:
    if isinstance(goals, CGTGoal):
        goals = [goals]

    assumptions_goals = []
    guarantees_goals = []
    variables_goals = set()

    for goal in goals:
        goal_variables = set()
        goal_new_variables = set()
        goal_old_variables = set()
        assumptions_guarantee_pairs = []
        for contract in goal.contracts:
            a_boolean, a_new_vars, a_old_vars = traslate_boolean(
                str(contract.assumptions.formula))
            g_boolean, g_new_vars, g_old_vars = traslate_boolean(
                str(contract.guarantees.formula))
            vars = [v.name for v in contract.variables.list]
            goal_variables.update(vars)
            a_new_vars.extend(g_old_vars)
            a_old_vars.extend(g_old_vars)
            goal_new_variables.update(a_new_vars)
            goal_old_variables.update(a_old_vars)
            assumptions_guarantee_pairs.append((a_boolean, g_boolean))
        goal_variables = goal_variables - goal_old_variables
        goal_variables.update(goal_new_variables)

        assumptions_goal = Or([a for (a, goal) in assumptions_guarantee_pairs])
        guarantees_goal = And(
            [Implies(a, goal) for (a, goal) in assumptions_guarantee_pairs])

        guarantees_goals.append(guarantees_goal)
        variables_goals.update(goal_variables)

    return guarantees_goals
Example #6
0
 def saturate_with(self, assumptions):
     new_vars = deepcopy(self.variables)
     new_vars.extend(assumptions.variables)
     saturated = Implies(str(assumptions.formula), self.unsaturated)
     self.__init__(self.unsaturated, new_vars, saturated)