Documentation

This commit is contained in:
Joel Friedrich
2023-11-22 12:12:04 +01:00
committed by Steffen Illium
parent 604c0c6f57
commit 855f53b406
35 changed files with 655 additions and 198 deletions

View File

@ -3,7 +3,7 @@ from typing import Union
from marl_factory_grid.environment.actions import Action
from marl_factory_grid.utils.results import ActionResult
from marl_factory_grid.modules.clean_up import constants as d, rewards as r
from marl_factory_grid.modules.clean_up import constants as d
from marl_factory_grid.environment import constants as c
@ -11,7 +11,10 @@ from marl_factory_grid.environment import constants as c
class Clean(Action):
def __init__(self):
super().__init__(d.CLEAN_UP, r.CLEAN_UP_VALID, r.CLEAN_UP_FAIL)
"""
Attempts to reduce dirt amount on entity's position.
"""
super().__init__(d.CLEAN_UP, d.REWARD_CLEAN_UP_VALID, d.REWARD_CLEAN_UP_FAIL)
def do(self, entity, state) -> Union[None, ActionResult]:
if dirt := next((x for x in state.entities.pos_dict[entity.pos] if "dirt" in x.name.lower()), None):

View File

@ -5,3 +5,7 @@ CLEAN_UP = 'do_cleanup_action'
CLEAN_UP_VALID = 'clean_up_valid'
CLEAN_UP_FAIL = 'clean_up_fail'
CLEAN_UP_ALL = 'all_cleaned_up'
REWARD_CLEAN_UP_VALID: float = 0.5
REWARD_CLEAN_UP_FAIL: float = -0.1
REWARD_CLEAN_UP_ALL: float = 4.5

View File

@ -7,19 +7,33 @@ class DirtPile(Entity):
@property
def amount(self):
"""
Internal Usage
"""
return self._amount
@property
def encoding(self):
# Edit this if you want items to be drawn in the ops differntly
return self._amount
def __init__(self, *args, amount=2, max_local_amount=5, **kwargs):
"""
Represents a pile of dirt at a specific position in the environment.
:param amount: The amount of dirt in the pile.
:type amount: float
:param max_local_amount: The maximum amount of dirt allowed in a single pile at one position.
:type max_local_amount: float
"""
super(DirtPile, self).__init__(*args, **kwargs)
self._amount = amount
self.max_local_amount = max_local_amount
def set_new_amount(self, amount):
"""
Internal Usage
"""
self._amount = min(amount, self.max_local_amount)
def summarize_state(self):

View File

@ -7,24 +7,56 @@ from marl_factory_grid.utils.results import Result
class DirtPiles(Collection):
_entity = DirtPile
var_is_blocking_light = False
var_can_collide = False
var_can_move = False
var_has_position = True
@property
def var_is_blocking_light(self):
return False
@property
def global_amount(self):
def var_can_collide(self):
return False
@property
def var_can_move(self):
return False
@property
def var_has_position(self):
return True
@property
def global_amount(self) -> float:
"""
Internal Usage
"""
return sum([dirt.amount for dirt in self])
def __init__(self, *args,
max_local_amount=5,
clean_amount=1,
max_global_amount: int = 20,
coords_or_quantity=10,
initial_amount=2,
amount_var=0.2,
n_var=0.2,
**kwargs):
def __init__(self, *args, max_local_amount=5, clean_amount=1, max_global_amount: int = 20, coords_or_quantity=10,
initial_amount=2, amount_var=0.2, n_var=0.2, **kwargs):
"""
A Collection of dirt piles that triggers their spawn.
:param max_local_amount: The maximum amount of dirt allowed in a single pile at one position.
:type max_local_amount: int
:param clean_amount: The amount of dirt removed by a single cleaning action.
:type clean_amount: int
:param max_global_amount: The maximum total amount of dirt allowed in the environment.
:type max_global_amount: int
:param coords_or_quantity: Determines whether to use coordinates or quantity when triggering dirt pile spawn.
:type coords_or_quantity: Union[Tuple[int, int], int]
:param initial_amount: The initial amount of dirt in each newly spawned pile.
:type initial_amount: int
:param amount_var: The variability in the initial amount of dirt in each pile.
:type amount_var: float
:param n_var: The variability in the number of new dirt piles spawned.
:type n_var: float
"""
super(DirtPiles, self).__init__(*args, **kwargs)
self.amount_var = amount_var
self.n_var = n_var

View File

@ -1,3 +0,0 @@
CLEAN_UP_VALID: float = 0.5
CLEAN_UP_FAIL: float = -0.1
CLEAN_UP_ALL: float = 4.5

View File

@ -1,4 +1,4 @@
from marl_factory_grid.modules.clean_up import constants as d, rewards as r
from marl_factory_grid.modules.clean_up import constants as d
from marl_factory_grid.environment import constants as c
from marl_factory_grid.environment.rules import Rule
@ -9,9 +9,9 @@ from marl_factory_grid.utils.results import DoneResult
class DoneOnAllDirtCleaned(Rule):
def __init__(self, reward: float = r.CLEAN_UP_ALL):
def __init__(self, reward: float = d.REWARD_CLEAN_UP_ALL):
"""
Defines a 'Done'-condition which tirggers, when there is no more 'Dirt' in the environment.
Defines a 'Done'-condition which triggers, when there is no more 'Dirt' in the environment.
:type reward: float
:parameter reward: Given reward when condition triggers.
@ -29,9 +29,9 @@ class RespawnDirt(Rule):
def __init__(self, respawn_freq: int = 15, respawn_n: int = 5, respawn_amount: float = 1.0):
"""
Defines the spawn pattern of intial and additional 'Dirt'-entitites.
First chooses positions, then trys to spawn dirt until 'respawn_n' or the maximal global amount is reached.
If there is allready some, it is topped up to min(max_local_amount, amount).
Defines the spawn pattern of initial and additional 'Dirt'-entities.
First chooses positions, then tries to spawn dirt until 'respawn_n' or the maximal global amount is reached.
If there is already some, it is topped up to min(max_local_amount, amount).
:type respawn_freq: int
:parameter respawn_freq: In which frequency should this Rule try to spawn new 'Dirt'?