Example #1
0
        StateOfThreeGenerator(world, i, ["state_of_three"], in_only=True, average=None),
        LaneVehicleGenerator(world, i, ["lane_waiting_count"], in_only=True, average="all", negative=True),
        i,
        world,
        file_name,
        info_file
    ))
    if args.load_model:
        agents[-1].load_model(args.save_dir)



print(i.phases)

# Create metric
metric = [TravelTimeMetric(world), ThroughputMetric(world), SpeedScoreMetric(world), MaxWaitingTimeMetric(world)]

# create env
env = TSCEnv(world, agents, metric)

#
n_agents = len(agents)

# train dqn_agent
def train(args, env):
    for e in range(episodes):

        for agent in agents: agent.reset_episode_infos()

        first_obs = np.array(env.reset())*0.01
        current_obs = first_obs
Example #2
0
    'red_v': args.red_v
}

#Create world
world = World(args.config_file, thread_num=args.thread)

#Create agents
agents = []
for i in world.intersections:
    action_space = gym.spaces.Discrete(len(i.phases))
    agents.append(SOTLAgent(action_space, options, i, world))

# Create metric
metric = [
    TravelTimeMetric(world),
    ThroughputMetric(world),
    SpeedScoreMetric(world),
    MaxWaitingTimeMetric(world)
]

#Create env
env = TSCEnv(world, agents, metric)

obs = env.reset()
actions = []
steps = 0
episodes_rewards = 0

#Walk through the steps
while steps < args.steps:
Example #3
0
                    type=int,
                    default=1,
                    help='how often agent make decisions')
args = parser.parse_args()

# create world
world = World(args.config_file, thread_num=args.thread)

# create agents
agents = []
for i in world.intersections:
    action_space = gym.spaces.Discrete(len(i.phases))
    agents.append(SOTLAgent(action_space, i, world))

# create metric
metric = ThroughputMetric(world)

# create env
env = TSCEnv(world, agents, metric)


def test(met, met_name):

    # simulate
    obs = env.reset()
    env.update_metric(met)
    actions = []
    for i in range(args.steps):
        actions = []
        for agent_id, agent in enumerate(agents):
            actions.append(agent.get_action(obs[agent_id]))