Skip to content
Snippets Groups Projects
Commit 6baaf842 authored by Erik Nygren's avatar Erik Nygren :bullettrain_front:
Browse files

agent targets and agent start positions are always on seperate tracks

parent 39a249ac
No related branches found
No related tags found
No related merge requests found
...@@ -28,9 +28,9 @@ speed_ration_map = {1.: 1., # Fast passenger train ...@@ -28,9 +28,9 @@ speed_ration_map = {1.: 1., # Fast passenger train
1. / 3.: 0., # Slow commuter train 1. / 3.: 0., # Slow commuter train
1. / 4.: 0.} # Slow freight train 1. / 4.: 0.} # Slow freight train
env = RailEnv(width=100, env = RailEnv(width=50,
height=100, height=50,
rail_generator=sparse_rail_generator(num_cities=20, # Number of cities in map (where train stations are) rail_generator=sparse_rail_generator(num_cities=10, # Number of cities in map (where train stations are)
seed=10, # Random seed seed=10, # Random seed
grid_mode=False, grid_mode=False,
max_inter_city_rails=2, max_inter_city_rails=2,
......
"""Schedule generators (railway undertaking, "EVU").""" """Schedule generators (railway undertaking, "EVU")."""
import random
import warnings import warnings
from typing import Tuple, List, Callable, Mapping, Optional, Any from typing import Tuple, List, Callable, Mapping, Optional, Any
...@@ -74,11 +75,13 @@ def sparse_schedule_generator(speed_ratio_map: Mapping[float, float] = None) -> ...@@ -74,11 +75,13 @@ def sparse_schedule_generator(speed_ratio_map: Mapping[float, float] = None) ->
# Set target for agent # Set target for agent
start_city = agent_start_targets_nodes[agent_idx][0] start_city = agent_start_targets_nodes[agent_idx][0]
target_city = agent_start_targets_nodes[agent_idx][1] target_city = agent_start_targets_nodes[agent_idx][1]
start = random.choice(train_stations[start_city])
target = random.choice(train_stations[target_city])
while start[1] % 2 != 0:
start = random.choice(train_stations[start_city])
while target[1] % 2 != 1:
target = random.choice(train_stations[start_city])
start_city_idx = np.random.randint(len(train_stations[start_city]))
start = train_stations[start_city][start_city_idx]
target_station_idx = np.random.randint(len(train_stations[target_city]))
target = train_stations[target_city][target_station_idx]
agent_orientation = (agent_start_targets_nodes[agent_idx][2] + 2 * start[1]) % 4 agent_orientation = (agent_start_targets_nodes[agent_idx][2] + 2 * start[1]) % 4
if not rail.check_path_exists(start[0], agent_orientation, target[0]): if not rail.check_path_exists(start[0], agent_orientation, target[0]):
agent_orientation = (agent_orientation + 2) % 4 agent_orientation = (agent_orientation + 2) % 4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment