Skip to content

Commit

Permalink
edit on racetrack_env:
Browse files Browse the repository at this point in the history
Added an if statement before creating other vehicles to fix the error that occurs when the other_vehicles variable is selected as zero.
Now environment let us create only ego vehicle for experiments (with setting other_vehicles to zero.)
  • Loading branch information
mehmetozturan committed Mar 26, 2024
1 parent 81c11d6 commit c2d8df1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
45 changes: 23 additions & 22 deletions highway_env/envs/racetrack_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,31 +379,32 @@ def _make_vehicles(self) -> None:
self.controlled_vehicles.append(controlled_vehicle)
self.road.vehicles.append(controlled_vehicle)

# Front vehicle
vehicle = IDMVehicle.make_on_lane(
self.road,
("b", "c", lane_index[-1]),
longitudinal=rng.uniform(
low=0, high=self.road.network.get_lane(("b", "c", 0)).length
),
speed=6 + rng.uniform(high=3),
)
self.road.vehicles.append(vehicle)

# Other vehicles
for i in range(rng.integers(self.config["other_vehicles"])):
random_lane_index = self.road.network.random_lane_index(rng)
if self.config["other_vehicles"] > 0:
# Front vehicle
vehicle = IDMVehicle.make_on_lane(
self.road,
random_lane_index,
("b", "c", lane_index[-1]),
longitudinal=rng.uniform(
low=0, high=self.road.network.get_lane(random_lane_index).length
low=0, high=self.road.network.get_lane(("b", "c", 0)).length
),
speed=6 + rng.uniform(high=3),
)
# Prevent early collisions
for v in self.road.vehicles:
if np.linalg.norm(vehicle.position - v.position) < 20:
break
else:
self.road.vehicles.append(vehicle)
self.road.vehicles.append(vehicle)

# Other vehicles
for i in range(rng.integers(self.config["other_vehicles"])):
random_lane_index = self.road.network.random_lane_index(rng)
vehicle = IDMVehicle.make_on_lane(
self.road,
random_lane_index,
longitudinal=rng.uniform(
low=0, high=self.road.network.get_lane(random_lane_index).length
),
speed=6 + rng.uniform(high=3),
)
# Prevent early collisions
for v in self.road.vehicles:
if np.linalg.norm(vehicle.position - v.position) < 20:
break
else:
self.road.vehicles.append(vehicle)

0 comments on commit c2d8df1

Please sign in to comment.