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

Some method are now private

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