diff --git a/ant_example/antHillExample.py b/ant_example/antHillExample.py index 9ed322253c804c2419b08c6f23f7a8475b96c018..0d56376abf2193e0540357a95fc2dc37c621e233 100644 --- a/ant_example/antHillExample.py +++ b/ant_example/antHillExample.py @@ -1,9 +1,7 @@ """ class antHillExample """ -from pyAmakCore.classes.tools.amasIHM import AmasIHM -from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy - +from pyAmakCore.classes.amas import Amas from antExample import AntExampleV1 from antExample2 import AntExampleV2 @@ -11,26 +9,19 @@ from antExample3 import CommunicatingAnt from antExample4 import TestAnt +class AntHillExample(Amas): -class AntHillExample(AmasIHM): - - def __init__(self, env, nbr_ants): + def __init__(self, env, nbr_ants, execution_policy): self.nbr_ants = nbr_ants - super().__init__(env) + super().__init__(env, execution_policy) def on_initialization(self) -> None: - # self.set_execution_policy(ExecutionPolicy.ONE_PHASE) - self.set_execution_policy(ExecutionPolicy.TWO_PHASES) - - # self.set_do_log(True) + self.set_do_log(True) self.add_ignore_attribute("_CommunicatingAgent__mailbox") - self.add_ignore_attribute("_Agent__criticality") - self.add_ignore_attribute("_Agent__phase") - def on_initial_agents_creation(self) -> None: for i in range(self.nbr_ants): # self.add_agent(AntExampleV1(self, self.get_environment().xmax/2, self.get_environment().ymax/2)) - self.add_agent(AntExampleV2(self, self.get_environment().xmax/2, self.get_environment().ymax/2)) - # self.add_agent(CommunicatingAnt(self, self.get_environment().xmax / 2, self.get_environment().ymax / 2)) + # self.add_agent(AntExampleV2(self, self.get_environment().xmax/2, self.get_environment().ymax/2)) + self.add_agent(CommunicatingAnt(self, self.get_environment().xmax / 2, self.get_environment().ymax / 2)) # self.add_agent(TestAnt(self, self.get_environment().xmax / 2, self.get_environment().ymax / 2)) diff --git a/ant_example/antsLaunchExample.py b/ant_example/antsLaunchExample.py index fae6319e25910abc8e91be8e64e2b1ee408d51ef..dd044a98e09f9a90fa5206d4c025f868b3872f04 100644 --- a/ant_example/antsLaunchExample.py +++ b/ant_example/antsLaunchExample.py @@ -3,6 +3,9 @@ Class antsLaunchExample """ from random import seed +from pyAmakCore.classes.tools.schedulerIHM import SchedulerIHM +from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy + from pyAmakIHM.classes.fenetre import Fenetre from controleurAntsExample import ControleurAntsExample from worldExample import WorldExample @@ -18,8 +21,12 @@ ToOverrideWarning.enable_warning(False) fenetre = Fenetre("Prototype Ants") env = WorldExample(0, fenetre.get_canvas_width(), 0, fenetre.get_canvas_height(), 5, 7) -amas = AntHillExample(env, nbr_ants) -controleur = ControleurAntsExample(fenetre, amas, nbr_ants) +# amas = AntHillExample(env, nbr_ants, ExecutionPolicy.ONE_PHASE) +amas = AntHillExample(env, nbr_ants, ExecutionPolicy.TWO_PHASES) + +scheduler = SchedulerIHM(amas) + +controleur = ControleurAntsExample(fenetre, scheduler, nbr_ants) def main(): diff --git a/ant_example/controleurAntsExample.py b/ant_example/controleurAntsExample.py index 6416d720f8696d35f69beb0c7ace5e9242393e8c..4bb928b5b78c045777484d624ade529b90bc6689 100644 --- a/ant_example/controleurAntsExample.py +++ b/ant_example/controleurAntsExample.py @@ -17,8 +17,8 @@ class ControleurAntsExample(Controleur): for i in range(self.__numberAnts): self.__ants.append(self.draw_image(widthCanvas / 2, heightCanvas / 2, 'images/blackAnt.png')) - def updateWindow(self, env, amas): - ants = amas.get_Agents_Sorted() + def updateWindow(self): + ants = self.get_amas().get_agents() for i in range(len(ants)): x = ants[i].get_dx() diff --git a/philosopher_example/controleurPhilosophersExample.py b/philosopher_example/controleurPhilosophersExample.py index 75b8c0f590a371c6a1499b4a744b8b931402ad90..c1c39ba46b2e9e16130cd4ed1481dc55d6350c25 100644 --- a/philosopher_example/controleurPhilosophersExample.py +++ b/philosopher_example/controleurPhilosophersExample.py @@ -5,8 +5,8 @@ from random import randint class ControleurPhilosophersExample(Controleur): - def __init__(self, fenetre, amas): - super().__init__(fenetre, amas) + def __init__(self, fenetre, scheduler): + super().__init__(fenetre, scheduler) self.__philosophers = [] self.__left = [] self.__right = [] @@ -61,10 +61,10 @@ class ControleurPhilosophersExample(Controleur): self.addColumn(self.__chart[0],nom) - def updateWindow(self, env, amas): - agents = amas.get_Agents_Sorted() - self.addPoint(self.__chart[1],0,amas.get_cycle(),self.__hoursThinkingMr5) - self.addPoint(self.__chart[2],0,amas.get_cycle(),self.__hoursThinkingMr5) + def updateWindow(self): + agents = self.get_amas().get_agents() + self.addPoint(self.__chart[1],0,self.get_amas().get_cycle(),self.__hoursThinkingMr5) + self.addPoint(self.__chart[2],0,self.get_amas().get_cycle(),self.__hoursThinkingMr5) for i in range(10): state = agents[i].get_state() diff --git a/philosopher_example/philosophersAmasExample.py b/philosopher_example/philosophersAmasExample.py index e69270d43479e03fc469b6d378a913e4180ea044..6f5ed2abda29b9e4938e9d1f1ee8d9ff7412e832 100644 --- a/philosopher_example/philosophersAmasExample.py +++ b/philosopher_example/philosophersAmasExample.py @@ -1,14 +1,12 @@ -from pyAmakCore.classes.tools.amasIHM import AmasIHM - from philosophersExample import PhilosophersExample +from pyAmakCore.classes.amas import Amas from tableExample import TableExample -class PhilosophersAmasExamples(AmasIHM): - - def __init__(self): - super().__init__(TableExample()) +class PhilosophersAmasExamples(Amas): + def __init__(self, execution_policy): + super().__init__(TableExample(), execution_policy) def on_initial_agents_creation(self): ps = [] @@ -25,4 +23,4 @@ class PhilosophersAmasExamples(AmasIHM): ps[0].add_neighbour(ps[len(ps) - 1]) ps[len(ps) - 1].add_neighbour(ps[0]) - self.add_agents(ps) \ No newline at end of file + self.add_agents(ps) diff --git a/philosopher_example/philosophersExample.py b/philosopher_example/philosophersExample.py index 6a4bb86a6bd1f35f778e53f892044d1d63028830..a60b73ffd27e00d56059a605590b6e7d99d7fc24 100644 --- a/philosopher_example/philosophersExample.py +++ b/philosopher_example/philosophersExample.py @@ -26,7 +26,7 @@ class PhilosophersExample(Agent): else: if self.__state == State.HUNGRY: self.__hungerDuration += 1 - if self._get_most_critical_neighbor(True) == self: + if self.get_most_critical_neighbor(True) == self: self.__left.try_take(self) self.__right.try_take(self) if self.__left.owned(self) and self.__right.owned(self): diff --git a/philosopher_example/philosophersLaunchExample.py b/philosopher_example/philosophersLaunchExample.py index 163266233266b806bbcaa01e951e6834126edc27..b25decc674551d7461bdd60b420cfcdec4c6d097 100644 --- a/philosopher_example/philosophersLaunchExample.py +++ b/philosopher_example/philosophersLaunchExample.py @@ -1,11 +1,20 @@ +from pyAmakCore.classes.tools.schedulerIHM import SchedulerIHM + +from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy +from pyAmakCore.exception.override import ToOverrideWarning from pyAmakIHM.classes.fenetre import Fenetre from controleurPhilosophersExample import ControleurPhilosophersExample from philosophersAmasExample import PhilosophersAmasExamples fenetre = Fenetre("Prototype Philosophers") -amas = PhilosophersAmasExamples() -controleur = ControleurPhilosophersExample(fenetre, amas) +ToOverrideWarning.enable_warning(False) + +amas = PhilosophersAmasExamples(ExecutionPolicy.ONE_PHASE) + +scheduler = SchedulerIHM(amas) + +controleur = ControleurPhilosophersExample(fenetre, scheduler) def main():