1 | package agents.rlboa;
|
---|
2 |
|
---|
3 | import genius.core.Bid;
|
---|
4 | import genius.core.BidHistory;
|
---|
5 | import genius.core.bidding.BidDetails;
|
---|
6 | import genius.core.boaframework.*;
|
---|
7 | import genius.core.utility.AbstractUtilitySpace;
|
---|
8 | import genius.core.utility.UtilitySpace;
|
---|
9 |
|
---|
10 | import java.util.Collections;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | public class AverageTitForTatOfferingGamma2 extends OfferingStrategy {
|
---|
14 |
|
---|
15 | private int gamma = 2;
|
---|
16 | private int k = 0;
|
---|
17 | private List<BidDetails> allBids;
|
---|
18 |
|
---|
19 | private double minUtil;
|
---|
20 | private double maxUtil;
|
---|
21 |
|
---|
22 | public AverageTitForTatOfferingGamma2(NegotiationSession negotiationSession, OpponentModel opponentModel, OMStrategy omStrategy) {
|
---|
23 | super.init(negotiationSession, null);
|
---|
24 |
|
---|
25 | OutcomeSpace sortedOutcomeSpace = new SortedOutcomeSpace(this.negotiationSession.getUtilitySpace());
|
---|
26 | this.negotiationSession.setOutcomeSpace(sortedOutcomeSpace);
|
---|
27 | allBids = sortedOutcomeSpace.getAllOutcomes();
|
---|
28 |
|
---|
29 | // get min/max utility obtainable
|
---|
30 | try {
|
---|
31 | AbstractUtilitySpace utilitySpace = this.negotiationSession.getUtilitySpace();
|
---|
32 | Bid maxUtilBid = utilitySpace.getMaxUtilityBid();
|
---|
33 | Bid minUtilBid = utilitySpace.getMinUtilityBid();
|
---|
34 | maxUtil = utilitySpace.getUtility(maxUtilBid);
|
---|
35 | minUtil = utilitySpace.getUtility(minUtilBid);
|
---|
36 | minUtil = Math.max(minUtil, utilitySpace.getReservationValueUndiscounted());
|
---|
37 | } catch (Exception e) {
|
---|
38 | // exception is thrown by getMaxUtilityBid if there are no bids in the outcomespace
|
---|
39 | // but I guess that's pretty rare. Default to 0.0 - 1.0 to prevent crashes.
|
---|
40 | maxUtil = 1.0;
|
---|
41 | minUtil = 0.0;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public BidDetails determineOpeningBid() {
|
---|
47 | BidDetails openingsBid = allBids.get(k);
|
---|
48 | k++;
|
---|
49 | return openingsBid;
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public BidDetails determineNextBid() {
|
---|
54 | int opponentWindowSize = this.negotiationSession.getOpponentBidHistory().size();
|
---|
55 | BidDetails nextBid = null;
|
---|
56 |
|
---|
57 | // in the paper, the condition of applicability is t_n > 2*gamma; but because
|
---|
58 | // we keep track of opponent/own bids seperately we have devide the threshold by 2
|
---|
59 | // we can use averageTitForTat if the number of bids made by the opponent is larger
|
---|
60 | // than the window we average over
|
---|
61 | if (opponentWindowSize > gamma) {
|
---|
62 | double targetUtility = this.averageTitForTat();
|
---|
63 | nextBid = this.negotiationSession.getOutcomeSpace().getBidNearUtility(targetUtility);
|
---|
64 | } else {
|
---|
65 | nextBid = this.determineOpeningBid();
|
---|
66 | }
|
---|
67 |
|
---|
68 | return nextBid;
|
---|
69 | }
|
---|
70 |
|
---|
71 | private double averageTitForTat() {
|
---|
72 |
|
---|
73 | // determine relative change of opponent bid
|
---|
74 | int tOpp = this.negotiationSession.getOpponentBidHistory().size() - 1;
|
---|
75 | List<BidDetails> opponentHistory = this.negotiationSession.getOpponentBidHistory().getHistory();
|
---|
76 |
|
---|
77 | double opponentLastBid = opponentHistory.get(tOpp).getMyUndiscountedUtil();
|
---|
78 | double opponentFirstBidInWindow = opponentHistory.get(tOpp - gamma).getMyUndiscountedUtil();
|
---|
79 | double relativeChangeOpponent = opponentFirstBidInWindow / opponentLastBid;
|
---|
80 |
|
---|
81 | // target utility is the same change applied to our last bid
|
---|
82 | double myLastBid = this.negotiationSession.getOwnBidHistory().getLastBidDetails().getMyUndiscountedUtil();
|
---|
83 | double targetUtil = relativeChangeOpponent * myLastBid;
|
---|
84 |
|
---|
85 | return Math.min(Math.max(targetUtil, minUtil), maxUtil);
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public String getName() {
|
---|
90 | return "AverageTitForTat2 offering";
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|