Skip to content
Snippets Groups Projects
Commit 6d276c99 authored by Maxime MORGE's avatar Maxime MORGE
Browse files

In AgentBehaviour, thereiver decline to the other OFFERERS

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