Skip to content
Snippets Groups Projects
Commit 47aa2ba5 authored by shinedday's avatar shinedday
Browse files

Add seed method

parent 3b3dd420
No related branches found
No related tags found
No related merge requests found
"""
Environment class
"""
from random import seed
import sys
import pathlib
sys.path.insert(0, str(pathlib.Path(__file__).parent))
......@@ -15,12 +17,19 @@ class Environment(Schedulable):
"""
def __init__(self) -> None:
self.set_seed()
super().__init__()
self.scheduler: Scheduler = None
self.on_initialization()
# tell scheduler that init is done
self.give_token_syncro()
def set_seed(self):
"""
This method set the seed for all random in the system, it should be override to set a custom seed
"""
seed()
def add_scheduler(self, scheduler: Scheduler) -> None:
"""
set scheduler pointer to scheduler
......
......@@ -7,9 +7,15 @@ class ToOverrideWarning:
"""
Warning raised a method that should be override is called
"""
__enable_warning = True
def __init__(
self,
name: str
) -> None:
print("[WARNING] : Method " + name + " was called without being override.")
if ToOverrideWarning.__enable_warning:
print("[WARNING] : Method " + name + " was called without being override.")
@classmethod
def enable_warning(cls, condition: bool) -> None:
cls.__enable_warning = condition
......@@ -16,7 +16,7 @@ class SimpleAmas(Amas):
def on_initial_agents_creation(self) -> None:
for i in range(10):
self.add_agent(Agent(self))
self.add_agent(SimpleAgent(self))
class SimpleEnv(Environment):
......@@ -35,4 +35,8 @@ amas.start()
"""
There are no visible memory leak in pyAmakCore
"""
"""
TODO :
We could test add agent / get most critical neighbor ... also
"""
\ No newline at end of file
from random import randint, seed
from time import sleep
from pyAmakCore.classes.amas import Amas
from pyAmakCore.classes.environment import Environment
from pyAmakCore.classes.agent import Agent
from pyAmakCore.exception.override import ToOverrideWarning
class SimpleAgent(Agent):
"""
test
"""
def on_act(self) -> None:
print(randint(0, 100))
class SimpleAmas(Amas):
"""
test
"""
def on_initialization(self) -> None:
ToOverrideWarning.enable_warning(False)
def on_initial_agents_creation(self) -> None:
for i in range(10):
self.add_agent(SimpleAgent(self))
def on_cycle_begin(self) -> None:
pass
# print(randint(0, 100))
def on_cycle_end(self) -> None:
if self.get_cycle() == 30:
sleep(300)
class SimpleEnv(Environment):
"""
test
"""
def set_seed(self):
seed(30)
env = SimpleEnv()
amas = SimpleAmas(env)
amas.put_token()
amas.start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment