1 | package parties.in4010.q12015.group9;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.Iterator;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.BidHistory;
|
---|
8 | import genius.core.timeline.TimeLineInfo;
|
---|
9 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
10 |
|
---|
11 | public class AcceptStrat {
|
---|
12 | private AdditiveUtilitySpace ourUtility;
|
---|
13 |
|
---|
14 | public AcceptStrat(AdditiveUtilitySpace ownUtility) {
|
---|
15 | ourUtility = ownUtility;
|
---|
16 | }
|
---|
17 |
|
---|
18 | // This is called at the end of every chooseAction to determine if we bid or
|
---|
19 | // accept
|
---|
20 | public boolean determineAcceptance(Bid opponentBid,
|
---|
21 | HashMap<Object, BidHistory> previousBidsMap, Bid ourBid,
|
---|
22 | HashMap<Object, AdditiveUtilitySpace> opponentUtilities,
|
---|
23 | TimeLineInfo timeLine) {
|
---|
24 | try {
|
---|
25 | double ourBidUtil = ourUtility.getUtility(ourBid);
|
---|
26 | double theirBidUtil = ourUtility.getUtility(opponentBid);
|
---|
27 | HashMap<Object, BidHistory> bidHistory = previousBidsMap;
|
---|
28 | double curTime = timeLine.getTime();
|
---|
29 | // Get a utility compared to our bid, time and utility compared to
|
---|
30 | // constant acceptance
|
---|
31 | boolean ACNext = acceptanceRatingNext(ourBidUtil, theirBidUtil);
|
---|
32 | boolean ACTime = acceptanceRatingTime(curTime, theirBidUtil);
|
---|
33 | boolean ACConst = acceptanceRatingConst(theirBidUtil, bidHistory,
|
---|
34 | curTime);
|
---|
35 | // If any strategy accepts we accept, the current parameters for the
|
---|
36 | // strategies mean we are basically running a next bid value
|
---|
37 | // strategy which also accepts anything at the very last second and
|
---|
38 | // accepts insanely good bids
|
---|
39 | return (ACNext || ACTime || ACConst);
|
---|
40 | } catch (Exception e) {
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | // Function for determining acceptance mostly based on a constant. Generally
|
---|
46 | // we will use this to only accept the most insanely good offers
|
---|
47 | private boolean acceptanceRatingConst(double theirBidUtil,
|
---|
48 | HashMap<Object, BidHistory> previousBidsMap, double t) {
|
---|
49 | double requiredConst = 0.80; // default mninimum constant value
|
---|
50 | double lowerbound = 83;
|
---|
51 | double upperbound = 96;
|
---|
52 | if (t >= lowerbound && t < upperbound) { // decrease constant linearly
|
---|
53 | // in this range
|
---|
54 | requiredConst = requiredConst - 1
|
---|
55 | * ((t - lowerbound) / (upperbound - lowerbound));
|
---|
56 | } else if (t >= upperbound) {
|
---|
57 | double r = 1 - t; // time remaining in negotation
|
---|
58 | Iterator<BidHistory> historyIterator = previousBidsMap.values()
|
---|
59 | .iterator();
|
---|
60 | double maxUtil = 0;
|
---|
61 | while (historyIterator.hasNext()) { // retrieve max bid from every
|
---|
62 | // sender within remaining time
|
---|
63 | // window
|
---|
64 | BidHistory bidHistory = historyIterator.next();
|
---|
65 | double partyMax = bidHistory.filterBetweenTime(t - r, t)
|
---|
66 | .getBestBidDetails().getMyUndiscountedUtil();
|
---|
67 | if (partyMax > maxUtil) {
|
---|
68 | maxUtil = partyMax;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | requiredConst = maxUtil;
|
---|
72 | }
|
---|
73 | return (theirBidUtil > requiredConst);
|
---|
74 | }
|
---|
75 |
|
---|
76 | // Function for determining acceptance mostly based on time. Currently this
|
---|
77 | // is only used to accept (nearly) any bid when we probably can't make any
|
---|
78 | // new bids anymore anyways.
|
---|
79 | private boolean acceptanceRatingTime(double t, double theirBidUtil) {
|
---|
80 | final double requiredTime = 0.98;
|
---|
81 | final double minUtil = 0.3;
|
---|
82 | return (t >= requiredTime) & (theirBidUtil > minUtil);
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 | // This function determines acceptance mostly based on the next bid combined
|
---|
87 | // with some time discounting (on top of the basic time discounting of our
|
---|
88 | // own bids)
|
---|
89 | private boolean acceptanceRatingNext(double ourBidUtil, double theirBidUtil) {
|
---|
90 | final double a = 0.98;
|
---|
91 | final double b = 0.00;
|
---|
92 | return (a * theirBidUtil + b) > ourBidUtil;
|
---|
93 | }
|
---|
94 | }
|
---|