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
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
......@@ -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
......
......@@ -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)))
......
......@@ -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"
}
/**
......
......@@ -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("[",",","]")}"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment