mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-23 12:01:36 +02:00
New Szenario "Two_Rooms_One_Door"
This commit is contained in:
@ -4,7 +4,7 @@ DEFAULTS = 'Defaults'
|
||||
SELF = 'Self'
|
||||
PLACEHOLDER = 'Placeholder'
|
||||
FLOOR = 'Floor' # Identifier of Floor-objects and groups (groups).
|
||||
FLOORS = 'Floors' # Identifier of Floor-objects and groups (groups).
|
||||
FLOORS = 'Floors' # Identifier of Floor-objects and groups (groups).
|
||||
WALL = 'Wall' # Identifier of Wall-objects and groups (groups).
|
||||
WALLS = 'Walls' # Identifier of Wall-objects and groups (groups).
|
||||
LEVEL = 'Level' # Identifier of Level-objects and groups (groups).
|
||||
|
@ -12,6 +12,22 @@ from marl_factory_grid.environment import constants as c
|
||||
|
||||
class Agent(Entity):
|
||||
|
||||
@property
|
||||
def var_is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_can_move(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_is_blocking_pos(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def obs_tag(self):
|
||||
return self.name
|
||||
|
@ -9,7 +9,7 @@ class BoundEntityMixin:
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return f'{self.__class__.__name__}({self._bound_entity.name})'
|
||||
return f'{self.__class__.__name__}({self.bound_entity.name})'
|
||||
|
||||
def belongs_to_entity(self, entity):
|
||||
return entity == self.bound_entity
|
||||
|
@ -21,7 +21,7 @@ class Object:
|
||||
def name(self):
|
||||
if self._str_ident is not None:
|
||||
return f'{self.__class__.__name__}[{self._str_ident}]'
|
||||
return f'{self.__class__.__name__}#{self.identifier_int}'
|
||||
return f'{self.__class__.__name__}#{self.u_int}'
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
@ -30,10 +30,14 @@ class Object:
|
||||
else:
|
||||
return self.name
|
||||
|
||||
def reset_uid(self):
|
||||
self._u_idx = defaultdict(lambda: 0)
|
||||
return True
|
||||
|
||||
def __init__(self, str_ident: Union[str, None] = None, **kwargs):
|
||||
self._observers = []
|
||||
self._str_ident = str_ident
|
||||
self.identifier_int = self._identify_and_count_up()
|
||||
self.u_int = self._identify_and_count_up()
|
||||
self._collection = None
|
||||
|
||||
if kwargs:
|
||||
|
@ -30,10 +30,6 @@ class Floor(EnvObject):
|
||||
def var_is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def neighboring_floor_pos(self):
|
||||
return [x.pos for x in self.neighboring_floor]
|
||||
|
||||
@property
|
||||
def neighboring_floor(self):
|
||||
if self._neighboring_floor:
|
||||
|
@ -78,12 +78,19 @@ class Factory(gym.Env):
|
||||
return self.state.entities[item]
|
||||
|
||||
def reset(self) -> (dict, dict):
|
||||
if hasattr(self, 'state'):
|
||||
for entity_group in self.state.entities:
|
||||
try:
|
||||
entity_group[0].reset_uid()
|
||||
except (AttributeError, TypeError):
|
||||
pass
|
||||
|
||||
self.state = None
|
||||
|
||||
# Init entity:
|
||||
entities = self.map.do_init()
|
||||
|
||||
# Grab all rules:
|
||||
# Grab all )rules:
|
||||
rules = self.conf.load_rules()
|
||||
|
||||
# Agents
|
||||
|
@ -41,6 +41,9 @@ class Entities(Objects):
|
||||
val.add_observer(self)
|
||||
return self
|
||||
|
||||
def __contains__(self, item):
|
||||
return item in self._data
|
||||
|
||||
def __delitem__(self, name):
|
||||
assert_str = 'This group of entity does not exist in this collection!'
|
||||
assert any([key for key in name.keys() if key in self.keys()]), assert_str
|
||||
@ -51,7 +54,10 @@ class Entities(Objects):
|
||||
|
||||
@property
|
||||
def obs_pairs(self):
|
||||
return [y for x in self for y in x.obs_pairs]
|
||||
try:
|
||||
return [y for x in self for y in x.obs_pairs]
|
||||
except AttributeError:
|
||||
print('OhOh (debug me)')
|
||||
|
||||
def by_pos(self, pos: (int, int)):
|
||||
return self.pos_dict[pos]
|
||||
|
@ -82,7 +82,7 @@ class IsBoundMixin:
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences,PyTypeChecker
|
||||
class HasBoundedMixin:
|
||||
class HasBoundMixin:
|
||||
|
||||
@property
|
||||
def obs_pairs(self):
|
||||
|
@ -37,7 +37,7 @@ class Objects:
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._data = defaultdict(lambda: None)
|
||||
self._observers = list()
|
||||
self._observers = [self]
|
||||
self.pos_dict = defaultdict(list)
|
||||
|
||||
def __len__(self):
|
||||
@ -52,6 +52,7 @@ class Objects:
|
||||
assert self._data[item.name] is None, f'{item.name} allready exists!!!'
|
||||
self._data.update({item.name: item})
|
||||
item.set_collection(self)
|
||||
# self.notify_add_entity(item)
|
||||
for observer in self.observers:
|
||||
observer.notify_add_entity(item)
|
||||
return self
|
||||
@ -96,8 +97,6 @@ class Objects:
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def __getitem__(self, item):
|
||||
if isinstance(item, (int, np.int64, np.int32)):
|
||||
if item < 0:
|
||||
|
@ -4,7 +4,7 @@ import numpy as np
|
||||
|
||||
from marl_factory_grid.environment.entity.util import GlobalPosition
|
||||
from marl_factory_grid.environment.groups.env_objects import EnvObjects
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin, HasBoundedMixin
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin, HasBoundMixin
|
||||
from marl_factory_grid.environment.groups.objects import Objects
|
||||
from marl_factory_grid.modules.zones import Zone
|
||||
from marl_factory_grid.utils import helpers as h
|
||||
@ -35,7 +35,7 @@ class Combined(PositionMixin, EnvObjects):
|
||||
return [(name, None) for name in self.names]
|
||||
|
||||
|
||||
class GlobalPositions(HasBoundedMixin, EnvObjects):
|
||||
class GlobalPositions(HasBoundMixin, EnvObjects):
|
||||
|
||||
_entity = GlobalPosition
|
||||
is_blocking_light = False,
|
||||
|
Reference in New Issue
Block a user