39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
import uuid
|
|
from abc import ABC
|
|
class BaseAgent(ABC):
|
|
_bal="balance"
|
|
def __init__(self,simulation) -> None:
|
|
"""
|
|
Base class of an agent.
|
|
Simulation: to register tick method at.
|
|
"""
|
|
self.id=uuid.uuid4()
|
|
self.simulation=simulation
|
|
simulation.register_agent(self.id,self.tick,self.reset)
|
|
pass
|
|
def tick(self,tick,episode):
|
|
"""
|
|
Tick method for simulation to call to execute selected action
|
|
"""
|
|
assert "No Tick method has been provided"
|
|
pass
|
|
|
|
def reset(self,episode):
|
|
"""
|
|
Resets agent to new episode.
|
|
"""
|
|
assert "No reset method has been provided"
|
|
pass
|
|
|
|
def unregister(self):
|
|
"""
|
|
Disables agent by removing it from the simulation
|
|
"""
|
|
self.simulation.unregister_agent(id)
|
|
def register(self):
|
|
"""
|
|
Enables agent by adding it to the simulation:
|
|
"""
|
|
self.simulation.register_agent(self.id,self.tick,self.reset)
|
|
|