Ejemplo n.º 1
0
    def __init__(self, parent=None):
        """
        Defines the class attributes especially the root_item which later contains the list of headers e.g. for a TreeView representation.
        :param parent: the parent of the model
        :type parent: QObject
        """
        super(ROSModel, self).__init__(parent)

        self.__logger = ModelLogger()

        self._translator = QTranslator()
        # internationalize everything including the 2 plugins
        self.rp = rospkg.RosPack()
        directory = os.path.join(self.rp.get_path('arni_gui'), 'translations')
        files = find_qm_files(directory)
        translator = self.get_translator()
        # todo: make this more intelligent (should be done as soon as new languages are needed / implemented)
        print("chose translation " + files[0])
        translator.load(files[0])
        qApp.installTranslator(translator)

        self.__root_item = RootItem(self.__logger, "abstract", self)

        self.__parent = parent
        self.__model_lock = Lock()

        self.update_signal.connect(self.update_model)


        """
        IMPORTANT: Does not contain the models nodes but the logical nodes. E.g. a ConnectionItem splits up to two
        TreeConnectionItems where the identifier_dict only contains the connectionitem. This allows to push
        data into one item but to show it at two places in the Qt GUI.
        """
        self.__identifier_dict = {"root": self.__root_item}
        self.__item_delegate = SizeDelegate()

        # CAUTION: Do not change this mapping if not absolutely necessary. If you change it remember to change
        # item_filter_proxy (and maybe other classes) as well - sadly not all functions use the access function.
        self.__mapping = {
            0: 'type',
            1: 'name',
            2: 'state',
            3: 'data'
        }

        self.__last_time_error_occured = 0
        self.__logger.log("info", Time.now(), "ROSModel", "ROSModel initialization finished")

        self.__seuid_helper = SEUID()

        self.__find_host = HostLookup()

        self.__buffer_thread = BufferThread(self)
        self.__buffer_thread.start()
Ejemplo n.º 2
0
def run_single_model(conf_path):
    sumo_backend.set_backend(gh.backend)
    if gh.backend == "traci":
        gh.sumo_cmd[0] = "-c"
        gh.sumo_cmd = ["sumo"] + gh.sumo_cmd
    elif gh.backend in "traci-gui":
        gh.sumo_cmd[0] = "-c"
        gh.sumo_cmd = ["sumo-gui"] + gh.sumo_cmd
    backend = sumo_backend.get_backend()
    temp_dir = prepare_net(backend)

    junctions = build_junctions()
    a_class, r_class, s_class, sr_class = get_constructors()
    agents = [
        a_class(j) for j in junctions
        if j.junction_id in gh.junctions_with_agents
    ]
    if hasattr(gh, "load_weights") and gh.load_weights:
        for agent, w_file in zip(agents, gh.load_weights):
            agent.weights = np.load(w_file)
    log_keys = generate_log_keys(agents, junctions)
    logger = None
    if gh.log:
        logger = ModelLogger(agents, conf_path, log_keys)
    sim_runner = sr_class(agents=agents,
                          junctions=junctions,
                          sumo_cmd=gh.sumo_cmd,
                          state_extractor_cls=s_class,
                          reward_extractor_class=r_class,
                          backend=sumo_backend.get_backend(),
                          logger=logger)
    solver = Solver(sim_runner=sim_runner, logger=logger)
    rewards = solver.train()
    sim_runner.close_simulation()
    shutil.rmtree(temp_dir)
    return rewards