mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-05-22 14:56:43 +02:00
Zones Removed
This commit is contained in:
parent
72a1c0a149
commit
0e07e47d51
@ -120,9 +120,6 @@ Just define what your environment needs in a *yaml*-configfile like:
|
||||
Maintainers:
|
||||
coords_or_quantity: 1
|
||||
|
||||
# Zones: Entities representing zones in the environment.
|
||||
Zones: { }
|
||||
|
||||
|
||||
# Rules section specifies the rules governing the dynamics of the environment.
|
||||
Rules:
|
||||
|
@ -104,9 +104,6 @@ Entities:
|
||||
Maintainers:
|
||||
coords_or_quantity: 1
|
||||
|
||||
# Zones: Entities representing zones in the environment.
|
||||
Zones: { }
|
||||
|
||||
|
||||
# Rules section specifies the rules governing the dynamics of the environment.
|
||||
Rules:
|
||||
|
@ -42,7 +42,6 @@ Entities:
|
||||
Destinations: { }
|
||||
Doors: { }
|
||||
GlobalPositions: { }
|
||||
Zones: { }
|
||||
|
||||
Rules:
|
||||
# Environment Dynamics
|
||||
@ -56,9 +55,6 @@ Rules:
|
||||
|
||||
# Init
|
||||
AssignGlobalPositions: { }
|
||||
ZoneInit: { }
|
||||
AgentSingleZonePlacement: { }
|
||||
IndividualDestinationZonePlacement: { }
|
||||
|
||||
# Done Conditions
|
||||
MaxStepsReached:
|
||||
|
@ -1,3 +0,0 @@
|
||||
from .entitites import Zone
|
||||
from .groups import Zones
|
||||
from .rules import AgentSingleZonePlacement
|
@ -1,4 +0,0 @@
|
||||
# Names / Identifiers
|
||||
|
||||
ZONES = 'Zones' # Identifier of Zone-objects and groups (groups).
|
||||
ZONE = 'Zone' # -||-
|
@ -1,19 +0,0 @@
|
||||
import random
|
||||
from typing import List, Tuple
|
||||
|
||||
from marl_factory_grid.environment.entity.object import Object
|
||||
|
||||
|
||||
class Zone(Object):
|
||||
|
||||
@property
|
||||
def positions(self):
|
||||
return self.coords
|
||||
|
||||
def __init__(self, coords: List[Tuple[(int, int)]], *args, **kwargs):
|
||||
super(Zone, self).__init__(*args, **kwargs)
|
||||
self.coords = coords
|
||||
|
||||
@property
|
||||
def random_pos(self):
|
||||
return random.choice(self.coords)
|
@ -1,26 +0,0 @@
|
||||
from marl_factory_grid.environment.groups.objects import Objects
|
||||
from marl_factory_grid.modules.zones import Zone
|
||||
|
||||
|
||||
class Zones(Objects):
|
||||
symbol = None
|
||||
_entity = Zone
|
||||
|
||||
@property
|
||||
def var_can_move(self):
|
||||
return False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Zones, self).__init__(*args, can_collide=True, **kwargs)
|
||||
|
||||
def by_pos(self, pos):
|
||||
return self.pos_dict[pos]
|
||||
|
||||
def notify_add_entity(self, entity: Zone):
|
||||
self.pos_dict.update({key: [entity] for key in entity.positions})
|
||||
return True
|
||||
|
||||
def notify_del_entity(self, entity: Zone):
|
||||
for pos in entity.positions:
|
||||
self.pos_dict[pos].remove(entity)
|
||||
return True
|
@ -1,71 +0,0 @@
|
||||
from random import choices, choice
|
||||
|
||||
from . import constants as z, Zone
|
||||
from .. import Destination
|
||||
from ..destinations import constants as d
|
||||
from ...environment.rules import Rule
|
||||
from ...environment import constants as c
|
||||
|
||||
|
||||
class ZoneInit(Rule):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._zones = list()
|
||||
|
||||
def on_init(self, state, lvl_map):
|
||||
z_idx = 1
|
||||
|
||||
while z_idx:
|
||||
zone_positions = lvl_map.get_coordinates_for_symbol(z_idx)
|
||||
if len(zone_positions):
|
||||
self._zones.append(Zone(zone_positions))
|
||||
z_idx += 1
|
||||
else:
|
||||
z_idx = 0
|
||||
|
||||
def on_reset(self, state):
|
||||
state[z.ZONES].add_items(self._zones)
|
||||
return []
|
||||
|
||||
|
||||
class AgentSingleZonePlacement(Rule):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def on_reset(self, state):
|
||||
n_agents = len(state[c.AGENT])
|
||||
assert len(state[z.ZONES]) >= n_agents
|
||||
|
||||
z_idxs = choices(list(range(len(state[z.ZONES]))), k=n_agents)
|
||||
for agent in state[c.AGENT]:
|
||||
agent.move(state[z.ZONES][z_idxs.pop()].random_pos, state)
|
||||
return []
|
||||
|
||||
|
||||
class IndividualDestinationZonePlacement(Rule):
|
||||
|
||||
def __init__(self):
|
||||
raise NotImplementedError("This is pretty new, and needs to be debugged, after the zones")
|
||||
super().__init__()
|
||||
|
||||
def on_reset(self, state):
|
||||
for agent in state[c.AGENT]:
|
||||
self.trigger_spawn(agent, state)
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def trigger_spawn(agent, state):
|
||||
agent_zones = state[z.ZONES].by_pos(agent.pos)
|
||||
other_zones = [x for x in state[z.ZONES] if x not in agent_zones]
|
||||
already_has_destination = True
|
||||
while already_has_destination:
|
||||
pos = choice(other_zones).random_pos
|
||||
if state[d.DESTINATION].by_pos(pos) is None:
|
||||
already_has_destination = False
|
||||
destination = Destination(pos, bind_to=agent)
|
||||
|
||||
state[d.DESTINATION].add_item(destination)
|
||||
continue
|
||||
return c.VALID
|
@ -73,7 +73,6 @@ class EnvRecorder(Wrapper):
|
||||
n_dests=0,
|
||||
dwell_time=0,
|
||||
spawn_frequency=0,
|
||||
spawn_in_other_zone=False,
|
||||
spawn_mode=''
|
||||
)
|
||||
rewards_dest = dict(
|
||||
|
@ -15,7 +15,7 @@ OBSERVATIONS = 'Observations'
|
||||
RULES = 'Rule'
|
||||
TESTS = 'Tests'
|
||||
EXCLUDED = ['identifier', 'args', 'kwargs', 'Move', 'Agent', 'GlobalPositions', 'Walls', 'Gamestate', 'Path',
|
||||
'Iterable', 'Move', 'Result', 'TemplateRule', 'Entities', 'EnvObjects', 'Zones', 'Collection',
|
||||
'Iterable', 'Move', 'Result', 'TemplateRule', 'Entities', 'EnvObjects', 'Collection',
|
||||
'State', 'Object', 'default_valid_reward', 'default_fail_reward', 'size']
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user