Пример #1
0
def execute(agent_helper):
    """Execution function for testing or training"""
    agent_helper.env = create_environment(agent_helper)
    agent_helper.agent = create_agent(agent_helper)

    if agent_helper.train:
        if agent_helper.weights:
            load_weights(
                agent_helper.agent,
                f"{agent_helper.result_base_path}/{agent_helper.weights}/weights"
            )
        train_agent(agent_helper)
        if agent_helper.test:
            # if test after training (append_test)
            agent_helper.steps = agent_helper.max_episode_steps
            agent_helper.result = ExperimentResult(agent_helper.experiment_id)
            agent_helper.result.steps = agent_helper.steps
            agent_helper.test_mode = True
            setup_files(agent_helper)
    if agent_helper.test:
        test_agent(agent_helper)
        if agent_helper.gen_scenario:
            agent_helper.gen_scenario_test = True
            setup_files(agent_helper)
            logger.info("Testing with a different sim config file")
            test_agent(agent_helper)
Пример #2
0
def execute(agent_helper):
    """Execution function for testing or training"""
    agent_helper.env = create_environment(agent_helper)
    logger.info(
        f"observation_space: {agent_helper.env.observation_space.shape}")
    logger.info(f"action_space: {agent_helper.env.action_space.shape[0]}")

    logger.info("DONE CREATE ENVIRONMENT")
    agent_helper.agent = create_agent(agent_helper)
    logger.info("DONE CREATE AGENT")
    if agent_helper.train:
        logger.info(f"agent_helper.weights: {agent_helper.weights}")
        if agent_helper.weights:
            load_weights(
                agent_helper.agent,
                f"{agent_helper.result_base_path}/{agent_helper.weights}/weights"
            )
        train_agent(agent_helper)
        if agent_helper.test:
            # if test after training (append_test) test for 1 episodes
            agent_helper.episodes = 1
            agent_helper.result = ExperimentResult(agent_helper.experiment_id)
            agent_helper.result.episodes = agent_helper.episodes
            agent_helper.test_mode = True
            setup_files(agent_helper)
    if agent_helper.test:
        test_agent(agent_helper)
        if agent_helper.gen_scenario:
            agent_helper.gen_scenario_test = True
            setup_files(agent_helper)
            logger.info("Testing with a different sim config file")
            test_agent(agent_helper)
Пример #3
0
 def __init__(self,
              agent_config,
              network,
              service,
              sim_config,
              service_requirement,
              seed,
              episodes,
              weights,
              verbose,
              DATETIME,
              test,
              append_test,
              sim_seed,
              gen_scenario,
              episode_steps=96,
              n_steps_per_episode=1000):
     self.episode_steps = episode_steps
     self.verbose = verbose
     self.agent_config_path = agent_config
     self.network_path = network
     self.service_path = service
     self.service_requirement_path = service_requirement
     self.sim_config_path = sim_config
     self.seed = seed
     self.experiment_id = f"{DATETIME}_seed{seed}"
     self.result = ExperimentResult(self.experiment_id)
     self.weights = weights
     self.episodes = episodes
     self.agent = None
     self.result_base_path = None
     self.graph_base_path = None
     self.result_file = None
     self.config = None
     self.config_dir = None
     self.logfile = None
     self.weights_path = None
     self.graph_path = None
     self.env = None
     self.test = test
     self.train = True
     self.test_mode = test
     if self.test:
         self.train = False
     self.append_test = append_test
     if self.append_test:
         self.test = self.experiment_id
     self.gen_scenario = gen_scenario
     self.gen_scenario_test = False
     self.gen_scenario_result_base_path = None
     self.callbacks = None
     self.sim_seed = sim_seed
     self.n_steps_per_episode = n_steps_per_episode