Skip to content
Snippets Groups Projects
Commit d7a336e1 authored by shined day's avatar shined day
Browse files

Merge branch '22-fix-2-phases-execution_policy' into 'master'

Fixed

Closes #22

See merge request be-pyamak/pyamak-noyau!9
parents c0202ace 0b97f635
Branches
Tags
No related merge requests found
No preview for this file type
...@@ -163,25 +163,32 @@ class Agent: ...@@ -163,25 +163,32 @@ class Agent:
""" """
self.on_perceive() self.on_perceive()
self.compute_criticality() self.compute_criticality()
self.__phase = Phase.PERCEPTION_DONE self.__next_phase()
def __phase2(self) -> None: def __phase2(self) -> None:
""" """
this is the second phase of a cycle this is the second phase of a cycle
""" """
self.__phase = Phase.DECISION_AND_ACTION
self.on_decide() self.on_decide()
self.on_act() self.on_act()
self.compute_criticality() self.compute_criticality()
self.__phase = Phase.DECISION_AND_ACTION_DONE self.__next_phase()
def __next_phase(self):
next_phase = {
Phase.INITIALIZING: Phase.PERCEPTION,
Phase.PERCEPTION: Phase.PERCEPTION_DONE,
Phase.PERCEPTION_DONE: Phase.DECISION_AND_ACTION,
Phase.DECISION_AND_ACTION: Phase.DECISION_AND_ACTION_DONE,
Phase.DECISION_AND_ACTION_DONE: Phase.PERCEPTION
}
self.__phase = next_phase.get(self.__phase)
def run(self) -> None: def run(self) -> None:
""" """
Full cycle of an agent Full cycle of an agent
""" """
# TODO : next phase DECISION_AND_ACTION_DONE -> PERCEPTION self.__next_phase()
if self.__phase == Phase.INITIALIZING:
self.__phase = Phase.PERCEPTION
execution_policy = self.__amas.get_execution_policy() execution_policy = self.__amas.get_execution_policy()
...@@ -199,6 +206,7 @@ class Agent: ...@@ -199,6 +206,7 @@ class Agent:
if execution_policy == ExecutionPolicy.ONE_PHASE: if execution_policy == ExecutionPolicy.ONE_PHASE:
self.on_cycle_begin() self.on_cycle_begin()
self.__phase1() self.__phase1()
self.__next_phase()
self.__phase2() self.__phase2()
self.on_cycle_end() self.on_cycle_end()
......
...@@ -85,6 +85,12 @@ class Amas(Schedulable): ...@@ -85,6 +85,12 @@ class Amas(Schedulable):
""" """
return self.__execution_policy return self.__execution_policy
def set_execution_policy(self, execution_policy: ExecutionPolicy) -> None:
"""
set system execution_policy
"""
self.__execution_policy = execution_policy
def get_cycle(self) -> int: def get_cycle(self) -> int:
""" """
return nbr of cycle return nbr of cycle
......
"""
test that run of Agent work as intended
"""
from unittest import TestCase, main
from pyAmakCore.classes.agent import Agent
from pyAmakCore.classes.amas import Amas
from pyAmakCore.classes.environment import Environment
from pyAmakCore.enumeration.executionPolicy import ExecutionPolicy
class TestAgentRun(TestCase):
"""
Test class for Agent run
"""
def test_run(self):
Agent.reset_agent()
environment = Environment()
amas = Amas(environment)
amas.set_execution_policy(ExecutionPolicy.ONE_PHASE)
agent = Agent(amas)
agent.run()
self.assertEqual()
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment