refactoring and init.py
2
.gitignore
vendored
@ -553,7 +553,7 @@ celerybeat.pid
|
|||||||
*.sage.py
|
*.sage.py
|
||||||
|
|
||||||
# Environments
|
# Environments
|
||||||
# .env
|
# .environment
|
||||||
.env/
|
.env/
|
||||||
.venv/
|
.venv/
|
||||||
env/
|
env/
|
||||||
|
29
README.md
@ -80,36 +80,35 @@ General:
|
|||||||
level_name: rooms # 'double', 'large', 'simple', ...
|
level_name: rooms # 'double', 'large', 'simple', ...
|
||||||
```
|
```
|
||||||
... or create your own , maybe with the help of [asciiflow.com](https://asciiflow.com/#/).
|
... or create your own , maybe with the help of [asciiflow.com](https://asciiflow.com/#/).
|
||||||
Be sure to use '#' as Walls, '-' as free (walkable) Floor-Tiles, 'D' for Doors.
|
Make sure to use `#` as [Walls](mfg_package/environment/entity/wall_floor.py), `-` as free (walkable) [Floor](mfg_package/environment/entity/wall_floor.py)-Tiles, `D` for [Walls](./modules/doors/entities.py).
|
||||||
Custom Entites (define you own) may bring their own "Symbol"
|
Other Entites (define you own) may bring their own `Symbols`
|
||||||
|
|
||||||
#### Entites
|
#### Entites
|
||||||
Entites are either [Objects](./environment/entity/object.py) for tracking stats or env. [Entity](./environment/entity/entity.py) which can interact.
|
Entites, either [Objects](mfg_package/environment/entity/object.py) for tracking stats
|
||||||
|
or env. [Entity](mfg_package/environment/entity/entity.py) which can interact.
|
||||||
Abstract Entities are provided.
|
Abstract Entities are provided.
|
||||||
|
|
||||||
#### Groups
|
#### Groups
|
||||||
[Groups](./environment/groups/objects.py) are entity Sets that provide administrative access to all group members.
|
[Groups](mfg_package/environment/groups/objects.py) are entity Sets that provide administrative access to all group members.
|
||||||
All [Entites](./environment/entity/global_entities.py) are available at runtime as EnvState property.
|
All [Entites](mfg_package/environment/entity/global_entities.py) are available at runtime as EnvState property.
|
||||||
|
|
||||||
|
|
||||||
#### Rules
|
#### Rules
|
||||||
[Rules](./environment/entity/object.py) define how the environment behaves on micro-scale.
|
[Rules](mfg_package/environment/entity/object.py) define how the environment behaves on micro-scale.
|
||||||
Each of the hookes ('on_init', 'pre-step', 'on_step', 'post_step', 'on_done')
|
Each of the hookes (`on_init`, `pre_step`, `on_step`, '`post_step`', `on_done`)
|
||||||
provide env-access to implement customn logic, calculate rewards, or gather information.
|
provide env-access to implement customn logic, calculate rewards, or gather information.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[Results](mfg_package/environment/entity/object.py) provide a way to return `rule` evaluations such as rewards and state reports
|
||||||
|
|
||||||
[Results](./environment/entity/object.py) provide a way to return 'rule' evaluations such as rewards and state reports
|
|
||||||
back to the environment.
|
back to the environment.
|
||||||
#### Assets
|
#### Assets
|
||||||
Make sure to bring your own assets for each Entity, that is living in the Gridworld, the 'Renderer' relies on it.
|
Make sure to bring your own assets for each Entity living in the Gridworl as the `Renderer` relies on it.
|
||||||
PNG-files (transparent background) of square aspect-ratio should do the job, in general.
|
PNG-files (transparent background) of square aspect-ratio should do the job, in general.
|
||||||
|
|
||||||
<div style="margin:0 auto;">
|
<img src=".\environment\assets\wall.png" width="5%">
|
||||||
<img src=".\environment\assets\wall.png" width="10%"> | <img src=".\environment\assets\agent\agent.png" width="10%">
|
    
|
||||||
</div>
|
<img src=".\environment\assets\agent\agent.png" width="5%">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
from algorithms.marl.base_ac import BaseActorCritic
|
|
||||||
from algorithms.marl.iac import LoopIAC
|
|
||||||
from algorithms.marl.snac import LoopSNAC
|
|
||||||
from algorithms.marl.seac import LoopSEAC
|
|
||||||
from algorithms.marl.mappo import LoopMAPPO
|
|
||||||
from algorithms.marl.memory import MARLActorCriticMemory
|
|
BIN
images/Hooks_FIKS.png
Normal file
After Width: | Height: | Size: 296 KiB |
1
mfg_package/algorithms/marl/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from mfg_package.algorithms.marl.memory import MARLActorCriticMemory
|
@ -2,8 +2,8 @@ import torch
|
|||||||
from typing import Union, List, Dict
|
from typing import Union, List, Dict
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from torch.distributions import Categorical
|
from torch.distributions import Categorical
|
||||||
from algorithms.marl.memory import MARLActorCriticMemory
|
from mfg_package.algorithms.marl.memory import MARLActorCriticMemory
|
||||||
from algorithms.utils import add_env_props, instantiate_class
|
from mfg_package.algorithms.utils import add_env_props, instantiate_class
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from collections import deque
|
from collections import deque
|
||||||
@ -18,7 +18,7 @@ class Names:
|
|||||||
HIDDEN_ACTOR = 'hidden_actor'
|
HIDDEN_ACTOR = 'hidden_actor'
|
||||||
HIDDEN_CRITIC = 'hidden_critic'
|
HIDDEN_CRITIC = 'hidden_critic'
|
||||||
AGENT = 'agent'
|
AGENT = 'agent'
|
||||||
ENV = 'env'
|
ENV = 'environment'
|
||||||
N_AGENTS = 'n_agents'
|
N_AGENTS = 'n_agents'
|
||||||
ALGORITHM = 'algorithm'
|
ALGORITHM = 'algorithm'
|
||||||
MAX_STEPS = 'max_steps'
|
MAX_STEPS = 'max_steps'
|
||||||
@ -172,7 +172,7 @@ class BaseActorCritic:
|
|||||||
eps_rew += torch.tensor(reward)
|
eps_rew += torch.tensor(reward)
|
||||||
results.append(eps_rew.tolist() + [sum(eps_rew).item()] + [episode])
|
results.append(eps_rew.tolist() + [sum(eps_rew).item()] + [episode])
|
||||||
episode += 1
|
episode += 1
|
||||||
agent_columns = [f'agent#{i}' for i in range(self.cfg['env']['n_agents'])]
|
agent_columns = [f'agent#{i}' for i in range(self.cfg['environment']['n_agents'])]
|
||||||
results = pd.DataFrame(results, columns=agent_columns + ['sum', 'episode'])
|
results = pd.DataFrame(results, columns=agent_columns + ['sum', 'episode'])
|
||||||
results = pd.melt(results, id_vars=['episode'], value_vars=agent_columns + ['sum'], value_name='reward', var_name='agent')
|
results = pd.melt(results, id_vars=['episode'], value_vars=agent_columns + ['sum'], value_name='reward', var_name='agent')
|
||||||
return results
|
return results
|
@ -1,9 +1,9 @@
|
|||||||
import torch
|
import torch
|
||||||
from algorithms.marl.base_ac import BaseActorCritic, nms
|
from mfg_package.algorithms.marl.base_ac import BaseActorCritic, nms
|
||||||
from algorithms.utils import instantiate_class
|
from mfg_package.algorithms.utils import instantiate_class
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from natsort import natsorted
|
from natsort import natsorted
|
||||||
from algorithms.marl.memory import MARLActorCriticMemory
|
from mfg_package.algorithms.marl.memory import MARLActorCriticMemory
|
||||||
|
|
||||||
|
|
||||||
class LoopIAC(BaseActorCritic):
|
class LoopIAC(BaseActorCritic):
|
@ -1,10 +1,9 @@
|
|||||||
from algorithms.marl.base_ac import Names as nms
|
from mfg_package.algorithms.marl.base_ac import Names as nms
|
||||||
from algorithms.marl import LoopSNAC
|
from mfg_package.algorithms.marl.snac import LoopSNAC
|
||||||
from algorithms.marl.memory import MARLActorCriticMemory
|
from mfg_package.algorithms.marl.memory import MARLActorCriticMemory
|
||||||
import random
|
|
||||||
import torch
|
import torch
|
||||||
from torch.distributions import Categorical
|
from torch.distributions import Categorical
|
||||||
from algorithms.utils import instantiate_class
|
from mfg_package.algorithms.utils import instantiate_class
|
||||||
|
|
||||||
|
|
||||||
class LoopMAPPO(LoopSNAC):
|
class LoopMAPPO(LoopSNAC):
|
@ -1,8 +1,8 @@
|
|||||||
import torch
|
import torch
|
||||||
from torch.distributions import Categorical
|
from torch.distributions import Categorical
|
||||||
from algorithms.marl.iac import LoopIAC
|
from mfg_package.algorithms.marl.iac import LoopIAC
|
||||||
from algorithms.marl.base_ac import nms
|
from mfg_package.algorithms.marl.base_ac import nms
|
||||||
from algorithms.marl.memory import MARLActorCriticMemory
|
from mfg_package.algorithms.marl.memory import MARLActorCriticMemory
|
||||||
|
|
||||||
|
|
||||||
class LoopSEAC(LoopIAC):
|
class LoopSEAC(LoopIAC):
|
@ -1,5 +1,5 @@
|
|||||||
from algorithms.marl.base_ac import BaseActorCritic
|
from mfg_package.algorithms.marl.base_ac import BaseActorCritic
|
||||||
from algorithms.marl.base_ac import nms
|
from mfg_package.algorithms.marl.base_ac import nms
|
||||||
import torch
|
import torch
|
||||||
from torch.distributions import Categorical
|
from torch.distributions import Categorical
|
||||||
from pathlib import Path
|
from pathlib import Path
|
@ -6,10 +6,9 @@ import numpy as np
|
|||||||
import networkx as nx
|
import networkx as nx
|
||||||
from networkx.algorithms.approximation import traveling_salesman as tsp
|
from networkx.algorithms.approximation import traveling_salesman as tsp
|
||||||
|
|
||||||
|
from mfg_package.modules.doors import constants as do
|
||||||
from modules.doors import constants as do
|
from mfg_package.environment import constants as c
|
||||||
from environment import constants as c
|
from mfg_package.utils.helpers import MOVEMAP
|
||||||
from environment.utils.helpers import MOVEMAP
|
|
||||||
|
|
||||||
from abc import abstractmethod, ABC
|
from abc import abstractmethod, ABC
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
from algorithms.static.TSP_base_agent import TSPBaseAgent
|
from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent
|
||||||
|
|
||||||
from modules.clean_up import constants as di
|
from mfg_package.modules.clean_up import constants as di
|
||||||
|
|
||||||
future_planning = 7
|
future_planning = 7
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from algorithms.static.TSP_base_agent import TSPBaseAgent
|
from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent
|
||||||
|
|
||||||
from modules.items import constants as i
|
from mfg_package.modules.items import constants as i
|
||||||
|
|
||||||
future_planning = 7
|
future_planning = 7
|
||||||
inventory_size = 3
|
inventory_size = 3
|
@ -1,7 +1,7 @@
|
|||||||
from algorithms.static.TSP_base_agent import TSPBaseAgent
|
from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent
|
||||||
|
|
||||||
from modules.destinations import constants as d
|
from mfg_package.modules.destinations import constants as d
|
||||||
from modules.doors import constants as do
|
from mfg_package.modules.doors import constants as do
|
||||||
|
|
||||||
future_planning = 7
|
future_planning = 7
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
from algorithms.static.TSP_base_agent import TSPBaseAgent
|
from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent
|
||||||
|
|
||||||
future_planning = 7
|
future_planning = 7
|
||||||
|
|
@ -56,7 +56,7 @@ def load_yaml_file(path: Path):
|
|||||||
|
|
||||||
|
|
||||||
def add_env_props(cfg):
|
def add_env_props(cfg):
|
||||||
env = instantiate_class(cfg['env'].copy())
|
env = instantiate_class(cfg['environment'].copy())
|
||||||
cfg['agent'].update(dict(observation_size=list(env.observation_space.shape),
|
cfg['agent'].update(dict(observation_size=list(env.observation_space.shape),
|
||||||
n_actions=env.action_space.n))
|
n_actions=env.action_space.n))
|
||||||
|
|
@ -1,10 +1,9 @@
|
|||||||
import abc
|
import abc
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment import rewards as r
|
from mfg_package.environment import rewards as r, constants as c
|
||||||
from environment import constants as c
|
from mfg_package.utils.helpers import MOVEMAP
|
||||||
from environment.utils.helpers import MOVEMAP
|
from mfg_package.utils.results import ActionResult
|
||||||
from environment.utils.results import ActionResult
|
|
||||||
|
|
||||||
|
|
||||||
class Action(abc.ABC):
|
class Action(abc.ABC):
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
@ -1,12 +1,12 @@
|
|||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.actions import Action
|
from mfg_package.environment.actions import Action
|
||||||
from environment.entity.entity import Entity
|
from mfg_package.environment.entity.entity import Entity
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
from environment.utils import renderer
|
from mfg_package.utils import renderer
|
||||||
from environment.utils.helpers import is_move
|
from mfg_package.utils.helpers import is_move
|
||||||
from environment.utils.results import ActionResult, Result
|
from mfg_package.utils.results import ActionResult, Result
|
||||||
|
|
||||||
|
|
||||||
class Agent(Entity):
|
class Agent(Entity):
|
@ -1,12 +1,12 @@
|
|||||||
import abc
|
import abc
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.entity.object import EnvObject
|
from mfg_package.environment.entity.object import EnvObject
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
|
|
||||||
|
|
||||||
class Entity(EnvObject, abc.ABC):
|
class Entity(EnvObject, abc.ABC):
|
||||||
"""Full Env Entity that lives on the env Grid. Doors, Items, DirtPile etc..."""
|
"""Full Env Entity that lives on the environment Grid. Doors, Items, DirtPile etc..."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_position(self):
|
def has_position(self):
|
@ -1,8 +1,7 @@
|
|||||||
from abc import ABC, abstractmethod
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class Object:
|
class Object:
|
||||||
@ -67,7 +66,7 @@ class Object:
|
|||||||
|
|
||||||
class EnvObject(Object):
|
class EnvObject(Object):
|
||||||
|
|
||||||
"""Objects that hold Information that are observable, but have no position on the env grid. Inventories etc..."""
|
"""Objects that hold Information that are observable, but have no position on the environment grid. Inventories etc..."""
|
||||||
|
|
||||||
_u_idx = defaultdict(lambda: 0)
|
_u_idx = defaultdict(lambda: 0)
|
||||||
|
|
@ -2,8 +2,8 @@ import math
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from environment.entity.mixin import BoundEntityMixin
|
from mfg_package.environment.entity.mixin import BoundEntityMixin
|
||||||
from environment.entity.object import Object, EnvObject
|
from mfg_package.environment.entity.object import Object, EnvObject
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
@ -2,10 +2,10 @@ from typing import List
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.entity.object import EnvObject
|
from mfg_package.environment.entity.object import EnvObject
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
from environment.utils import helpers as h
|
from mfg_package.utils import helpers as h
|
||||||
|
|
||||||
|
|
||||||
class Floor(EnvObject):
|
class Floor(EnvObject):
|
@ -8,13 +8,13 @@ from typing import Union
|
|||||||
|
|
||||||
import gymnasium as gym
|
import gymnasium as gym
|
||||||
|
|
||||||
from environment.utils.level_parser import LevelParser
|
from mfg_package.utils.level_parser import LevelParser
|
||||||
from environment.utils.observation_builder import OBSBuilder
|
from mfg_package.utils.observation_builder import OBSBuilder
|
||||||
from environment.utils.config_parser import FactoryConfigParser
|
from mfg_package.utils.config_parser import FactoryConfigParser
|
||||||
from environment.utils import helpers as h
|
from mfg_package.utils import helpers as h
|
||||||
import environment.constants as c
|
import mfg_package.environment.constants as c
|
||||||
|
|
||||||
from environment.utils.states import Gamestate
|
from mfg_package.utils.states import Gamestate
|
||||||
|
|
||||||
REC_TAC = 'rec_'
|
REC_TAC = 'rec_'
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ class BaseFactory(gym.Env):
|
|||||||
# Returns: Reward, Info
|
# Returns: Reward, Info
|
||||||
rewards = defaultdict(lambda: 0.0)
|
rewards = defaultdict(lambda: 0.0)
|
||||||
|
|
||||||
# Gather per agent env rewards and
|
# Gather per agent environment rewards and
|
||||||
# Combine Info dicts into a global one
|
# Combine Info dicts into a global one
|
||||||
combined_info_dict = defaultdict(lambda: 0.0)
|
combined_info_dict = defaultdict(lambda: 0.0)
|
||||||
for result in chain(tick_results, done_check_results):
|
for result in chain(tick_results, done_check_results):
|
||||||
@ -171,7 +171,7 @@ class BaseFactory(gym.Env):
|
|||||||
# noinspection PyGlobalUndefined
|
# noinspection PyGlobalUndefined
|
||||||
def render(self, mode='human'):
|
def render(self, mode='human'):
|
||||||
if not self._renderer: # lazy init
|
if not self._renderer: # lazy init
|
||||||
from environment.utils.renderer import Renderer
|
from mfg_package.utils.renderer import Renderer
|
||||||
global Renderer
|
global Renderer
|
||||||
self._renderer = Renderer(self.map.level_shape, view_radius=self.conf.pomdp_r, fps=10)
|
self._renderer = Renderer(self.map.level_shape, view_radius=self.conf.pomdp_r, fps=10)
|
||||||
|
|
@ -1,7 +1,6 @@
|
|||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment.groups.mixins import PositionMixin
|
from mfg_package.environment.groups.mixins import PositionMixin
|
||||||
from environment.entity.agent import Agent
|
from mfg_package.environment.entity.agent import Agent
|
||||||
import environment.constants as c
|
|
||||||
|
|
||||||
|
|
||||||
class Agents(PositionMixin, EnvObjects):
|
class Agents(PositionMixin, EnvObjects):
|
@ -1,5 +1,5 @@
|
|||||||
from environment.groups.objects import Objects
|
from mfg_package.environment.groups.objects import Objects
|
||||||
from environment.entity.object import EnvObject
|
from mfg_package.environment.entity.object import EnvObject
|
||||||
|
|
||||||
|
|
||||||
class EnvObjects(Objects):
|
class EnvObjects(Objects):
|
@ -2,9 +2,8 @@ from collections import defaultdict
|
|||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from environment.groups.objects import Objects
|
from mfg_package.environment.groups.objects import Objects
|
||||||
from environment.entity.entity import Entity
|
from mfg_package.utils.helpers import POS_MASK
|
||||||
from environment.utils.helpers import POS_MASK
|
|
||||||
|
|
||||||
|
|
||||||
class Entities(Objects):
|
class Entities(Objects):
|
@ -1,11 +1,6 @@
|
|||||||
from abc import ABC
|
from mfg_package.environment import constants as c
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
import numpy as np
|
from mfg_package.environment.entity.entity import Entity
|
||||||
|
|
||||||
from environment import constants as c
|
|
||||||
|
|
||||||
from environment.entity.entity import Entity
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences,PyTypeChecker,PyArgumentList
|
# noinspection PyUnresolvedReferences,PyTypeChecker,PyArgumentList
|
@ -3,7 +3,7 @@ from typing import List
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from environment.entity.object import Object
|
from mfg_package.environment.entity.object import Object
|
||||||
|
|
||||||
|
|
||||||
class Objects:
|
class Objects:
|
@ -1,14 +1,13 @@
|
|||||||
import numbers
|
from typing import List, Union
|
||||||
from typing import List, Union, Dict
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment.groups.objects import Objects
|
from mfg_package.environment.groups.objects import Objects
|
||||||
from environment.groups.mixins import HasBoundedMixin, PositionMixin
|
from mfg_package.environment.groups.mixins import HasBoundedMixin, PositionMixin
|
||||||
from environment.entity.util import PlaceHolder, GlobalPosition
|
from mfg_package.environment.entity.util import GlobalPosition
|
||||||
from environment.utils import helpers as h
|
from mfg_package.utils import helpers as h
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class Combined(PositionMixin, EnvObjects):
|
class Combined(PositionMixin, EnvObjects):
|
@ -1,12 +1,10 @@
|
|||||||
import random
|
import random
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import numpy as np
|
from mfg_package.environment import constants as c
|
||||||
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment import constants as c
|
from mfg_package.environment.groups.mixins import PositionMixin
|
||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.entity.wall_floor import Wall, Floor
|
||||||
from environment.groups.mixins import PositionMixin
|
|
||||||
from environment.entity.wall_floor import Wall, Floor
|
|
||||||
|
|
||||||
|
|
||||||
class Walls(PositionMixin, EnvObjects):
|
class Walls(PositionMixin, EnvObjects):
|
@ -1,9 +1,8 @@
|
|||||||
import abc
|
import abc
|
||||||
from typing import Union, List
|
from typing import List
|
||||||
|
|
||||||
from environment.utils.results import Result, TickResult, DoneResult, ActionResult
|
from mfg_package.utils.results import TickResult, DoneResult
|
||||||
from environment import constants as c
|
from mfg_package.environment import rewards as r, constants as c
|
||||||
from environment import rewards as r
|
|
||||||
|
|
||||||
|
|
||||||
class Rule(abc.ABC):
|
class Rule(abc.ABC):
|
@ -5,12 +5,12 @@ from typing import Union
|
|||||||
|
|
||||||
from gymnasium import Wrapper
|
from gymnasium import Wrapper
|
||||||
|
|
||||||
from environment.utils.helpers import IGNORED_DF_COLUMNS
|
from mfg_package.utils.helpers import IGNORED_DF_COLUMNS
|
||||||
from environment.factory import REC_TAC
|
from mfg_package.environment.factory import REC_TAC
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from plotting.compare_runs import plot_single_run
|
from mfg_package.plotting.compare_runs import plot_single_run
|
||||||
|
|
||||||
|
|
||||||
class EnvMonitor(Wrapper):
|
class EnvMonitor(Wrapper):
|
@ -4,13 +4,13 @@ from os import PathLike
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
import yaml
|
||||||
from gymnasium import Wrapper
|
from gymnasium import Wrapper
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import simplejson
|
|
||||||
|
|
||||||
from environment.factory import REC_TAC
|
from mfg_package.environment.factory import REC_TAC
|
||||||
|
|
||||||
|
|
||||||
class EnvRecorder(Wrapper):
|
class EnvRecorder(Wrapper):
|
||||||
@ -81,7 +81,7 @@ class EnvRecorder(Wrapper):
|
|||||||
# cls.out_file.unlink(missing_ok=True)
|
# cls.out_file.unlink(missing_ok=True)
|
||||||
with filepath.open('w') as f:
|
with filepath.open('w') as f:
|
||||||
if only_deltas:
|
if only_deltas:
|
||||||
from deepdiff import DeepDiff, Delta
|
from deepdiff import DeepDiff
|
||||||
diff_dict = [DeepDiff(t1,t2, ignore_order=True)
|
diff_dict = [DeepDiff(t1,t2, ignore_order=True)
|
||||||
for t1, t2 in zip(self._recorder_out_list, self._recorder_out_list[1:])
|
for t1, t2 in zip(self._recorder_out_list, self._recorder_out_list[1:])
|
||||||
]
|
]
|
||||||
@ -95,7 +95,7 @@ class EnvRecorder(Wrapper):
|
|||||||
'header': self.env.summarize_header
|
'header': self.env.summarize_header
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
simplejson.dump(out_dict, f, indent=4)
|
yaml.dump(out_dict, f, indent=4)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
print('Shit')
|
print('Shit')
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment.utils.results import TickResult, DoneResult
|
from mfg_package.utils.results import TickResult, DoneResult
|
||||||
|
|
||||||
|
|
||||||
class TemplateRule(Rule):
|
class TemplateRule(Rule):
|
@ -1,10 +1,10 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment.actions import Action
|
from mfg_package.environment.actions import Action
|
||||||
from environment.utils.results import ActionResult
|
from mfg_package.utils.results import ActionResult
|
||||||
|
|
||||||
from modules.batteries import constants as b, rewards as r
|
from mfg_package.modules.batteries import constants as b, rewards as r
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class BtryCharge(Action):
|
class BtryCharge(Action):
|
@ -1,10 +1,10 @@
|
|||||||
from environment.entity.mixin import BoundEntityMixin
|
from mfg_package.environment.entity.mixin import BoundEntityMixin
|
||||||
from environment.entity.object import EnvObject
|
from mfg_package.environment.entity.object import EnvObject
|
||||||
from environment.entity.entity import Entity
|
from mfg_package.environment.entity.entity import Entity
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
|
|
||||||
from modules.batteries import constants as b
|
from mfg_package.modules.batteries import constants as b
|
||||||
|
|
||||||
|
|
||||||
class Battery(BoundEntityMixin, EnvObject):
|
class Battery(BoundEntityMixin, EnvObject):
|
@ -1,6 +1,6 @@
|
|||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment.groups.mixins import PositionMixin, HasBoundedMixin
|
from mfg_package.environment.groups.mixins import PositionMixin, HasBoundedMixin
|
||||||
from modules.batteries.entitites import ChargePod, Battery
|
from mfg_package.modules.batteries.entitites import ChargePod, Battery
|
||||||
|
|
||||||
|
|
||||||
class Batteries(HasBoundedMixin, EnvObjects):
|
class Batteries(HasBoundedMixin, EnvObjects):
|
@ -1,9 +1,9 @@
|
|||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment.utils.results import TickResult, DoneResult
|
from mfg_package.utils.results import TickResult, DoneResult
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from modules.batteries import constants as b, rewards as r
|
from mfg_package.modules.batteries import constants as b, rewards as r
|
||||||
|
|
||||||
|
|
||||||
class Btry(Rule):
|
class Btry(Rule):
|
@ -1,11 +1,11 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment.actions import Action
|
from mfg_package.environment.actions import Action
|
||||||
from environment.utils.results import ActionResult
|
from mfg_package.utils.results import ActionResult
|
||||||
|
|
||||||
from modules.clean_up import constants as d, rewards as r
|
from mfg_package.modules.clean_up import constants as d, rewards as r
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class CleanUp(Action):
|
class CleanUp(Action):
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
@ -1,8 +1,8 @@
|
|||||||
from numpy import random
|
from numpy import random
|
||||||
|
|
||||||
from environment.entity.entity import Entity
|
from mfg_package.environment.entity.entity import Entity
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
from modules.clean_up import constants as d
|
from mfg_package.modules.clean_up import constants as d
|
||||||
|
|
||||||
|
|
||||||
class DirtPile(Entity):
|
class DirtPile(Entity):
|
@ -1,9 +1,9 @@
|
|||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment.groups.mixins import PositionMixin
|
from mfg_package.environment.groups.mixins import PositionMixin
|
||||||
from environment.entity.wall_floor import Floor
|
from mfg_package.environment.entity.wall_floor import Floor
|
||||||
from modules.clean_up.entitites import DirtPile
|
from mfg_package.modules.clean_up.entitites import DirtPile
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class DirtPiles(PositionMixin, EnvObjects):
|
class DirtPiles(PositionMixin, EnvObjects):
|
@ -1,7 +1,7 @@
|
|||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment.utils.results import DoneResult
|
from mfg_package.utils.results import DoneResult
|
||||||
from modules.clean_up import constants as d, rewards as r
|
from mfg_package.modules.clean_up import constants as d, rewards as r
|
||||||
|
|
||||||
|
|
||||||
class DirtAllCleanDone(Rule):
|
class DirtAllCleanDone(Rule):
|
@ -1,7 +1,7 @@
|
|||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment.utils.results import TickResult
|
from mfg_package.utils.results import TickResult
|
||||||
|
|
||||||
from modules.clean_up import constants as d
|
from mfg_package.modules.clean_up import constants as d
|
||||||
|
|
||||||
|
|
||||||
class DirtRespawnRule(Rule):
|
class DirtRespawnRule(Rule):
|
@ -1,9 +1,9 @@
|
|||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment.utils.helpers import is_move
|
from mfg_package.utils.helpers import is_move
|
||||||
from environment.utils.results import TickResult
|
from mfg_package.utils.results import TickResult
|
||||||
|
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from modules.clean_up import constants as d
|
from mfg_package.modules.clean_up import constants as d
|
||||||
|
|
||||||
|
|
||||||
class DirtSmearOnMove(Rule):
|
class DirtSmearOnMove(Rule):
|
@ -1,10 +1,10 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment.actions import Action
|
from mfg_package.environment.actions import Action
|
||||||
from environment.utils.results import ActionResult
|
from mfg_package.utils.results import ActionResult
|
||||||
|
|
||||||
from modules.destinations import constants as d, rewards as r
|
from mfg_package.modules.destinations import constants as d, rewards as r
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class DestAction(Action):
|
class DestAction(Action):
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
@ -1,10 +1,10 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from environment.entity.agent import Agent
|
from mfg_package.environment.entity.agent import Agent
|
||||||
from environment.entity.entity import Entity
|
from mfg_package.environment.entity.entity import Entity
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
from modules.destinations import constants as d
|
from mfg_package.modules.destinations import constants as d
|
||||||
|
|
||||||
|
|
||||||
class Destination(Entity):
|
class Destination(Entity):
|
@ -1,6 +1,6 @@
|
|||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment.groups.mixins import PositionMixin
|
from mfg_package.environment.groups.mixins import PositionMixin
|
||||||
from modules.destinations.entitites import Destination
|
from mfg_package.modules.destinations.entitites import Destination
|
||||||
|
|
||||||
|
|
||||||
class Destinations(PositionMixin, EnvObjects):
|
class Destinations(PositionMixin, EnvObjects):
|
@ -1,10 +1,10 @@
|
|||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment.utils.results import TickResult, DoneResult
|
from mfg_package.utils.results import TickResult, DoneResult
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
from modules.destinations import constants as d, rewards as r
|
from mfg_package.modules.destinations import constants as d, rewards as r
|
||||||
from modules.destinations.entitites import Destination
|
from mfg_package.modules.destinations.entitites import Destination
|
||||||
|
|
||||||
|
|
||||||
class DestinationReach(Rule):
|
class DestinationReach(Rule):
|
@ -1,10 +1,10 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment.actions import Action
|
from mfg_package.environment.actions import Action
|
||||||
from environment.utils.results import ActionResult
|
from mfg_package.utils.results import ActionResult
|
||||||
|
|
||||||
from modules.doors import constants as d, rewards as r
|
from mfg_package.modules.doors import constants as d, rewards as r
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class DoorUse(Action):
|
class DoorUse(Action):
|
Before Width: | Height: | Size: 699 B After Width: | Height: | Size: 699 B |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
@ -1,8 +1,8 @@
|
|||||||
from environment.entity.entity import Entity
|
from mfg_package.environment.entity.entity import Entity
|
||||||
from environment.utils.render import RenderEntity
|
from mfg_package.utils.render import RenderEntity
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
from modules.doors import constants as d
|
from mfg_package.modules.doors import constants as d
|
||||||
|
|
||||||
|
|
||||||
class DoorIndicator(Entity):
|
class DoorIndicator(Entity):
|
@ -1,9 +1,9 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment.groups.env_objects import EnvObjects
|
from mfg_package.environment.groups.env_objects import EnvObjects
|
||||||
from environment.groups.mixins import PositionMixin
|
from mfg_package.environment.groups.mixins import PositionMixin
|
||||||
from modules.doors import constants as d
|
from mfg_package.modules.doors import constants as d
|
||||||
from modules.doors.entitites import Door
|
from mfg_package.modules.doors.entitites import Door
|
||||||
|
|
||||||
|
|
||||||
class Doors(PositionMixin, EnvObjects):
|
class Doors(PositionMixin, EnvObjects):
|
@ -1,7 +1,7 @@
|
|||||||
from environment.rules import Rule
|
from mfg_package.environment.rules import Rule
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
from environment.utils.results import TickResult
|
from mfg_package.utils.results import TickResult
|
||||||
from modules.doors import constants as d
|
from mfg_package.modules.doors import constants as d
|
||||||
|
|
||||||
|
|
||||||
class DoorAutoClose(Rule):
|
class DoorAutoClose(Rule):
|
@ -1,10 +1,10 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from environment.actions import Action
|
from mfg_package.environment.actions import Action
|
||||||
from environment.utils.results import ActionResult
|
from mfg_package.utils.results import ActionResult
|
||||||
|
|
||||||
from modules.items import constants as i, rewards as r
|
from mfg_package.modules.items import constants as i, rewards as r
|
||||||
from environment import constants as c
|
from mfg_package.environment import constants as c
|
||||||
|
|
||||||
|
|
||||||
class ItemAction(Action):
|
class ItemAction(Action):
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |