From d87b24d5c0460ba08c991626652dd006f80348ef Mon Sep 17 00:00:00 2001
From: Alex <alexandravigneron1@gmail.com>
Date: Thu, 2 Jul 2020 17:07:22 +0200
Subject: [PATCH] renaming in choosebestsingleoffer

---
 .../solver/decentralized/mgm2/AgentBehaviour.scala       | 2 +-
 .../org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala | 9 ++++-----
 .../solver/decentralized/supervisor/Supervisor.scala     | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)

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 1791994..763281d 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/AgentBehaviour.scala
@@ -277,7 +277,7 @@ class AgentBehaviour(variable: Variable,
      case Event(MakeOffer(eventualOffer), mind) if mind.nbReceivedOffers == neighbours.size-1 =>
      if (debug) println(s"$variable in $stateName has received MakeOffer and the context is full.")
       var updatedMind: MGM2Mind = mind.addOffer(eventualOffer)
-      val (bestOffer, bestDelta) = updatedMind.chooseBestSingleOffer(variable, neighbours, constraints)
+      val (bestOffer, bestDelta) = updatedMind.chooseBestSingleOffer(variable, constraints)
        updatedMind = updatedMind.updateDeltas(variable, bestDelta)
        val partner : Option[Variable]= bestOffer match {
          case Some(o) => Some(o.offererVariable)
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 68210d3..b7dafea 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/mgm2/MGM2Mind.scala
@@ -122,7 +122,6 @@ class MGM2Mind(val context : Context = new Context(),
      * @param constraints which should be valuated
      */
    def chooseBestSingleOffer(receiverVariable: Variable,
-                             neighbours: Set[Variable],
                              constraints: Set[Constraint]): (Option[Offer], Double) = {
      val currentCost = currentContext.cost(constraints)
      var bestOffer: Option[Offer] = None // The best offer which will be selected, eventually none
@@ -133,13 +132,13 @@ class MGM2Mind(val context : Context = new Context(),
          val receiverValue: Value = move.context.getValue(receiverVariable).get
          val offererValue: Value = move.context.getValue(offererVariable).get
          val constraint: Constraint = relevantConstraint(constraints, receiverVariable, offererVariable)
-         val costConstraint = constraint.cost(context)
+         val commonUtilityBeforeChange = constraint.cost(context)
          val potentialContext = context.fix(offererVariable, offererValue).fix(receiverVariable, receiverValue)
+          val commonUtilityAfterChange = constraint.cost(potentialContext)
          val potentialCost =  potentialContext.cost(constraints)
-         val potentialCostConstraint = constraint.cost(potentialContext)
-         val gainConstraint = costConstraint - potentialCostConstraint
+         val sharedUtilityGain = commonUtilityAfterChange - commonUtilityBeforeChange
          //Subtract the difference in the link between the two agent so it is not counted twice
-         val delta: Double = currentCost - potentialCost + move.payoff - gainConstraint
+         val delta: Double = potentialCost - currentCost + move.payoff - sharedUtilityGain
          if (delta ~> bestDelta) {
            bestDelta = delta
            bestOffer = Some(new Offer(offererVariable, List(move)))
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 e0e4e5c..51e59e7 100644
--- a/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala
+++ b/src/main/scala/org/scadcop/solver/decentralized/supervisor/Supervisor.scala
@@ -249,7 +249,7 @@ class Supervisor(val pb : DCOP, val algorithm: Algorithm) extends Actor with Sta
 
 object Supervisor {
   var counter = 0
-  val NB_ROUNDS = 2
+  val NB_ROUNDS = 5
 
   def incrementCounter() : Int = {
     counter = counter + 1
-- 
GitLab