Esempio n. 1
0
    def realize_to_controller(self):
        """Realize the goal into a Controller object"""

        if self.controller is not None:
            return

        if self.session_name is None:
            folder_name = f"{self.s_controller_folder_name}/{self.goal_folder_name}"
        else:
            folder_name = f"{self.session_name}/{self.s_controller_folder_name}/{self.goal_folder_name}"

        try:
            controller_info = self.specification.get_controller_info()
            a, g, i, o = controller_info.get_strix_inputs()
            controller_synthesis_input = StringMng.get_controller_synthesis_str(
                controller_info)
            Store.save_to_file(controller_synthesis_input, "controller.txt",
                               folder_name)
            realized, kiss_mealy, time = Strix.generate_controller(a, g, i, o)

            if not realized:
                controller_info = self.specification.get_controller_info(
                    world_ts=self.__world.typeset)
                a, g, i, o = controller_info.get_strix_inputs()
                controller_synthesis_input = StringMng.get_controller_synthesis_str(
                    controller_info)
                Store.save_to_file(controller_synthesis_input,
                                   "controller.txt", folder_name)
                realized, kiss_mealy, time = Strix.generate_controller(
                    a, g, i, o)

            self.__realizable = realized

            if realized:
                Store.save_to_file(kiss_mealy, "controller_kiss", folder_name)
                # Store.generate_eps_from_dot(dot_mealy, "controller", folder_name)
            else:
                Store.save_to_file(kiss_mealy, "controller_inverted_kiss",
                                   folder_name)
                # Store.generate_eps_from_dot(dot_mealy, "controller_inverted", folder_name)

            self.__controller = Controller(mealy_machine=kiss_mealy,
                                           world=self.world,
                                           name=self.name,
                                           synth_time=time)
            print(f"NAME:\t{self.__name} ({self.__id})")
            print(self.__controller)
            Store.save_to_file(str(self.__controller), "controller_table",
                               folder_name)

        except ControllerException as e:
            raise GoalSynthesisFail(self, e)
Esempio n. 2
0
    def create_transition_controller(self, start: Types, finish: Types, t_trans: int) -> Controller:

        t_controller_name = f"TRANS_{start.name}->{finish.name}"

        if self.session_name is None:
            folder_name = f"{self.t_controllers_folder_name}/{t_controller_name}"
        else:
            folder_name = f"{self.session_name}/{self.t_controllers_folder_name}/{t_controller_name}"

        typeset = Typeset({start, finish})
        realizable = False
        for n_steps in range(1, t_trans):
            trans_spec_str = Logic.and_([start.name, Logic.xn_(finish.name, n_steps)])
            trans_spec = Atom(formula=(trans_spec_str, typeset))
            trans_contract = Contract(guarantees=trans_spec)
            try:
                controller_info = trans_contract.get_controller_info(world_ts=self.world.typeset)
                a, g, i, o = controller_info.get_strix_inputs()
                controller_synthesis_input = StringMng.get_controller_synthesis_str(controller_info)
                Store.save_to_file(controller_synthesis_input,
                                   f"t_controller_{start.name}_{finish.name}_specs.txt", folder_name)
                realized, kiss_mealy, time = Strix.generate_controller(a, g, i, o)
                if realized:
                    realizable = True
                    break
            except ControllerException as e:
                raise TransSynthesisFail(self, e)
        if not realizable:
            raise Exception(
                f"Controller [{start.name}, {finish.name}] cannot be synthetized in {t_trans} steps")
        else:
            Store.save_to_file(kiss_mealy, f"{start.name}_{finish.name}_mealy",
                               folder_name)
            # Store.generate_eps_from_dot(dot_mealy, f"{start.name}_{finish.name}_dot",
            #                             folder_name)

            t_controller = Controller(mealy_machine=kiss_mealy, world=self.world, name=t_controller_name,
                                      synth_time=time)
            Store.save_to_file(str(t_controller), f"{start.name}_{finish.name}_table", folder_name)

            return t_controller