diff --git a/src/main/scala/org/scadcop/problem/DCOP.scala b/src/main/scala/org/scadcop/problem/DCOP.scala
index 124c616f1fa12c206708aeade8b6cdda2da4bf37..f6985725f1c2b1e5a1f63fd2e2580a58da90b70a 100644
--- a/src/main/scala/org/scadcop/problem/DCOP.scala
+++ b/src/main/scala/org/scadcop/problem/DCOP.scala
@@ -8,6 +8,8 @@ package org.scadcop.problem
*/
class DCOP(val variables: Set[Variable], val constraints: Set[Constraint]) {
+ val debug = false
+
/**
* String representation
*/
@@ -40,6 +42,7 @@ class DCOP(val variables: Set[Variable], val constraints: Set[Constraint]) {
if (constraint.varA == variable) variables = variables + constraint.varB
if (constraint.varB == variable) variables = variables + constraint.varA
}
+ if (debug) println(s"DCOP: linked variables of $variable=$variables")
variables
}
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 5dea133593a2d77f0cb541b4b18d034f1646b59a..d2ced5726428ab097454bb797efc4ffd23f133aa 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala
@@ -24,8 +24,6 @@ class AgentBehaviour(variable: Variable,
with FSM[MGM2State, MGM2Mind]
with Stash {
- debug = true
-
/**
* Initially the agent has no task in the bundle
*/
@@ -77,7 +75,6 @@ class AgentBehaviour(variable: Variable,
case Event(ContinueAlgo, mind) =>
if (debug) println(s"$variable in $stateName has received ContinueAlgo")
val updatedMind = mind.reset(variable) // performing a reset
- if (trace) println(s"$variable -> All : InformValue(${updatedMind.context.getValue(variable).get})")
broadcast(InformValue(updatedMind.context.getValue(variable).get))
val b: Boolean = mind.determineSubset(AgentBehaviour.THRESHOLD)
if (trace) println(s"$variable -> $variable : ChooseSubset($b)")
@@ -116,13 +113,13 @@ class AgentBehaviour(variable: Variable,
// When it receives a ChooseSubset(true) and becomes an Offerer
case Event(ChooseSubset(true), mind) =>
if (debug) println(s"$variable in $stateName has received ChooseSubset(true)")
- broadcast(MakeOffer(new Offer(variable, List())))
unstashAll
goto(OffererWaitingValues) using mind
// When it receives a ChooseSubset(false) and becomes a Receiver
case Event(ChooseSubset(false), mind) =>
if (debug) println(s"$variable in $stateName has received ChooseSubset(false)")
+ broadcast(MakeOffer(new Offer(variable, List())))
unstashAll
goto(ReceiverWaitingValues) using mind
}
@@ -152,7 +149,6 @@ class AgentBehaviour(variable: Variable,
if (debug) println(s"$variable> context before computing the joint offer=${updatedMind.currentContext}")
val moves: List[BilateralMove] = updatedMind.computeJointOffer(potentialPartner, neighbours, constraints)
val offer: Offer = new Offer(variable, moves)
- if (trace) println(s"$variable -> $potentialPartner : MakeOffer(${Some(offer)})")
directory.addressOf(potentialPartner) ! MakeOffer(offer)
if (trace) println(s"$variable -> $potentialPartner : MakeOffer(${Some(offer)}")
multicast(neighbours - potentialPartner, MakeOffer(new Offer(variable, List())))
@@ -174,7 +170,7 @@ class AgentBehaviour(variable: Variable,
//when it receives a neighbour's delta
case Event(InformDelta(_), mind) =>
- if (debug) println(s"$variable in $stateName has received Informdelta")
+ if (debug) println(s"$variable in $stateName has received InformDelta")
stash
stay using mind
@@ -190,10 +186,12 @@ class AgentBehaviour(variable: Variable,
case Event(Accept(offer), mind) =>
if (debug) println(s"$variable in $stateName has received Accept")
val newPartner: Variable = directory.variableOf(sender)
- val move : Move = offer.moves.head
- val updatedMind: MGM2Mind = mind.commitFully(newPartner, offer)
- if (trace) println(s"$variable -> All : InformDelta(${updatedMind.deltas(variable)})")
+ var updatedMind: MGM2Mind = mind.commitFully(newPartner, offer)
broadcast(InformDelta(updatedMind.deltas(variable)))
+ // MM: Should be replaced by
+ // broadcast(InformDelta(offer.moves.head.payoff))
+ // updatedMind = updatedMind.setCurrBestOffer(Some(offer))
+ // No ?
unstashAll
goto(Committed) using updatedMind
@@ -208,7 +206,6 @@ class AgentBehaviour(variable: Variable,
}
updatedMind = updatedMind.updateDeltas(variable: Variable, bestDelta)
updatedMind = updatedMind.setCurrBestOffer(bestOffer)
- if (trace) println(s"$variable -> All : InformDelta(${updatedMind.deltas(variable)})")
broadcast(InformDelta(updatedMind.deltas(variable)))
unstashAll
goto(Uncommitted) using updatedMind
@@ -222,6 +219,12 @@ class AgentBehaviour(variable: Variable,
* Either the agent is in the ReceiverWaitingValues state
*/
when(ReceiverWaitingValues) {
+
+ // When it receives a reject it does NOTHING
+ case Event(Reject(_), mind) =>
+ if (debug) println(s"$variable in $stateName has received Reject")
+ stay using mind
+
// When the context is partial
case Event(InformValue(peerValue), mind) if mind.context.size < neighbours.size =>
if (debug) println(s"$variable in $stateName has received InformValue and the context is partial.")
@@ -286,6 +289,11 @@ class AgentBehaviour(variable: Variable,
*/
when(ReceiverAllOffersReceived) {
+ // When it receives a reject it does NOTHING
+ case Event(Reject(_), mind) =>
+ if (debug) println(s"$variable in $stateName has received Reject")
+ stay using mind
+
// When it receives a neighbour's delta
case Event(InformDelta(_), mind) =>
if (debug) println(s"$variable in $stateName has received InformDelta")
@@ -298,8 +306,7 @@ class AgentBehaviour(variable: Variable,
if (trace) println(s"$variable -> ${bestOffer.offererVariable} : Accept($bestOffer)")
directory.addressOf(bestOffer.offererVariable) ! Accept(bestOffer)
val updatedMind: MGM2Mind = mind.commitFully(bestOffer.offererVariable, bestOffer)
- rejectOffers(updatedMind.receivedOffers.filterNot(_ == bestOffer))//decline all other offers
- if (trace) println(s"$variable -> All : InformDelta(${updatedMind.deltas(variable)})")
+ rejectOffers(updatedMind.receivedOffers.filterNot(_.offererVariable == bestOffer.offererVariable))//DONE decline to the other OFFERERS
broadcast(InformDelta(updatedMind.deltas(variable))) //inform all neighbours
unstashAll
goto(Committed) using updatedMind
@@ -308,9 +315,7 @@ class AgentBehaviour(variable: Variable,
case Event(BestOffer(None), mind) =>
if (debug) println(s"$variable in $stateName has received BestOffer(empty)")
val updatedMind: MGM2Mind = mind.uncommit()
- if (trace) println(s"$variable -> All : Reject(someOffer)")
rejectOffers(updatedMind.receivedOffers) //decline all offers
- if (trace) println(s"$variable -> All : InformDelta(${updatedMind.deltas(variable)})")
broadcast(InformDelta(updatedMind.deltas(variable))) //inform all neighbours
unstashAll
goto(Committed) using updatedMind
@@ -320,6 +325,12 @@ class AgentBehaviour(variable: Variable,
* Either the agent is in the Committed state
*/
when(Committed) {
+
+ // When it receives a reject it does NOTHING
+ case Event(Reject(_), mind) =>
+ if (debug) println(s"$variable in $stateName has received Reject")
+ stay using mind
+
// When it receives an offer it does NOTHING
case Event(MakeOffer(_), mind) =>
if (debug) println(s"$variable in $stateName has received MakeOffer")
@@ -355,7 +366,7 @@ class AgentBehaviour(variable: Variable,
when(Uncommitted){
// When it receives a reject it does NOTHING
case Event(Reject(_), mind) =>
- if (debug) println(s"$variable in $stateName has received MakeOffer")
+ if (debug) println(s"$variable in $stateName has received Reject")
stay using mind
// When it receives an offer it does NOTHING
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 33c2341397dcd7ae89cd01449daf38e2c6fbd160..4bd106cfc668650a3e3041f99b3c7a26b18b6d60 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala
@@ -142,7 +142,7 @@ class MGM2Mind(val context : Context = new Context(),
val potentialCostConstraint = constraint.cost(potentialContext)
val gainConstraint = costConstraint - potentialCostConstraint
//Subtract the difference in the link between the two agent so it is not counted twice
- val delta: Double = currentCost - potentialCost + move.gain - gainConstraint
+ val delta: Double = currentCost - potentialCost + move.payoff - gainConstraint
if (delta ~> bestDelta) {
bestDelta = delta
bestOffer = Some(new Offer(offererVariable, List(move)))
diff --git a/src/main/scala/org/scadcop/solver/decentralized/mgm2/Move.scala b/src/main/scala/org/scadcop/solver/decentralized/mgm2/Move.scala
index 07b78ce07822470969e0198712dea7244d9d7052..381f403c35c79c0bc0c428f8d0bb448075f84cfc 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/Move.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/Move.scala
@@ -6,10 +6,10 @@ import org.scadcop.problem._
/**
* Abstract class representing a move
* @param context is an assignment
- * @param gain is the associated gain
+ * @param payoff is the associated gain
*/
-abstract class Move(val context : Context, val gain: Double){
- override def toString: String = s"context with payoff ${gain.toString}"
+abstract class Move(val context : Context, val payoff: Double){
+ override def toString: String = s"context=$context payoff= $payoff"
}
/**
diff --git a/src/main/scala/org/scadcop/solver/decentralized/mgm2/Offer.scala b/src/main/scala/org/scadcop/solver/decentralized/mgm2/Offer.scala
index c7c451d0f0f369e783ac75dad3fe51a778d444b6..e9c21cc504fdcdc9a40f1a1ab2ef2b23beb4f986 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/Offer.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/Offer.scala
@@ -9,5 +9,5 @@ import org.scadcop.problem._
* @param moves is a list of coordinated moves
*/
class Offer(val offererVariable : Variable, val moves : List[Move]){
- override def toString: String = s"$offererVariable.toString moves= ${moves.mkString("[",",","]")}"
+ override def toString: String = s"offerer=$offererVariable moves= ${moves.mkString("[",",","]")}"
}