diff --git a/doc/report/figures/fsm/mgm2_supervisor.gv b/doc/report/figures/fsm/mgm2_supervisor.gv index 001bf11cd6f5609d7d5b34af06bad13a3bc4065e..46ab71bc7cf93e5be5af62ff1e088c68210f94e0 100644 --- a/doc/report/figures/fsm/mgm2_supervisor.gv +++ b/doc/report/figures/fsm/mgm2_supervisor.gv @@ -7,18 +7,18 @@ digraph finite_state_machine { node [shape = circle]; /*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 "]; - WaitingForAgentValues -> WaitingForAgentValues [label = " agent : InformValue(val) && (#currentContext < #agents - 1) => + RunningSupervisorState -> RunningSupervisorState [label = " agent : InformValue(val) && (#currentContext < #agents - 1) => 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) self.shouldAlgoKeepOn() match { case true => broadcast ! ContinueAlgo @@ -29,16 +29,16 @@ digraph finite_state_machine { "]; - DecidingToContinueOrStop -> WaitingForAgentValues [label = " self ! ContinueAlgo => + Deciding -> RunningSupervisorState [label = " self ! ContinueAlgo => currentContext.reset(); unstashall "]; - DecidingToContinueOrStop -> DecidingToContinueOrStop [label = " sender : InformValue(val) => + Deciding -> Deciding [label = " sender : InformValue(val) => stash "]; - DecidingToContinueOrStop -> Finish [label = " self ! StopAlgo => + Deciding -> Finish [label = " self ! StopAlgo => return currentContext "]; } \ No newline at end of file diff --git a/doc/report/figures/fsm/mgm2_supervisor.png b/doc/report/figures/fsm/mgm2_supervisor.png index 76a2276dbca5374bb12ebfb76162f63b232291a7..e1c5cb2457c1e30ded11ef31e8d8c7b1f0ac9353 100644 Binary files a/doc/report/figures/fsm/mgm2_supervisor.png and b/doc/report/figures/fsm/mgm2_supervisor.png differ diff --git a/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala b/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala index ccfc53f9a084f0216f5decbbcfcb491efa6dbbae..ead4194ae85c2504dd91c6f0f766df48e36d0871 100644 --- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala +++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala @@ -407,21 +407,21 @@ class AgentBehaviour(variable: Variable, val newVal: Value = mind.updateVal(variable, move) val updatedMind: MGM2Mind = mind.updateContext(variable, variable, newVal) 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 // When it should act because it has the highest delta in the neighbourhood case Event(Act(true, None), mind) => 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})") - //supervisor ! InformValue(updatedMind.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) goto(Continue) using mind // When it should not act because it does not have the highest delta in the neighbourhood case Event(Act(false, _), mind) => 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})") - //supervisor ! InformValue(mind.context.getValue(variable).get) + supervisor ! InformValue(mind.context.getValue(variable).get) goto(Continue) using mind } diff --git a/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala b/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala index 63d7907320781ebbb83966674d52d1311158d651..17f7cc07ad1e21fd1bcbcbfb39cd251743f92393 100644 --- a/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala +++ b/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala @@ -102,6 +102,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta * Handles the message in the running state */ when(RunningSupervisorState) { + // When an agent wants to start case Event(KickStartMe, status) => sender ! ContinueAlgo @@ -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 */ diff --git a/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorState.scala b/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorState.scala index a9b463f978d2785b7220e18c95a8e9c0f6bd2091..2cb0fd0e9d6cb422e5f0925991d55949331f4b41 100644 --- a/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorState.scala +++ b/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorState.scala @@ -10,4 +10,5 @@ trait SupervisorState extends State case object InitialSupervisorState extends SupervisorState case object RunningSupervisorState extends SupervisorState case object FinalSupervisorState extends SupervisorState +case object Deciding extends SupervisorState