From d854be2f16f50a0e8c8afb12480429c9c764a6c6 Mon Sep 17 00:00:00 2001 From: shinedday <shinedday@gmail.com> Date: Tue, 18 May 2021 18:04:44 +0200 Subject: [PATCH] Update to v0.1.0 --- ant_example/antHillExample.py | 23 ++++++------------- ant_example/antsLaunchExample.py | 11 +++++++-- ant_example/controleurAntsExample.py | 4 ++-- .../controleurPhilosophersExample.py | 12 +++++----- .../philosophersAmasExample.py | 12 ++++------ philosopher_example/philosophersExample.py | 2 +- .../philosophersLaunchExample.py | 13 +++++++++-- 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/ant_example/antHillExample.py b/ant_example/antHillExample.py index 9ed3222..0d56376 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 fae6319..dd044a9 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 6416d72..4bb928b 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 75b8c0f..c1c39ba 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 e69270d..6f5ed2a 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 6a4bb86..a60b73f 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 1632662..b25decc 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(): -- GitLab