Skip to content
Snippets Groups Projects
Commit dd6b4536 authored by Jean-Christophe Routier's avatar Jean-Christophe Routier
Browse files

isTerminated becomes a counter condition

parent 845a2216
Branches master
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ abstract class VariableAgent(val variable: Variable, ...@@ -23,7 +23,7 @@ abstract class VariableAgent(val variable: Variable,
val constraints: Set[Constraint]) extends Actor { val constraints: Set[Constraint]) extends Actor {
var trace: Boolean = false var trace: Boolean = false
var debug: Boolean = false var debug: Boolean = false
var debugState: Boolean = true var debugState: Boolean = false
var supervisor: ActorRef = context.parent var supervisor: ActorRef = context.parent
var directory: Directory = new Directory() var directory: Directory = new Directory()
......
...@@ -414,7 +414,7 @@ class AgentBehaviour(variable: Variable, ...@@ -414,7 +414,7 @@ class AgentBehaviour(variable: Variable,
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(mind.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
......
...@@ -15,8 +15,8 @@ import akka.actor.{Actor, ActorRef, FSM, Props, Stash, PoisonPill} ...@@ -15,8 +15,8 @@ import akka.actor.{Actor, ActorRef, FSM, Props, Stash, PoisonPill}
class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Stash class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Stash
with FSM[SupervisorState, SupervisorStatus] { with FSM[SupervisorState, SupervisorStatus] {
var debug = true var debug = false
var debugState = true var debugState = false
var trace = false var trace = false
var solver: ActorRef = context.parent // Reference to the distributed solver var solver: ActorRef = context.parent // Reference to the distributed solver
...@@ -162,7 +162,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -162,7 +162,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
//when it receives its own decison that it should continue //when it receives its own decison that it should continue
case Event(ContinueAlgo, status) => { case Event(ContinueAlgo, status) => {
val newStatus: SupervisorStatus = status.resetContext() val newStatus: SupervisorStatus = status.resetContext()
unstashall unstashAll
goto(RunningSupervisorState) using newStatus goto(RunningSupervisorState) using newStatus
} }
...@@ -246,3 +246,12 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -246,3 +246,12 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
initialize() initialize()
} }
object Supervisor {
var counter = 0
val NB_ROUNDS = 2
def incrementCounter() : Int = {
counter = counter + 1
counter
}
}
...@@ -40,16 +40,18 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(), ...@@ -40,16 +40,18 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(),
* Returns true if the algorithm ends * Returns true if the algorithm ends
* @todo modify it * @todo modify it
*/ */
def isTerminated : Boolean = ! isFirstRound def isTerminated : Boolean = Supervisor.incrementCounter() == Supervisor.NB_ROUNDS
/*Returns the updated supervisor's status when resetting the context*/ /*Returns the updated supervisor's status when resetting the context*/
def resetContext(): SupervisorStatus { def resetContext(): SupervisorStatus = {
new SupervisorStatus(readyVariables, new SupervisorStatus(readyVariables,
inactiveVariables = Set(), inactiveVariables = Set(),
killedVariables, killedVariables,
assignment new Context(), assignment = new Context(),
metric, metric,
isFirstRound isFirstRound
) )
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment