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

tried to fiw supervisors' counting inform val, doesnt work

parent d87b24d5
No related branches found
No related tags found
No related merge requests found
...@@ -78,7 +78,7 @@ class MGM2Mind(val context : Context = new Context(), ...@@ -78,7 +78,7 @@ class MGM2Mind(val context : Context = new Context(),
variable.domain.foreach { value => variable.domain.foreach { value =>
val potentialContext: Context = context.fix(variable, value) val potentialContext: Context = context.fix(variable, value)
val potentialCost = potentialContext.cost(constraints) val potentialCost = potentialContext.cost(constraints)
val delta = currentCost - potentialCost val delta = potentialCost - currentCost
if (delta ~> bestDelta) { if (delta ~> bestDelta) {
val move = new UnilateralMove(potentialContext, delta) val move = new UnilateralMove(potentialContext, delta)
bestDelta = delta bestDelta = delta
......
...@@ -85,6 +85,12 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -85,6 +85,12 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
new SupervisorStatus(readyVariables = status.readyVariables + variable, new SupervisorStatus(readyVariables = status.readyVariables + variable,
isFirstRound = status.isFirstRound) 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 //When all the agents become ready
case Event(Ready, status) if status.nbReady == pb.size - 1 => case Event(Ready, status) if status.nbReady == pb.size - 1 =>
val variable = directory.variableOf(sender) val variable = directory.variableOf(sender)
...@@ -93,6 +99,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -93,6 +99,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
if (trace) println(s"Supervisor -> $anyVariable : Trigger") if (trace) println(s"Supervisor -> $anyVariable : Trigger")
directory.addressOf(anyVariable) ! Trigger directory.addressOf(anyVariable) ! Trigger
} }
unstashAll
goto(RunningSupervisorState) using goto(RunningSupervisorState) using
new SupervisorStatus(readyVariables = status.readyVariables + variable, new SupervisorStatus(readyVariables = status.readyVariables + variable,
isFirstRound = status.isFirstRound) isFirstRound = status.isFirstRound)
...@@ -109,22 +116,25 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -109,22 +116,25 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
stay using status stay using status
// When an agent becomes inactive // 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) val variable: Variable = directory.variableOf(sender)
if (debug) println(s"Supervisor ($stateName): $variable is inactive") 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, inactiveVariables = status.inactiveVariables + variable,
assignment = status.assignment.fix(variable,value), assignment = status.assignment.fix(variable,value),
isFirstRound = status.isFirstRound) isFirstRound = status.isFirstRound)
updatedStatus.incrementInformValCounter()
stay using updatedStatus
// When all the agent become inactive // 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) val variable: Variable = directory.variableOf(sender)
if (debug) println(s"Supervisor ($stateName): $variable is finally inactive") 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, inactiveVariables = status.inactiveVariables + variable,
assignment = status.assignment.fix(variable,value), assignment = status.assignment.fix(variable,value),
isFirstRound = false) isFirstRound = false)
updatedStatus.incrementInformValCounter()
if (! updatedStatus.isTerminated){// If the solving must be restart for another round if (! updatedStatus.isTerminated){// If the solving must be restart for another round
pb.variables.foreach { anyVariable: Variable => pb.variables.foreach { anyVariable: Variable =>
...@@ -249,7 +259,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta ...@@ -249,7 +259,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
object Supervisor { object Supervisor {
var counter = 0 var counter = 0
val NB_ROUNDS = 5 val NB_ROUNDS = 10
def incrementCounter() : Int = { def incrementCounter() : Int = {
counter = counter + 1 counter = counter + 1
......
...@@ -18,7 +18,8 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(), ...@@ -18,7 +18,8 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(),
val killedVariables: Set[Variable] = Set(), val killedVariables: Set[Variable] = Set(),
val assignment: Context = new Context(), val assignment: Context = new Context(),
val metric: Metric= collection.mutable.Map[String,Double](), 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(), ...@@ -42,14 +43,26 @@ class SupervisorStatus(val readyVariables: Set[Variable] = Set(),
*/ */
def isTerminated : Boolean = Supervisor.incrementCounter() > Supervisor.NB_ROUNDS 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*/ /*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,
metric, metric,
isFirstRound isFirstRound,
informValCounter = 0
) )
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment