mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-11-02 21:47:25 +01:00
Resolved some warnings and style issues
This commit is contained in:
@@ -6,7 +6,9 @@ from marl_factory_grid.utils.results import TickResult, DoneResult
|
||||
class TemplateRule(Rule):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TemplateRule, self).__init__(*args, **kwargs)
|
||||
super(TemplateRule, self).__init__()
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
def on_init(self, state, lvl_map):
|
||||
pass
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from typing import Union
|
||||
|
||||
import marl_factory_grid.modules.batteries.constants
|
||||
from marl_factory_grid.environment.actions import Action
|
||||
from marl_factory_grid.utils.results import ActionResult
|
||||
|
||||
@@ -24,5 +23,6 @@ class BtryCharge(Action):
|
||||
else:
|
||||
valid = c.NOT_VALID
|
||||
state.print(f'{entity.name} failed to charged batteries at {entity.pos}.')
|
||||
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=valid,
|
||||
reward=marl_factory_grid.modules.batteries.constants.REWARD_CHARGE_VALID if valid else marl_factory_grid.modules.batteries.constants.Reward_CHARGE_FAIL)
|
||||
reward=b.REWARD_CHARGE_VALID if valid else b.Reward_CHARGE_FAIL)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.environment.entity.entity import Entity
|
||||
from marl_factory_grid.environment.entity.object import _Object
|
||||
from marl_factory_grid.environment.entity.object import Object
|
||||
from marl_factory_grid.modules.batteries import constants as b
|
||||
from marl_factory_grid.utils.utility_classes import RenderEntity
|
||||
|
||||
|
||||
class Battery(_Object):
|
||||
class Battery(Object):
|
||||
|
||||
@property
|
||||
def var_can_be_bound(self):
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from typing import List, Union
|
||||
|
||||
import marl_factory_grid.modules.batteries.constants
|
||||
from marl_factory_grid.environment.rules import Rule
|
||||
from marl_factory_grid.utils.results import TickResult, DoneResult
|
||||
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.environment.rules import Rule
|
||||
from marl_factory_grid.modules.batteries import constants as b
|
||||
from marl_factory_grid.utils.results import TickResult, DoneResult
|
||||
|
||||
|
||||
class BatteryDecharge(Rule):
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from numpy import random
|
||||
|
||||
from marl_factory_grid.environment.entity.entity import Entity
|
||||
from marl_factory_grid.utils.utility_classes import RenderEntity
|
||||
from marl_factory_grid.modules.clean_up import constants as d
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
from typing import Union, List, Tuple
|
||||
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.utils.results import Result
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.modules.clean_up.entitites import DirtPile
|
||||
from marl_factory_grid.utils.results import Result
|
||||
|
||||
|
||||
class DirtPiles(Collection):
|
||||
|
||||
@@ -49,7 +49,7 @@ class RespawnDirt(Rule):
|
||||
def tick_step(self, state):
|
||||
collection = state[d.DIRT]
|
||||
if self._next_dirt_spawn < 0:
|
||||
pass # No DirtPile Spawn
|
||||
result = [] # No DirtPile Spawn
|
||||
elif not self._next_dirt_spawn:
|
||||
result = [collection.trigger_spawn(state, coords_or_quantity=self.respawn_n, amount=self.respawn_amount)]
|
||||
self._next_dirt_spawn = self.respawn_freq
|
||||
|
||||
@@ -21,4 +21,4 @@ class DestAction(Action):
|
||||
valid = c.NOT_VALID
|
||||
state.print(f'{entity.name} just tried to do_wait_action do_wait_action at {entity.pos} but failed')
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=valid,
|
||||
reward=marl_factory_grid.modules.destinations.constants.REWARD_WAIT_VALID if valid else marl_factory_grid.modules.destinations.constants.REWARD_WAIT_FAIL)
|
||||
reward=d.REWARD_WAIT_VALID if valid else d.REWARD_WAIT_FAIL)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.modules.destinations.entitites import Destination
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.modules.destinations import constants as d
|
||||
|
||||
|
||||
class Destinations(Collection):
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Union
|
||||
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.modules.doors import constants as d
|
||||
from marl_factory_grid.modules.doors.entitites import Door
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
USE_DOOR_VALID: float = -0.00
|
||||
USE_DOOR_FAIL: float = -0.01
|
||||
USE_DOOR_FAIL: float = -0.01
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import random
|
||||
from typing import List, Union
|
||||
from typing import List
|
||||
|
||||
from marl_factory_grid.environment.rules import Rule
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.environment.rules import Rule
|
||||
from marl_factory_grid.utils.results import TickResult
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ class AgentSingleZonePlacementBeta(Rule):
|
||||
super().__init__()
|
||||
|
||||
def on_init(self, state, lvl_map):
|
||||
zones = state[c.ZONES]
|
||||
n_zones = state[c.ZONES]
|
||||
agents = state[c.AGENT]
|
||||
if len(self.coordinates) == len(agents):
|
||||
coordinates = self.coordinates
|
||||
@@ -31,4 +29,4 @@ class AgentSingleZonePlacementBeta(Rule):
|
||||
return []
|
||||
|
||||
def tick_post_step(self, state) -> List[TickResult]:
|
||||
return []
|
||||
return []
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from typing import NamedTuple
|
||||
|
||||
|
||||
SYMBOL_NO_ITEM = 0
|
||||
SYMBOL_DROP_OFF = 1
|
||||
# Item Env
|
||||
|
||||
@@ -14,27 +14,14 @@ class Item(Entity):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def auto_despawn(self):
|
||||
return self._auto_despawn
|
||||
|
||||
@property
|
||||
def encoding(self):
|
||||
# Edit this if you want items to be drawn in the ops differently
|
||||
return 1
|
||||
|
||||
def set_auto_despawn(self, auto_despawn):
|
||||
self._auto_despawn = auto_despawn
|
||||
|
||||
def summarize_state(self) -> dict:
|
||||
super_summarization = super(Item, self).summarize_state()
|
||||
super_summarization.update(dict(auto_despawn=self.auto_despawn))
|
||||
return super_summarization
|
||||
|
||||
|
||||
class DropOffLocation(Entity):
|
||||
|
||||
|
||||
def render(self):
|
||||
return RenderEntity(i.DROP_OFF, self.pos)
|
||||
|
||||
@@ -42,18 +29,16 @@ class DropOffLocation(Entity):
|
||||
def encoding(self):
|
||||
return i.SYMBOL_DROP_OFF
|
||||
|
||||
def __init__(self, *args, storage_size_until_full: int = 5, auto_item_despawn_interval: int = 5, **kwargs):
|
||||
def __init__(self, *args, storage_size_until_full: int = 5, **kwargs):
|
||||
super(DropOffLocation, self).__init__(*args, **kwargs)
|
||||
self.auto_item_despawn_interval = auto_item_despawn_interval
|
||||
self.storage = deque(maxlen=storage_size_until_full or None)
|
||||
|
||||
def place_item(self, item: Item):
|
||||
if self.is_full:
|
||||
raise RuntimeWarning("There is currently no way to clear the storage or make it unfull.")
|
||||
return bc.NOT_VALID # in Zeile 81 verschieben?
|
||||
return bc.NOT_VALID
|
||||
else:
|
||||
self.storage.append(item)
|
||||
item.set_auto_despawn(self.auto_item_despawn_interval)
|
||||
return c.VALID
|
||||
|
||||
@property
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from random import shuffle
|
||||
|
||||
from marl_factory_grid.modules.items import constants as i
|
||||
from marl_factory_grid.environment import constants as c
|
||||
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.objects import _Objects
|
||||
from marl_factory_grid.environment.groups.mixins import IsBoundMixin
|
||||
from marl_factory_grid.environment.entity.agent import Agent
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import IsBoundMixin
|
||||
from marl_factory_grid.environment.groups.objects import Objects
|
||||
from marl_factory_grid.modules.items import constants as i
|
||||
from marl_factory_grid.modules.items.entitites import Item, DropOffLocation
|
||||
from marl_factory_grid.utils.results import Result
|
||||
|
||||
@@ -74,13 +71,12 @@ class Inventory(IsBoundMixin, Collection):
|
||||
self._collection = collection
|
||||
|
||||
|
||||
class Inventories(_Objects):
|
||||
class Inventories(Objects):
|
||||
_entity = Inventory
|
||||
|
||||
var_can_move = False
|
||||
var_has_position = False
|
||||
|
||||
|
||||
symbol = None
|
||||
|
||||
@property
|
||||
@@ -116,7 +112,6 @@ class Inventories(_Objects):
|
||||
return [val.summarize_states(**kwargs) for key, val in self.items()]
|
||||
|
||||
|
||||
|
||||
class DropOffLocations(Collection):
|
||||
_entity = DropOffLocation
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
DROP_OFF_VALID: float = 0.1
|
||||
DROP_OFF_FAIL: float = -0.1
|
||||
PICK_UP_FAIL: float = -0.1
|
||||
PICK_UP_VALID: float = 0.1
|
||||
PICK_UP_VALID: float = 0.1
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from typing import Union
|
||||
|
||||
import marl_factory_grid.modules.machines.constants
|
||||
from marl_factory_grid.environment.actions import Action
|
||||
from marl_factory_grid.utils.results import ActionResult
|
||||
|
||||
from marl_factory_grid.modules.machines import constants as m, rewards as r
|
||||
from marl_factory_grid.modules.machines import constants as m
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.utils import helpers as h
|
||||
|
||||
@@ -16,8 +17,10 @@ class MachineAction(Action):
|
||||
def do(self, entity, state) -> Union[None, ActionResult]:
|
||||
if machine := h.get_first(state[m.MACHINES].by_pos(entity.pos)):
|
||||
if valid := machine.maintain():
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=valid, reward=r.MAINTAIN_VALID)
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=valid, reward=marl_factory_grid.modules.machines.constants.MAINTAIN_VALID)
|
||||
else:
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=valid, reward=r.MAINTAIN_FAIL)
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=valid, reward=marl_factory_grid.modules.machines.constants.MAINTAIN_FAIL)
|
||||
else:
|
||||
return ActionResult(entity=entity, identifier=self._identifier, validity=c.NOT_VALID, reward=r.MAINTAIN_FAIL)
|
||||
return ActionResult(entity=entity, identifier=self._identifier,
|
||||
validity=c.NOT_VALID, reward=marl_factory_grid.modules.machines.constants.MAINTAIN_FAIL
|
||||
)
|
||||
|
||||
@@ -11,3 +11,7 @@ STATE_MAINTAIN = 'maintenance'
|
||||
SYMBOL_WORK = 1
|
||||
SYMBOL_IDLE = 0.6
|
||||
SYMBOL_MAINTAIN = 0.3
|
||||
MAINTAIN_VALID: float = 0.5
|
||||
MAINTAIN_FAIL: float = -0.1
|
||||
FAIL_MISSING_MAINTENANCE: float = -0.5
|
||||
NONE: float = 0
|
||||
|
||||
@@ -31,11 +31,10 @@ class Machine(Entity):
|
||||
return c.NOT_VALID
|
||||
|
||||
def tick(self, state):
|
||||
# if self.status == m.STATE_MAINTAIN and any([c.AGENT in x.name for x in self.tile.guests]):
|
||||
if self.status == m.STATE_MAINTAIN and any([c.AGENT in x.name for x in state.entities.pos_dict[self.pos]]):
|
||||
others = state.entities.pos_dict[self.pos]
|
||||
if self.status == m.STATE_MAINTAIN and any([c.AGENT in x.name for x in others]):
|
||||
return TickResult(identifier=self.name, validity=c.VALID, entity=self)
|
||||
# elif self.status == m.STATE_MAINTAIN and not any([c.AGENT in x.name for x in self.tile.guests]):
|
||||
elif self.status == m.STATE_MAINTAIN and not any([c.AGENT in x.name for x in state.entities.pos_dict[self.pos]]):
|
||||
elif self.status == m.STATE_MAINTAIN and not any([c.AGENT in x.name for x in others]):
|
||||
self.status = m.STATE_WORK
|
||||
self.reset_counter()
|
||||
return None
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Union, List, Tuple
|
||||
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
|
||||
from .entitites import Machine
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
MAINTAIN_VALID: float = 0.5
|
||||
MAINTAIN_FAIL: float = -0.1
|
||||
FAIL_MISSING_MAINTENANCE: float = -0.5
|
||||
|
||||
NONE: float = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
MAINTAINER = 'Maintainer' # TEMPLATE _identifier. Define your own!
|
||||
MAINTAINERS = 'Maintainers' # TEMPLATE _identifier. Define your own!
|
||||
|
||||
MAINTAINER_COLLISION_REWARD = -5
|
||||
|
||||
@@ -4,7 +4,6 @@ from marl_factory_grid.environment.groups.collection import Collection
|
||||
from .entities import Maintainer
|
||||
from ..machines import constants as mc
|
||||
from ..machines.actions import MachineAction
|
||||
from ...utils.states import Gamestate
|
||||
|
||||
|
||||
class Maintainers(Collection):
|
||||
@@ -23,8 +22,6 @@ class Maintainers(Collection):
|
||||
self.size = size
|
||||
self._spawnrule = spawnrule
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def spawn(self, coords_or_quantity: Union[int, List[Tuple[(int, int)]]], *entity_args):
|
||||
self.add_items([self._entity(mc.MACHINES, MachineAction(), pos) for pos in coords_or_quantity])
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
MAINTAINER_COLLISION_REWARD = -5
|
||||
@@ -1,15 +1,16 @@
|
||||
from typing import List
|
||||
|
||||
import marl_factory_grid.modules.maintenance.constants
|
||||
from marl_factory_grid.environment.rules import Rule
|
||||
from marl_factory_grid.utils.results import TickResult, DoneResult
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from . import rewards as r
|
||||
from . import constants as M
|
||||
|
||||
|
||||
class MoveMaintainers(Rule):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def tick_step(self, state) -> List[TickResult]:
|
||||
for maintainer in state[M.MAINTAINERS]:
|
||||
@@ -20,8 +21,8 @@ class MoveMaintainers(Rule):
|
||||
|
||||
class DoneAtMaintainerCollision(Rule):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def on_check_done(self, state) -> List[DoneResult]:
|
||||
agents = list(state[c.AGENT].values())
|
||||
@@ -30,5 +31,5 @@ class DoneAtMaintainerCollision(Rule):
|
||||
for agent in agents:
|
||||
if agent.pos in m_pos:
|
||||
done_results.append(DoneResult(entity=agent, validity=c.VALID, identifier=self.name,
|
||||
reward=r.MAINTAINER_COLLISION_REWARD))
|
||||
reward=marl_factory_grid.modules.maintenance.constants.MAINTAINER_COLLISION_REWARD))
|
||||
return done_results
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import random
|
||||
from typing import List, Tuple
|
||||
|
||||
from marl_factory_grid.environment.entity.object import _Object
|
||||
from marl_factory_grid.environment.entity.object import Object
|
||||
|
||||
|
||||
class Zone(_Object):
|
||||
class Zone(Object):
|
||||
|
||||
@property
|
||||
def positions(self):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from marl_factory_grid.environment.groups.objects import _Objects
|
||||
from marl_factory_grid.environment.groups.objects import Objects
|
||||
from marl_factory_grid.modules.zones import Zone
|
||||
|
||||
|
||||
class Zones(_Objects):
|
||||
class Zones(Objects):
|
||||
symbol = None
|
||||
_entity = Zone
|
||||
|
||||
|
||||
Reference in New Issue
Block a user