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

Update to v0.1.0

parent 3caef389
No related branches found
No related tags found
No related merge requests found
""" """
class antHillExample class antHillExample
""" """
from pyAmakCore.classes.tools.amasIHM import AmasIHM from pyAmakCore.classes.amas import Amas
from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy
from antExample import AntExampleV1 from antExample import AntExampleV1
from antExample2 import AntExampleV2 from antExample2 import AntExampleV2
...@@ -11,26 +9,19 @@ from antExample3 import CommunicatingAnt ...@@ -11,26 +9,19 @@ from antExample3 import CommunicatingAnt
from antExample4 import TestAnt from antExample4 import TestAnt
class AntHillExample(Amas):
class AntHillExample(AmasIHM): def __init__(self, env, nbr_ants, execution_policy):
def __init__(self, env, nbr_ants):
self.nbr_ants = nbr_ants self.nbr_ants = nbr_ants
super().__init__(env) super().__init__(env, execution_policy)
def on_initialization(self) -> None: def on_initialization(self) -> None:
# self.set_execution_policy(ExecutionPolicy.ONE_PHASE) self.set_do_log(True)
self.set_execution_policy(ExecutionPolicy.TWO_PHASES)
# self.set_do_log(True)
self.add_ignore_attribute("_CommunicatingAgent__mailbox") 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: def on_initial_agents_creation(self) -> None:
for i in range(self.nbr_ants): 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(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(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(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)) # self.add_agent(TestAnt(self, self.get_environment().xmax / 2, self.get_environment().ymax / 2))
...@@ -3,6 +3,9 @@ Class antsLaunchExample ...@@ -3,6 +3,9 @@ Class antsLaunchExample
""" """
from random import seed from random import seed
from pyAmakCore.classes.tools.schedulerIHM import SchedulerIHM
from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy
from pyAmakIHM.classes.fenetre import Fenetre from pyAmakIHM.classes.fenetre import Fenetre
from controleurAntsExample import ControleurAntsExample from controleurAntsExample import ControleurAntsExample
from worldExample import WorldExample from worldExample import WorldExample
...@@ -18,8 +21,12 @@ ToOverrideWarning.enable_warning(False) ...@@ -18,8 +21,12 @@ ToOverrideWarning.enable_warning(False)
fenetre = Fenetre("Prototype Ants") fenetre = Fenetre("Prototype Ants")
env = WorldExample(0, fenetre.get_canvas_width(), 0, fenetre.get_canvas_height(), 5, 7) env = WorldExample(0, fenetre.get_canvas_width(), 0, fenetre.get_canvas_height(), 5, 7)
amas = AntHillExample(env, nbr_ants) # amas = AntHillExample(env, nbr_ants, ExecutionPolicy.ONE_PHASE)
controleur = ControleurAntsExample(fenetre, amas, nbr_ants) amas = AntHillExample(env, nbr_ants, ExecutionPolicy.TWO_PHASES)
scheduler = SchedulerIHM(amas)
controleur = ControleurAntsExample(fenetre, scheduler, nbr_ants)
def main(): def main():
......
...@@ -17,8 +17,8 @@ class ControleurAntsExample(Controleur): ...@@ -17,8 +17,8 @@ class ControleurAntsExample(Controleur):
for i in range(self.__numberAnts): for i in range(self.__numberAnts):
self.__ants.append(self.draw_image(widthCanvas / 2, heightCanvas / 2, 'images/blackAnt.png')) self.__ants.append(self.draw_image(widthCanvas / 2, heightCanvas / 2, 'images/blackAnt.png'))
def updateWindow(self, env, amas): def updateWindow(self):
ants = amas.get_Agents_Sorted() ants = self.get_amas().get_agents()
for i in range(len(ants)): for i in range(len(ants)):
x = ants[i].get_dx() x = ants[i].get_dx()
......
...@@ -5,8 +5,8 @@ from random import randint ...@@ -5,8 +5,8 @@ from random import randint
class ControleurPhilosophersExample(Controleur): class ControleurPhilosophersExample(Controleur):
def __init__(self, fenetre, amas): def __init__(self, fenetre, scheduler):
super().__init__(fenetre, amas) super().__init__(fenetre, scheduler)
self.__philosophers = [] self.__philosophers = []
self.__left = [] self.__left = []
self.__right = [] self.__right = []
...@@ -61,10 +61,10 @@ class ControleurPhilosophersExample(Controleur): ...@@ -61,10 +61,10 @@ class ControleurPhilosophersExample(Controleur):
self.addColumn(self.__chart[0],nom) self.addColumn(self.__chart[0],nom)
def updateWindow(self, env, amas): def updateWindow(self):
agents = amas.get_Agents_Sorted() agents = self.get_amas().get_agents()
self.addPoint(self.__chart[1],0,amas.get_cycle(),self.__hoursThinkingMr5) self.addPoint(self.__chart[1],0,self.get_amas().get_cycle(),self.__hoursThinkingMr5)
self.addPoint(self.__chart[2],0,amas.get_cycle(),self.__hoursThinkingMr5) self.addPoint(self.__chart[2],0,self.get_amas().get_cycle(),self.__hoursThinkingMr5)
for i in range(10): for i in range(10):
state = agents[i].get_state() state = agents[i].get_state()
......
from pyAmakCore.classes.tools.amasIHM import AmasIHM
from philosophersExample import PhilosophersExample from philosophersExample import PhilosophersExample
from pyAmakCore.classes.amas import Amas
from tableExample import TableExample from tableExample import TableExample
class PhilosophersAmasExamples(AmasIHM): class PhilosophersAmasExamples(Amas):
def __init__(self):
super().__init__(TableExample())
def __init__(self, execution_policy):
super().__init__(TableExample(), execution_policy)
def on_initial_agents_creation(self): def on_initial_agents_creation(self):
ps = [] ps = []
...@@ -25,4 +23,4 @@ class PhilosophersAmasExamples(AmasIHM): ...@@ -25,4 +23,4 @@ class PhilosophersAmasExamples(AmasIHM):
ps[0].add_neighbour(ps[len(ps) - 1]) ps[0].add_neighbour(ps[len(ps) - 1])
ps[len(ps) - 1].add_neighbour(ps[0]) ps[len(ps) - 1].add_neighbour(ps[0])
self.add_agents(ps) self.add_agents(ps)
\ No newline at end of file
...@@ -26,7 +26,7 @@ class PhilosophersExample(Agent): ...@@ -26,7 +26,7 @@ class PhilosophersExample(Agent):
else: else:
if self.__state == State.HUNGRY: if self.__state == State.HUNGRY:
self.__hungerDuration += 1 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.__left.try_take(self)
self.__right.try_take(self) self.__right.try_take(self)
if self.__left.owned(self) and self.__right.owned(self): if self.__left.owned(self) and self.__right.owned(self):
......
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 pyAmakIHM.classes.fenetre import Fenetre
from controleurPhilosophersExample import ControleurPhilosophersExample from controleurPhilosophersExample import ControleurPhilosophersExample
from philosophersAmasExample import PhilosophersAmasExamples from philosophersAmasExample import PhilosophersAmasExamples
fenetre = Fenetre("Prototype Philosophers") 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(): def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment