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

Some method are now private

parent e5347167
Branches
Tags
No related merge requests found
......@@ -104,6 +104,12 @@ class Agent:
"""
self.__neighbours = []
def get_criticality(self) -> float:
"""
return criticality
"""
return self.__criticality
def compute_criticality(self) -> float:
"""
compute_criticality
......@@ -168,7 +174,7 @@ class Agent:
this is the first phase of a cycle
"""
self.on_perceive()
self.compute_criticality()
self.__criticality = self.compute_criticality()
self._next_phase()
def _phase2(self) -> None:
......@@ -177,7 +183,7 @@ class Agent:
"""
self.on_decide()
self.on_act()
self.compute_criticality()
self.__criticality = self.compute_criticality()
self._next_phase()
def _next_phase(self):
......
......@@ -32,9 +32,9 @@ class Amas(Schedulable, Loggable):
self.__agents: List[Agent] = []
self.__nbrcycle: int = 0
self.scheduler: Scheduler = Scheduler()
self.scheduler.add_schedulable(self)
self.__environment.add_scheduler(self.scheduler)
self.__scheduler: Scheduler = Scheduler()
self.__scheduler.add_schedulable(self)
self.__environment.add_scheduler(self.__scheduler)
self.__execution_policy: ExecutionPolicy = ExecutionPolicy.ONE_PHASE
......@@ -112,7 +112,7 @@ class Amas(Schedulable, Loggable):
Unlock Scheduler and wait for his response
"""
self.give_token_syncro()
self.scheduler.take_amas_token()
self.__scheduler.take_amas_token()
def cycle(self) -> None:
"""
......@@ -153,29 +153,29 @@ class Amas(Schedulable, Loggable):
"""
Tell scheduler to start
"""
self.scheduler.give_semaphore_start_stop()
self.__scheduler.give_semaphore_start_stop()
def take_token(self) -> None:
"""
Tell scheduler to stop
"""
self.scheduler.take_semaphore_start_stop()
self.__scheduler.take_semaphore_start_stop()
def exit_program(self) -> None:
"""
exit the program at the end of the cycle
"""
self.put_token()
self.scheduler.exit_bool = True
self.__scheduler.exit_bool = True
def set_sleep(self, sleep_time) -> None:
"""
set sleep between 2 cycles
"""
self.scheduler.sleep_time = sleep_time
self.__scheduler.sleep_time = sleep_time
def start(self) -> None:
"""
launch the system
"""
self.scheduler.run()
self.__scheduler.run()
......@@ -16,7 +16,7 @@ class Environment(Schedulable):
def __init__(self) -> None:
super().__init__()
self.scheduler: Scheduler = None
self.__scheduler: Scheduler = None
self.on_initialization()
# tell scheduler that init is done
self.give_token_syncro()
......@@ -26,15 +26,15 @@ class Environment(Schedulable):
set scheduler pointer to scheduler
add add self to schedulables of scheduler
"""
self.scheduler = scheduler
self.scheduler.add_schedulable(self)
self.__scheduler = scheduler
self.__scheduler.add_schedulable(self)
def synchronization(self) -> None:
"""
Unlock Scheduler and wait for his response
"""
self.give_token_syncro()
self.scheduler.take_environment_token()
self.__scheduler.take_environment_token()
def cycle(self) -> None:
"""
......
......@@ -38,9 +38,6 @@ class TestAmasAgents(TestCase):
agent1 = Agent(amas)
agent2 = Agent(amas)
agent3 = Agent(amas)
agent4 = Agent(amas)
agent5 = Agent(amas)
# add 1 agent
amas.add_agent(agent1)
self.assertEqual(amas.get_agents(), [agent1])
......
......@@ -12,7 +12,7 @@ from pyAmakCore.classes.environment import Environment
class SimplerAmas(Amas):
def synchronization(self):
self.scheduler.give_amas_token()
self._Amas__scheduler.give_amas_token()
super().synchronization()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment