-
-
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
197108a
commit 9af2ed0
Showing
10 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.envs.mujoco.ant_v4 import AntEnv | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
|
||
|
||
class MOAntEnv(AntEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the AntEnv environment. | ||
See [Gymnasium's env](https://gymnasium.farama.org/environments/mujoco/ant/) for more information. | ||
## Reward Space | ||
The reward is 2- or 3-dimensional: | ||
- 0: x-velocity | ||
- 1: y-velocity | ||
- 2: Control cost of the action | ||
If the cost_objective flag is set to False, the reward is 2-dimensional, and the cost is added to other objectives. | ||
A healthy reward is added to all objectives. | ||
""" | ||
|
||
def __init__(self, cost_objective=True, **kwargs): | ||
super().__init__(**kwargs) | ||
EzPickle.__init__(self, cost_objective, **kwargs) | ||
self.cost_objetive = cost_objective | ||
self.reward_dim = 3 if cost_objective else 2 | ||
self.reward_space = Box(low=-np.inf, high=np.inf, shape=(self.reward_dim,)) | ||
|
||
def step(self, action): | ||
observation, reward, terminated, truncated, info = super().step(action) | ||
x_velocity = info["x_velocity"] | ||
y_velocity = info["y_velocity"] | ||
cost = info["reward_ctrl"] | ||
healthy_reward = info["reward_survive"] | ||
|
||
if self.cost_objetive: | ||
cost /= self._ctrl_cost_weight # Ignore the weight in the original AntEnv | ||
vec_reward = np.array([x_velocity, y_velocity, cost], dtype=np.float32) | ||
else: | ||
vec_reward = np.array([x_velocity, y_velocity], dtype=np.float32) | ||
vec_reward += cost | ||
|
||
vec_reward += healthy_reward | ||
|
||
return observation, 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,34 @@ | ||
import numpy as np | ||
from gymnasium.envs.mujoco.humanoid_v4 import HumanoidEnv | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
|
||
|
||
class MOHumanoidEnv(HumanoidEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the HumanoidEnv environment. | ||
See [Gymnasium's env](https://gymnasium.farama.org/environments/mujoco/humanoid/) for more information. | ||
## Reward Space | ||
The reward is 2-dimensional: | ||
- 0: Reward for running forward (x-velocity) | ||
- 1: Control cost of the action | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
EzPickle.__init__(self, **kwargs) | ||
self.reward_space = Box(low=-np.inf, high=np.inf, shape=(2,)) | ||
self.reward_dim = 2 | ||
|
||
def step(self, action): | ||
observation, reward, terminated, truncated, info = super().step(action) | ||
velocity = info["x_velocity"] | ||
negative_cost = 10 * info["reward_quadctrl"] | ||
vec_reward = np.array([velocity, negative_cost], dtype=np.float32) | ||
|
||
vec_reward += self.healthy_reward # All objectives are penalyzed when the agent falls | ||
|
||
return observation, 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,33 @@ | ||
import numpy as np | ||
from gymnasium.envs.mujoco.swimmer_v4 import SwimmerEnv | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
|
||
|
||
class MOSwimmerEnv(SwimmerEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the SwimmerEnv environment. | ||
See [Gymnasium's env](https://gymnasium.farama.org/environments/mujoco/swimmer/) for more information. | ||
## Reward Space | ||
The reward is 2-dimensional: | ||
- 0: Reward for moving forward (x-velocity) | ||
- 1: Control cost of the action | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
EzPickle.__init__(self, **kwargs) | ||
self.reward_space = Box(low=-np.inf, high=np.inf, shape=(2,)) | ||
self.reward_dim = 2 | ||
|
||
def step(self, action): | ||
observation, reward, terminated, truncated, info = super().step(action) | ||
velocity = info["x_velocity"] | ||
energy = -np.sum(np.square(action)) | ||
|
||
vec_reward = np.array([velocity, energy], dtype=np.float32) | ||
|
||
return observation, 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,35 @@ | ||
import numpy as np | ||
from gymnasium.envs.mujoco.walker2d_v4 import Walker2dEnv | ||
from gymnasium.spaces import Box | ||
from gymnasium.utils import EzPickle | ||
|
||
|
||
class MOWalker2dEnv(Walker2dEnv, EzPickle): | ||
""" | ||
## Description | ||
Multi-objective version of the Walker2dEnv environment. | ||
See [Gymnasium's env](https://gymnasium.farama.org/environments/mujoco/walker2d/) for more information. | ||
## Reward Space | ||
The reward is 2-dimensional: | ||
- 0: Reward for running forward (x-velocity) | ||
- 1: Control cost of the action | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
EzPickle.__init__(self, **kwargs) | ||
self.reward_space = Box(low=-np.inf, high=np.inf, shape=(2,)) | ||
self.reward_dim = 2 | ||
|
||
def step(self, action): | ||
observation, reward, terminated, truncated, info = super().step(action) | ||
velocity = info["x_velocity"] | ||
energy = -np.sum(np.square(action)) | ||
|
||
vec_reward = np.array([velocity, energy], dtype=np.float32) | ||
|
||
vec_reward += self.healthy_reward # All objectives are penalyzed when the agent falls | ||
|
||
return observation, vec_reward, terminated, truncated, info |