From e80bd43ec60fb94a2eb9e60af2beb7bcebc070dd Mon Sep 17 00:00:00 2001 From: Alex <alexandravigneron1@gmail.com> Date: Thu, 2 Jul 2020 17:43:25 +0200 Subject: [PATCH] tried to fiw supervisors' counting inform val, doesnt work --- .../solver/decentralized/mgm2/MGM2Mind.scala | 2 +- .../decentralized/supervisor/Supervisor.scala | 20 ++++++++++++++----- .../supervisor/SupervisorStatus.scala | 19 +++++++++++++++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala b/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala index b7dafea..28c62e7 100644 --- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala +++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala @@ -78,7 +78,7 @@ class MGM2Mind(val context : Context = new Context(), variable.domain.foreach { value => val potentialContext: Context = context.fix(variable, value) val potentialCost = potentialContext.cost(constraints) - val delta = currentCost - potentialCost + val delta = potentialCost - currentCost if (delta ~> bestDelta) { val move = new UnilateralMove(potentialContext, delta) bestDelta = delta 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 51e59e7..6f77a87 100644 --- a/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala +++ b/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala @@ -85,6 +85,12 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta new SupervisorStatus(readyVariables = status.readyVariables + variable, isFirstRound = status.isFirstRound) + //when it receives an InformValue from an early agent + case Event(InformValue(_), status) => { + stash + stay using status + } + //When all the agents become ready case Event(Ready, status) if status.nbReady == pb.size - 1 => val variable = directory.variableOf(sender) @@ -93,6 +99,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta if (trace) println(s"Supervisor -> $anyVariable : Trigger") directory.addressOf(anyVariable) ! Trigger } + unstashAll goto(RunningSupervisorState) using new SupervisorStatus(readyVariables = status.readyVariables + variable, isFirstRound = status.isFirstRound) @@ -109,22 +116,25 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta stay using status // When an agent becomes inactive - case Event(InformValue(value), status) if status.assignment.valuation.size < pb.size - 1 => + case Event(InformValue(value), status) if status.informValCounter < pb.size - 1 => val variable: Variable = directory.variableOf(sender) if (debug) println(s"Supervisor ($stateName): $variable is inactive") - stay using new SupervisorStatus(readyVariables = status.readyVariables, + var updatedStatus = new SupervisorStatus(readyVariables = status.readyVariables, inactiveVariables = status.inactiveVariables + variable, assignment = status.assignment.fix(variable,value), isFirstRound = status.isFirstRound) + updatedStatus.incrementInformValCounter() + stay using updatedStatus // When all the agent become inactive - case Event(InformValue(value), status) if status.assignment.valuation.size == pb.size - 1 => + case Event(InformValue(value), status) if status.informValCounter == pb.size - 1 => val variable: Variable = directory.variableOf(sender) if (debug) println(s"Supervisor ($stateName): $variable is finally inactive") - val updatedStatus = new SupervisorStatus(readyVariables = status.readyVariables, + var updatedStatus = new SupervisorStatus(readyVariables = status.readyVariables, inactiveVariables = status.inactiveVariables + variable, assignment = status.assignment.fix(variable,value), isFirstRound = false) + updatedStatus.incrementInformValCounter() if (! updatedStatus.isTerminated){// If the solving must be restart for another round pb.variables.foreach { anyVariable: Variable => @@ -249,7 +259,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta object Supervisor { var counter = 0 - val NB_ROUNDS = 5 + val NB_ROUNDS = 10 def incrementCounter() : Int = { counter = counter + 1 diff --git a/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorStatus.scala b/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorStatus.scala index bc71821..160acec 100644 --- a/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorStatus.scala +++ b/src/main/scala/org/scadcop/solver/decentralized/supervisor/SupervisorStatus.scala @@ -18,7 +18,8 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(), val killedVariables: Set[Variable] = Set(), val assignment: Context = new Context(), val metric: Metric= collection.mutable.Map[String,Double](), - val isFirstRound : Boolean = true + val isFirstRound : Boolean = true, + val informValCounter: Int = 0 ){ /** @@ -42,14 +43,26 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(), */ def isTerminated : Boolean = Supervisor.incrementCounter() > Supervisor.NB_ROUNDS + def incrementInformValCounter(): SupervisorStatus = { + new SupervisorStatus(readyVariables, + inactiveVariables, + killedVariables, + assignment, + metric, + isFirstRound, + informValCounter = informValCounter + 1 + ) + } + /*Returns the updated supervisor's status when resetting the context*/ def resetContext(): SupervisorStatus = { new SupervisorStatus(readyVariables, inactiveVariables = Set(), killedVariables, - assignment = new Context(), + assignment, metric, - isFirstRound + isFirstRound, + informValCounter = 0 ) } } -- GitLab