-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5099244
commit 7a036ab
Showing
5 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
from highway_env.envs import IntersectionEnv | ||
|
||
|
||
class MOIntersectionEnv(IntersectionEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the IntersectionEnv environment. | ||
See [highway-env](https://github.com/eleurent/highway-env) for more information. | ||
## Reward Space | ||
The reward is 4-dimensional: | ||
- 0: high speed reward | ||
- 1: arrived reward | ||
- 2: collision reward | ||
- 3: on road reward | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
EzPickle.__init__(self, *args, **kwargs) | ||
|
||
super().__init__(*args, **kwargs) | ||
self.reward_space = Box( | ||
low=np.array([0.0, 0.0, -1.0, 0.0]), high=np.array([1.0, 1.0, 0.0, 1.0]), shape=(4,), dtype=np.float64 | ||
) | ||
self.reward_dim = 4 | ||
|
||
def step(self, action): | ||
obs, reward, terminated, truncated, info = super().step(action) | ||
rewards = info["rewards"] | ||
vec_reward = np.array( | ||
[ | ||
rewards["high_speed_reward"], | ||
rewards["arrived_reward"], | ||
-rewards["collision_reward"], | ||
rewards["on_road_reward"], | ||
], | ||
dtype=np.float64, | ||
) | ||
info["original_reward"] = reward | ||
return obs, vec_reward, terminated, truncated, info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import numpy as np | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
from highway_env.envs import MergeEnv | ||
|
||
|
||
class MOMergeEnv(MergeEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the MergeEnv environment. | ||
See [highway-env](https://github.com/eleurent/highway-env) for more information. | ||
## Reward Space | ||
The reward is 5-dimensional: | ||
- 0: high speed reward | ||
- 1: right lane reward | ||
- 2: collision reward | ||
- 3: lane change reward | ||
- 4: merging speed reward | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
EzPickle.__init__(self, *args, **kwargs) | ||
|
||
super().__init__(*args, **kwargs) | ||
self.reward_space = Box( | ||
low=np.array([-1.0, 0.0, -1.0, 0.0, 0.0]), high=np.array([1.0, 1.0, 0.0, 1.0, 1.0]), shape=(5,), dtype=np.float32 | ||
) | ||
self.reward_dim = 5 | ||
|
||
def step(self, action): | ||
obs, reward, terminated, truncated, info = super().step(action) | ||
rewards = info["rewards"] | ||
vec_reward = np.array( | ||
[ | ||
np.clip(rewards["high_speed_reward"], -1.0, 1.0), | ||
rewards["right_lane_reward"], | ||
-rewards["collision_reward"], | ||
rewards["lane_change_reward"], | ||
np.clip(rewards["merging_speed_reward"], 0.0, 1.0), | ||
], | ||
dtype=np.float32, | ||
) | ||
info["original_reward"] = reward | ||
return obs, vec_reward, terminated, truncated, info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
from highway_env.envs import RacetrackEnv | ||
|
||
|
||
class MORacetrackEnv(RacetrackEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the RacetrackEnv environment. | ||
See [highway-env](https://github.com/eleurent/highway-env) for more information. | ||
## Reward Space | ||
The reward is 4-dimensional: | ||
- 0: lane centering reward | ||
- 1: action reward | ||
- 2: collision reward | ||
- 3: on road reward | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
EzPickle.__init__(self, *args, **kwargs) | ||
|
||
super().__init__(*args, **kwargs) | ||
self.reward_space = Box( | ||
low=np.array([0.0, 0.0, -1.0, 0.0]), high=np.array([1.0, 1.0, 0.0, 1.0]), shape=(4,), dtype=np.float32 | ||
) | ||
self.reward_dim = 4 | ||
|
||
def step(self, action): | ||
obs, reward, terminated, truncated, info = super().step(action) | ||
rewards = info["rewards"] | ||
vec_reward = np.array( | ||
[ | ||
rewards["lane_centering_reward"], | ||
rewards["action_reward"], | ||
-rewards["collision_reward"], | ||
rewards["on_road_reward"], | ||
], | ||
dtype=np.float32, | ||
) | ||
info["original_reward"] = reward | ||
return obs, vec_reward, terminated, truncated, info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
from highway_env.envs import RoundaboutEnv | ||
|
||
|
||
class MORoundaboutEnv(RoundaboutEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the RoundaboutEnv environment. | ||
See [highway-env](https://github.com/eleurent/highway-env) for more information. | ||
## Reward Space | ||
The reward is 4-dimensional: | ||
- 0: high speed reward | ||
- 1: on road reward | ||
- 2: collision reward | ||
- 3: lane change reward | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
EzPickle.__init__(self, *args, **kwargs) | ||
|
||
super().__init__(*args, **kwargs) | ||
self.reward_space = Box( | ||
low=np.array([0.0, 0.0, -1.0, 0.0]), high=np.array([1.0, 1.0, 0.0, 1.0]), shape=(4,), dtype=np.float32 | ||
) | ||
self.reward_dim = 4 | ||
|
||
def step(self, action): | ||
obs, reward, terminated, truncated, info = super().step(action) | ||
rewards = info["rewards"] | ||
vec_reward = np.array( | ||
[ | ||
rewards["high_speed_reward"], | ||
rewards["on_road_reward"], | ||
-rewards["collision_reward"], | ||
rewards["lane_change_reward"], | ||
], | ||
dtype=np.float32, | ||
) | ||
info["original_reward"] = reward | ||
return obs, vec_reward, terminated, truncated, info |