Skip to content

Commit

Permalink
History Work
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatakis committed Dec 30, 2017
1 parent 28167dc commit 9b57ab2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 105 deletions.
7 changes: 6 additions & 1 deletion src/BestAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SimulatedAnnealingParams getSimulatedAnnealingParams() {

@Override
public double getBidUtilThreshold() {
return 0.99;
return 0.96;
}

@Override
Expand All @@ -64,6 +64,11 @@ public boolean useHistory() {
return true;
}

@Override
public double getSoftConcessionThreshold() {
return 0.9;
}

@Override
public double getConcessionThreshold() {
return 0.98;
Expand Down
9 changes: 8 additions & 1 deletion src/Core/AgentAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,19 @@ public interface AgentAPI {
boolean useHistory();

/**
* Value after which the agent will offer the min best offer.
* Value after which the agent will offer the min best received offer.
*
* @return a number in [0,1]
*/
double getConcessionThreshold();

/**
* After this time threshold start offering enemy smallest offers from history.
*
* @return a number in [0,1]
*/
double getSoftConcessionThreshold();

/**
* Number of previous rounds to to search in history.
*
Expand Down
41 changes: 21 additions & 20 deletions src/Core/BidHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import negotiator.persistent.PersistentDataContainer;

import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
Expand All @@ -18,18 +19,17 @@
import static Core.ThrashAgent.gLog;

public class BidHistory {
private final NegotiationInfo info;
private StandardInfoList history;
private Map<String, Double> bestOfferedUtils;
private Map<String, Double> worstOfferedUtils;
private Map<String, Map<Integer, Double>> acceptedUtils; //The accepted bids of enemies for different rounds
private int round;
private Random RNG;

public BidHistory(Random RNG, PersistentDataContainer pData) {
public BidHistory(NegotiationInfo info, Random RNG, PersistentDataContainer pData) {
this.RNG = RNG;
this.bestOfferedUtils = new HashMap<>();
this.worstOfferedUtils = new HashMap<>();
this.acceptedUtils = new HashMap<>();
this.info = info;

switch (pData.getPersistentDataType()) {
case DISABLED:
Expand All @@ -38,10 +38,13 @@ public BidHistory(Random RNG, PersistentDataContainer pData) {
break;
case STANDARD:
this.history = (StandardInfoList) pData.get();
this.round = history.size();
this.bestOfferedUtils = new HashMap<>();
this.worstOfferedUtils = new HashMap<>();
this.acceptedUtils = new HashMap<>();

//Compute for each party the maximum and minimum utility in last session.
if (!history.isEmpty()) {
this.round = history.size();

if (MemoryDepth < 1 || history.size() <= MemoryDepth) {
MemoryDepth = history.size() - 1;
Expand All @@ -56,20 +59,10 @@ public BidHistory(Random RNG, PersistentDataContainer pData) {
bestOfferedUtils.put(party, bestOfferedUtils.containsKey(party) ? Math.max(bestOfferedUtils.get(party), util) : util);
worstOfferedUtils.put(party, worstOfferedUtils.containsKey(party) ? Math.min(worstOfferedUtils.get(party), util) : util);

if (!acceptedUtils.containsKey(party)) {
acceptedUtils.put(party, new HashMap<>());
}

acceptedUtils.put(party, new HashMap<>());
acceptedUtils.get(party).put(i, util);
}
}

gLog.println("Accepted values");
for (String party : acceptedUtils.keySet()) {
for (Map.Entry<Integer, Double> value : acceptedUtils.get(party).entrySet()) {
gLog.println(party + " " + value);
}
}
}
break;
}
Expand All @@ -80,6 +73,8 @@ public void logHistory() {
gLog.println(bestOfferedUtils);
gLog.println("Worst");
gLog.println(worstOfferedUtils);
gLog.println("Accepted");
gLog.println(acceptedUtils);
}

public Map<String, Double> getBestOfferedUtils() {
Expand All @@ -98,9 +93,15 @@ public void setBestOppVals(Opponent opponent, AgentID sender) {
}
}

public double getLuckyBid(AgentID partyId) {
double l = acceptedUtils.get(partyId.getName()).get(RNG.nextInt(round));
gLog.println("Lucky BID");
return l;
public double getLuckyValue(AgentID partyId) {
double val = 0.999;
try {
for (int i : acceptedUtils.get(partyId.getName()).keySet()) {
val = Math.min(acceptedUtils.get(partyId.getName()).get(i), val);
}
} catch (Exception ignored) {
}
gLog.println("Lucky val for " + partyId.getName() + ": " + val);
return val;
}
}
6 changes: 5 additions & 1 deletion src/Core/BidStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,16 @@ private Bid relativeUtilitySearch(Bid thresholdBid) {
Math.min(threshold, 1 - (1 - emax) * Math.pow(time, 3.0)) :
Math.max(threshold - time, emax);

// Negotiations on the brink of breakup, make a concession to the greatest one in the past proposal
// make a concession ASAP
if (time > concessionThreshold) {
for (AgentID sender : rivals.keySet()) {
threshold = Math.min(threshold, rivals.get(sender).BestOfferUtil);
}
threshold = Math.max(threshold, reservationVal);
} else if (useHistory && time > softConcessionThreshold) {
for (AgentID sender : rivals.keySet()) {
threshold = Math.min(threshold, bidHistory.getLuckyValue(sender));
}
}

return threshold;
Expand Down
4 changes: 3 additions & 1 deletion src/Core/ThrashAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class ThrashAgent extends AbstractNegotiationParty implements Ag
static PrintWriter gLog;
static String filename;
static int MemoryDepth;
static double softConcessionThreshold;


@Override
Expand All @@ -45,6 +46,7 @@ public void init(NegotiationInfo info) {
utilitySpace = info.getUtilitySpace();
MemoryDepth = getMemoryDepth();
concessionThreshold = getConcessionThreshold();
softConcessionThreshold = getSoftConcessionThreshold();
myDescription = getDescription();
VetoVal = getVetoVal();
SearchingMethod = getSearchingMethod();
Expand All @@ -63,7 +65,7 @@ public void init(NegotiationInfo info) {
useHistory = useHistory();
if (useHistory) {
try {
bidHistory = new BidHistory(RNG, getData());
bidHistory = new BidHistory(info, RNG, getData());
} catch (Exception e) {
gLog.println(e.toString());
useHistory = false;
Expand Down
81 changes: 0 additions & 81 deletions src/Thresh1.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/TimeAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public double getConcessionThreshold() {
return 0.98;
}

@Override
public double getSoftConcessionThreshold() {
return 0.9;
}

@Override
public int getMemoryDepth() {
return 3;
Expand Down

0 comments on commit 9b57ab2

Please sign in to comment.