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
"""
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))
......@@ -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():
......
......@@ -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()
......
......@@ -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()
......
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)
......@@ -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):
......
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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment