1 | package parties.in4010.q12015.group10;
|
---|
2 |
|
---|
3 | import static java.lang.Math.pow;
|
---|
4 |
|
---|
5 | import java.util.Iterator;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Random;
|
---|
8 |
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.Deadline;
|
---|
11 | import genius.core.bidding.BidDetails;
|
---|
12 | import genius.core.boaframework.OutcomeSpace;
|
---|
13 | import genius.core.misc.Range;
|
---|
14 | import genius.core.timeline.TimeLineInfo;
|
---|
15 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
16 |
|
---|
17 | public class OfferingStrategy {
|
---|
18 |
|
---|
19 | public static Bid createPotentialBid(AdditiveUtilitySpace utilitySpace,
|
---|
20 | Opponent[] opponents, TimeLineInfo timeline, Deadline deadLine) {
|
---|
21 | System.out.println("OfferingStrategy - createPotentialBid");
|
---|
22 |
|
---|
23 | // Settings
|
---|
24 | double BandWidth = 0.05;
|
---|
25 |
|
---|
26 | // Settings
|
---|
27 |
|
---|
28 | // Determine the central Utility for the Boulware strategy
|
---|
29 | double time = timeline.getTime();
|
---|
30 | // SETTING: MINIMAL ACCEPTABLE END UTILITY
|
---|
31 | double uEnd = 0.8; // End utility
|
---|
32 | double e = 0.1; // Boulware parameter
|
---|
33 | double Pboulware = 1 - pow(time, 1 / e) * (1 - uEnd);
|
---|
34 |
|
---|
35 | // Calculate the lower bound of our own utility to later search for the
|
---|
36 | // bids that have a higher utility than this lower bound
|
---|
37 | double min = Math.max(Pboulware * (1 - BandWidth / 2), 0); // Lowerbound
|
---|
38 | // : 0
|
---|
39 |
|
---|
40 | // Get lowerBound from offeringStrategy (different lower bound, one of
|
---|
41 | // the lower bounds will be used)
|
---|
42 | double lowerBoundStrategyEst = OpponentStrategyEstimator
|
---|
43 | .updateAllModels(opponents, deadLine, timeline, utilitySpace);
|
---|
44 | min = Math.max(min, lowerBoundStrategyEst); // select highest minimum
|
---|
45 | // utility
|
---|
46 |
|
---|
47 | Range UtilRange = new Range(min, 1);
|
---|
48 | // System.out.println("Create OutcomeSpace");
|
---|
49 | OutcomeSpace OS = new OutcomeSpace(utilitySpace);
|
---|
50 |
|
---|
51 | // select all the bids with corresponding to range
|
---|
52 | List<BidDetails> PotentialBids = OS.getBidsinRange(UtilRange);
|
---|
53 |
|
---|
54 | // Now Find bid with highest minimum utility for all players
|
---|
55 |
|
---|
56 | // Determine for each opponent the utility for each possible bid
|
---|
57 | // Count number of opponents and number of bids
|
---|
58 |
|
---|
59 | int NumberOfOpponents = opponents.length;
|
---|
60 | int NumberofBids = PotentialBids.size();
|
---|
61 |
|
---|
62 | double[][] OpponentBidUtilities = new double[NumberOfOpponents][NumberofBids];
|
---|
63 | int OpponentCounter = 0;
|
---|
64 | int BidCounter = 0;
|
---|
65 |
|
---|
66 | double[] OwnUtilities = new double[NumberofBids];
|
---|
67 |
|
---|
68 | // calculates the utilities of all bids for all opponents
|
---|
69 | for (Opponent currentOpponent : opponents) {
|
---|
70 | // Iterates over all opponents
|
---|
71 | BidCounter = 0;
|
---|
72 | AdditiveUtilitySpace OpponentUtilities = currentOpponent
|
---|
73 | .getEstimatedUtilitySpace();
|
---|
74 | for (Iterator<BidDetails> BidDetailsIterator = PotentialBids
|
---|
75 | .iterator(); BidDetailsIterator.hasNext();) {
|
---|
76 | // Iterates over all possible bids
|
---|
77 | BidDetails Biddetails = BidDetailsIterator.next();
|
---|
78 | Bid bid = Biddetails.getBid();
|
---|
79 | double util = 0;
|
---|
80 | try {
|
---|
81 | util = OpponentUtilities.getUtility(bid);
|
---|
82 | } catch (Exception e1) {
|
---|
83 | // System.out.println("Invalid Bid");
|
---|
84 | e1.printStackTrace();
|
---|
85 | } // Throws Exception when bid is invalid
|
---|
86 | // Place calculated Utility in data Matrix
|
---|
87 | OpponentBidUtilities[OpponentCounter][BidCounter] = util;
|
---|
88 |
|
---|
89 | // Calculate own utility
|
---|
90 | try {
|
---|
91 | OwnUtilities[BidCounter] = utilitySpace.getUtility(bid);
|
---|
92 | } catch (Exception e1) {
|
---|
93 | e1.printStackTrace();
|
---|
94 | }
|
---|
95 | BidCounter++;
|
---|
96 | }
|
---|
97 | OpponentCounter++;
|
---|
98 | }
|
---|
99 |
|
---|
100 | double minUtil = 100;
|
---|
101 | double MaxMinUtil = 0;
|
---|
102 | int BestBidNumber_maxmin = -1;
|
---|
103 | int BestBidNumber_bestAlternative = -1;
|
---|
104 |
|
---|
105 | // now select bid that:
|
---|
106 | // has the highest minimum utility
|
---|
107 | // has a lower utility for the opponents than our own utility
|
---|
108 | for (int i = 0; i < NumberofBids; i++) {
|
---|
109 | // Gaat eerst langs de rijen (bids), vervolgens langs de kolommen
|
---|
110 | // (opponents)
|
---|
111 | // om de bid te vinden die het hoogste minimum heeft
|
---|
112 | for (int p = 0; p < NumberOfOpponents; p++) {
|
---|
113 | // System.out.println("2nd Iterate over Opponents");
|
---|
114 | double util = OpponentBidUtilities[p][i];
|
---|
115 |
|
---|
116 | if (util < minUtil) {
|
---|
117 | minUtil = util; // Results in lowest utility per bid
|
---|
118 | }
|
---|
119 | }
|
---|
120 | double ownUtil = OwnUtilities[i];
|
---|
121 | // if the minimum utility of this bid for all agents is higher than
|
---|
122 | // that of another bid for all agents
|
---|
123 | // and if the utility is lower than our own utility then update the
|
---|
124 | // bestnumber.
|
---|
125 | if (minUtil > MaxMinUtil && minUtil < ownUtil) {
|
---|
126 | BestBidNumber_maxmin = i;
|
---|
127 | } else if (minUtil > MaxMinUtil) {
|
---|
128 | BestBidNumber_bestAlternative = i;
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Determine the best bid from the list of bids according to strategy 3
|
---|
133 | BidDetails bd = null;
|
---|
134 | if (BestBidNumber_maxmin != -1) { // a good bid has been found
|
---|
135 | bd = PotentialBids.get(BestBidNumber_maxmin);
|
---|
136 | } else if (BestBidNumber_bestAlternative != -1) {
|
---|
137 | bd = PotentialBids.get(BestBidNumber_bestAlternative);
|
---|
138 | } else {
|
---|
139 | Random r = new Random();
|
---|
140 | int maxBound = NumberofBids - 1;
|
---|
141 | int minBound = 0;
|
---|
142 | int rand = r.nextInt((maxBound - minBound) + 1) + minBound;
|
---|
143 | bd = PotentialBids.get(rand);
|
---|
144 | }
|
---|
145 | Bid offer = bd.getBid();
|
---|
146 |
|
---|
147 | return offer;
|
---|
148 |
|
---|
149 | }
|
---|
150 | }
|
---|