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

Add seed

parent 3256ff05
No related branches found
No related tags found
No related merge requests found
......@@ -16,14 +16,16 @@ class Environment(Schedulable):
Environment class
"""
def __init__(self) -> None:
self.set_seed()
def __init__(self, seed_int: int = None) -> None:
self.set_seed(seed_int)
super().__init__()
self.on_initialization()
def set_seed(self):
def set_seed(self, number):
"""
This method set the seed for all random in the system, it should be override to set a custom seed
"""
seed()
if number is None:
seed()
return
seed(number)
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