Skip to content
Snippets Groups Projects
Commit e4d64d02 authored by Alex's avatar Alex
Browse files

beginning of supervisor

parent 4460acec
No related branches found
No related tags found
No related merge requests found
...@@ -7,18 +7,18 @@ digraph finite_state_machine { ...@@ -7,18 +7,18 @@ digraph finite_state_machine {
node [shape = circle]; node [shape = circle];
/*THE SUPERVISOR*/ /*THE SUPERVISOR*/
start -> WaitingForAgentValues [label = " broadcast(agents) ! Trigger Start -> RunningSupervisorState [label = " broadcast(agents) ! Trigger
"]; "];
WaitingForAgentValues -> WaitingForAgentValues [label = " agent : KickStartMe => RunningSupervisorState -> RunningSupervisorState [label = " agent : KickStartMe =>
agent ! ContinueAlgo agent ! ContinueAlgo
"]; "];
WaitingForAgentValues -> WaitingForAgentValues [label = " agent : InformValue(val) && (#currentContext < #agents - 1) => RunningSupervisorState -> RunningSupervisorState [label = " agent : InformValue(val) && (#currentContext < #agents - 1) =>
currentContext.put(agent, val) currentContext.put(agent, val)
"]; "];
WaitingForAgentValues -> DecidingToContinueOrStop [label = " agent : InformValue(val) && (#currentContext == #agents - 1) => RunningSupervisorState -> Deciding [label = " agent : InformValue(val) && (#currentContext == #agents - 1) =>
currentContext.put(agent, val) currentContext.put(agent, val)
self.shouldAlgoKeepOn() match { self.shouldAlgoKeepOn() match {
case true => broadcast ! ContinueAlgo case true => broadcast ! ContinueAlgo
...@@ -29,16 +29,16 @@ digraph finite_state_machine { ...@@ -29,16 +29,16 @@ digraph finite_state_machine {
"]; "];
DecidingToContinueOrStop -> WaitingForAgentValues [label = " self ! ContinueAlgo => Deciding -> RunningSupervisorState [label = " self ! ContinueAlgo =>
currentContext.reset(); currentContext.reset();
unstashall unstashall
"]; "];
DecidingToContinueOrStop -> DecidingToContinueOrStop [label = " sender : InformValue(val) => Deciding -> Deciding [label = " sender : InformValue(val) =>
stash stash
"]; "];
DecidingToContinueOrStop -> Finish [label = " self ! StopAlgo => Deciding -> Finish [label = " self ! StopAlgo =>
return currentContext return currentContext
"]; "];
} }
\ No newline at end of file
doc/report/figures/fsm/mgm2_supervisor.png

121 KiB | W: | H:

doc/report/figures/fsm/mgm2_supervisor.png

108 KiB | W: | H:

doc/report/figures/fsm/mgm2_supervisor.png
doc/report/figures/fsm/mgm2_supervisor.png
doc/report/figures/fsm/mgm2_supervisor.png
doc/report/figures/fsm/mgm2_supervisor.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -407,21 +407,21 @@ class AgentBehaviour(variable: Variable, ...@@ -407,21 +407,21 @@ class AgentBehaviour(variable: Variable,
val newVal: Value = mind.updateVal(variable, move) val newVal: Value = mind.updateVal(variable, move)
val updatedMind: MGM2Mind = mind.updateContext(variable, variable, newVal) val updatedMind: MGM2Mind = mind.updateContext(variable, variable, newVal)
if (trace) println(s"$variable -> Supervisor : I changed = InformValue(${updatedMind.context.getValue(variable).get})") if (trace) println(s"$variable -> Supervisor : I changed = InformValue(${updatedMind.context.getValue(variable).get})")
//supervisor ! InformValue(updatedMind.context.getValue(variable).get) supervisor ! InformValue(updatedMind.context.getValue(variable).get)
goto(Continue) using updatedMind goto(Continue) using updatedMind
// When it should act because it has the highest delta in the neighbourhood // When it should act because it has the highest delta in the neighbourhood
case Event(Act(true, None), mind) => case Event(Act(true, None), mind) =>
if (debug) println(s"$variable in $stateName has received Act(true) but has no move") if (debug) println(s"$variable in $stateName has received Act(true) but has no move")
if (trace) println(s"$variable -> $supervisor : I kept my previous value = InformValue(${mind.context.getValue(variable).get})") if (trace) println(s"$variable -> Supervisor : I kept my previous value = InformValue(${mind.context.getValue(variable).get})")
//supervisor ! InformValue(updatedMind.context.getValue(variable).get) supervisor ! InformValue(updatedMind.context.getValue(variable).get)
goto(Continue) using mind goto(Continue) using mind
// When it should not act because it does not have the highest delta in the neighbourhood // When it should not act because it does not have the highest delta in the neighbourhood
case Event(Act(false, _), mind) => case Event(Act(false, _), mind) =>
if (debug) println(s"$variable in $stateName has received Act(false)") if (debug) println(s"$variable in $stateName has received Act(false)")
if (trace) println(s"$variable -> Supervisor : I didn't change = InformValue(${mind.context.getValue(variable).get})") if (trace) println(s"$variable -> Supervisor : I didn't change = InformValue(${mind.context.getValue(variable).get})")
//supervisor ! InformValue(mind.context.getValue(variable).get) supervisor ! InformValue(mind.context.getValue(variable).get)
goto(Continue) using mind goto(Continue) using mind
} }
......
...@@ -102,6 +102,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -102,6 +102,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
* Handles the message in the running state * Handles the message in the running state
*/ */
when(RunningSupervisorState) { when(RunningSupervisorState) {
// When an agent wants to start // When an agent wants to start
case Event(KickStartMe, status) => case Event(KickStartMe, status) =>
sender ! ContinueAlgo sender ! ContinueAlgo
...@@ -147,6 +148,32 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -147,6 +148,32 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
} }
} }
/**
* Handles the messages when the supervisor is branching either to do anothe round or to stop.
*/
when(Deciding) {
//when an agent informs the supervisor of its current value
case Event(InformValue(v), status) => {
stash
stay using status
}
//when it receives its own decison that it should continue
case Event(ContinueAlgo, status) => {
//TODO reset the context it has
unstashall
goto(RunningSupervisorState) using status
}
case Event(StopAlgo, status) => {
//TODO ???
}
}
/** /**
* Handles the message in the final state * Handles the message in the final state
*/ */
......
...@@ -10,4 +10,5 @@ trait SupervisorState extends State ...@@ -10,4 +10,5 @@ trait SupervisorState extends State
case object InitialSupervisorState extends SupervisorState case object InitialSupervisorState extends SupervisorState
case object RunningSupervisorState extends SupervisorState case object RunningSupervisorState extends SupervisorState
case object FinalSupervisorState extends SupervisorState case object FinalSupervisorState extends SupervisorState
case object Deciding extends SupervisorState
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment