added scenario self stop, agent setup, action masking in PPO
This commit is contained in:
+21
-13
@@ -23,8 +23,7 @@ class Econ(BaseEnvironment):
|
||||
stone, wood, and water tiles.
|
||||
|
||||
Args:
|
||||
planner_gets_spatial_obs (bool): Whether the planner agent receives spatial
|
||||
observations from the world.
|
||||
action_against_mask_penelty=-1 (int): Reward penelty for performing action against mask
|
||||
full_observability (bool): Whether the mobile agents' spatial observation
|
||||
includes the full world view or is instead an egocentric view.
|
||||
mobile_agent_observation_range (int): If not using full_observability,
|
||||
@@ -64,7 +63,7 @@ class Econ(BaseEnvironment):
|
||||
|
||||
name = "econ"
|
||||
agent_subclasses = ["BasicMobileAgent"]
|
||||
required_entities = ["Wood", "Stone", "Water"]
|
||||
required_entities = ["Wood", "Stone", "Water","Gem_Raw","Gem"]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -143,6 +142,7 @@ class Econ(BaseEnvironment):
|
||||
"""
|
||||
self.agent_starting_pos = {agent.idx: [] for agent in self.world.agents}
|
||||
|
||||
self._persist_between_resets=False
|
||||
|
||||
|
||||
self.last_log_loged={}
|
||||
@@ -172,6 +172,7 @@ class Econ(BaseEnvironment):
|
||||
bad=agent.bad_action
|
||||
agent.bad_action=False
|
||||
return bad
|
||||
|
||||
def get_current_optimization_metrics(self):
|
||||
"""
|
||||
Compute optimization metrics based on the current state. Used to compute reward.
|
||||
@@ -239,9 +240,13 @@ class Econ(BaseEnvironment):
|
||||
|
||||
Here, reset to the layout in the fixed layout file
|
||||
"""
|
||||
|
||||
if self._persist_between_resets: # if we only want to modify some values and not accualy reset
|
||||
return
|
||||
|
||||
self.world.maps.clear()
|
||||
|
||||
resources = ["Wood", "Stone"]
|
||||
resources = ["Wood", "Stone","Gem_Raw"]
|
||||
|
||||
for resource in resources:
|
||||
self.world.maps.set_point_add(resource,0,0,1)
|
||||
@@ -255,15 +260,18 @@ class Econ(BaseEnvironment):
|
||||
locations to start. Note: If using fixed_four_skill_and_loc, the starting
|
||||
locations will be overridden in self.additional_reset_steps.
|
||||
"""
|
||||
self.world.clear_agent_locs()
|
||||
if not self._persist_between_resets:
|
||||
self.world.clear_agent_locs()
|
||||
|
||||
for agent in self.world.agents:
|
||||
if not agent.is_setup():
|
||||
|
||||
agent.state["inventory"] = {k: 0 for k in agent.inventory.keys()}
|
||||
agent.state["escrow"] = {k: 0 for k in agent.inventory.keys()}
|
||||
agent.state["endogenous"] = {k: 0 for k in agent.endogenous.keys()}
|
||||
# Add starting coin
|
||||
agent.state["inventory"]["Coin"] = float(self.starting_agent_coin)
|
||||
if not self._persist_between_resets:
|
||||
agent.set_setup(False) # resets agent states
|
||||
if not agent.is_setup(): # agent has not been setup for scenario
|
||||
agent.state["inventory"] = {k: 0 for k in agent.inventory.keys()}
|
||||
agent.state["escrow"] = {k: 0 for k in agent.inventory.keys()}
|
||||
agent.state["endogenous"] = {k: 0 for k in agent.endogenous.keys()}
|
||||
# Add starting coin
|
||||
agent.state["inventory"]["Coin"] = float(self.starting_agent_coin)
|
||||
agent.bad_action=False
|
||||
|
||||
self.world.planner.state["inventory"] = {
|
||||
@@ -286,7 +294,7 @@ class Econ(BaseEnvironment):
|
||||
regeneration.
|
||||
"""
|
||||
|
||||
resources = ["Wood", "Stone"]
|
||||
resources = ["Wood", "Stone", "Gem_Raw"]
|
||||
|
||||
for resource in resources:
|
||||
self.world.maps.set_point_add(resource,0,0,20)
|
||||
|
||||
Reference in New Issue
Block a user