1 | package negotiator.boaframework.offeringstrategy.anac2012;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.Map;
|
---|
6 | import java.util.Random;
|
---|
7 |
|
---|
8 | import agents.anac.y2012.OMACagent.TimeBidHistory;
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.bidding.BidDetails;
|
---|
11 | import genius.core.boaframework.NegotiationSession;
|
---|
12 | import genius.core.boaframework.NoModel;
|
---|
13 | import genius.core.boaframework.OMStrategy;
|
---|
14 | import genius.core.boaframework.OfferingStrategy;
|
---|
15 | import genius.core.boaframework.OpponentModel;
|
---|
16 | import genius.core.boaframework.SortedOutcomeSpace;
|
---|
17 | import genius.core.issue.Issue;
|
---|
18 | import genius.core.issue.IssueDiscrete;
|
---|
19 | import genius.core.issue.IssueInteger;
|
---|
20 | import genius.core.issue.IssueReal;
|
---|
21 | import genius.core.issue.Value;
|
---|
22 | import genius.core.issue.ValueInteger;
|
---|
23 | import genius.core.issue.ValueReal;
|
---|
24 | import genius.core.misc.Range;
|
---|
25 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
26 | import negotiator.boaframework.opponentmodel.DefaultModel;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * This is the decoupled Bidding Strategy of OMACAgent
|
---|
30 | *
|
---|
31 | * For the opponent model extension a range of bids is found near the target
|
---|
32 | * utility. The opponent model strategy uses the OM to select a bid from this
|
---|
33 | * range of bids.
|
---|
34 | *
|
---|
35 | * DEFAULT OM: None
|
---|
36 | *
|
---|
37 | * @author Alex Dirkzwager, Mark Hendrikx
|
---|
38 | */
|
---|
39 | public class OMACagent_Offering extends OfferingStrategy {
|
---|
40 |
|
---|
41 | private double MINIMUM_UTILITY = 0.59; // 0.618
|
---|
42 | private double resU = 0.0;
|
---|
43 | private double EU = 0.95; // a threshold of expected utility for a session,
|
---|
44 | // in use now
|
---|
45 | private double est_t = 0;
|
---|
46 | private double est_u = 0;
|
---|
47 | private TimeBidHistory mBidHistory; // new
|
---|
48 | private int intervals = 100;
|
---|
49 | private double timeInt = 1.0 / (double) intervals;
|
---|
50 | private double discount = 1.0;
|
---|
51 | private Bid maxBid = null; // the maxBid which can be made by itself
|
---|
52 | private double maxBidU = 0.0; // the uti of the bid above
|
---|
53 | private double cTime = 0.0;
|
---|
54 | private int tCount = 0;
|
---|
55 | private double nextUti = 0.96;
|
---|
56 | private double discountThreshold = 0.845D;
|
---|
57 | private double exma;
|
---|
58 | private double est_mu;
|
---|
59 | private double est_mt;
|
---|
60 | private double maxTime = 180.0;
|
---|
61 | private AdditiveUtilitySpace utilitySpace;
|
---|
62 | private SortedOutcomeSpace outcomespace;
|
---|
63 |
|
---|
64 | private Random randomnr;
|
---|
65 | private final boolean TEST_EQUIVALENCE = true;
|
---|
66 |
|
---|
67 | public OMACagent_Offering() {
|
---|
68 | }
|
---|
69 |
|
---|
70 | public OMACagent_Offering(NegotiationSession negoSession, OpponentModel model, OMStrategy oms) throws Exception {
|
---|
71 | init(negoSession, model, oms, null);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Init required for the Decoupled Framework.
|
---|
76 | */
|
---|
77 | @Override
|
---|
78 | public void init(NegotiationSession negoSession, OpponentModel model, OMStrategy oms,
|
---|
79 | Map<String, Double> parameters) throws Exception {
|
---|
80 | if (model instanceof DefaultModel) {
|
---|
81 | model = new NoModel();
|
---|
82 | }
|
---|
83 | if (!(model instanceof NoModel)) {
|
---|
84 | outcomespace = new SortedOutcomeSpace(negoSession.getUtilitySpace());
|
---|
85 | }
|
---|
86 | super.init(negoSession, model, oms, parameters);
|
---|
87 | utilitySpace = (AdditiveUtilitySpace) negoSession.getUtilitySpace();
|
---|
88 | if (utilitySpace.getReservationValue() != null) {
|
---|
89 | resU = utilitySpace.getReservationValue();
|
---|
90 | if (MINIMUM_UTILITY < resU)
|
---|
91 | MINIMUM_UTILITY = resU * 1.06;
|
---|
92 | }
|
---|
93 |
|
---|
94 | if (utilitySpace.getDiscountFactor() <= 1D && utilitySpace.getDiscountFactor() > 0D)
|
---|
95 | discount = utilitySpace.getDiscountFactor();
|
---|
96 |
|
---|
97 | try {
|
---|
98 | maxBid = utilitySpace.getMaxUtilityBid();
|
---|
99 | maxBidU = utilitySpace.getUtility(maxBid);
|
---|
100 | EU = EU * maxBidU;
|
---|
101 | } catch (Exception e) {
|
---|
102 | // System.out.println("Errors in ini process!");
|
---|
103 | }
|
---|
104 |
|
---|
105 | mBidHistory = new TimeBidHistory(this.utilitySpace, discount);
|
---|
106 | if (TEST_EQUIVALENCE) {
|
---|
107 | randomnr = new Random(100);
|
---|
108 | } else {
|
---|
109 | randomnr = new Random();
|
---|
110 |
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Override
|
---|
115 | public BidDetails determineOpeningBid() {
|
---|
116 | return determineNextBid();
|
---|
117 | }
|
---|
118 |
|
---|
119 | @Override
|
---|
120 | public BidDetails determineNextBid() {
|
---|
121 | Bid bidToOffer = null;
|
---|
122 |
|
---|
123 | try {
|
---|
124 | if (negotiationSession.getOpponentBidHistory().size() == 0) {
|
---|
125 | bidToOffer = chooseBidAction();
|
---|
126 | } else {
|
---|
127 | cTime = negotiationSession.getTime();
|
---|
128 | Bid partnerBid = negotiationSession.getOpponentBidHistory().getLastBid();
|
---|
129 | double offeredUtilFromOpponent = getUtility(partnerBid);
|
---|
130 | mBidHistory.addOpponentBidnTime(offeredUtilFromOpponent, partnerBid, cTime);
|
---|
131 |
|
---|
132 | bidToOffer = chooseBidAction();
|
---|
133 | }
|
---|
134 | } catch (Exception e) {
|
---|
135 | e.printStackTrace();
|
---|
136 | /*
|
---|
137 | * if (resU != 0){ bidToOffer=new EndNegotiation(); }else{
|
---|
138 | * bidToOffer=new Accept(getAgentID()); }
|
---|
139 | */
|
---|
140 | }
|
---|
141 | try {
|
---|
142 | nextBid = new BidDetails(bidToOffer, negotiationSession.getUtilitySpace().getUtility(bidToOffer));
|
---|
143 | } catch (Exception e) {
|
---|
144 | e.printStackTrace();
|
---|
145 | }
|
---|
146 | return nextBid;
|
---|
147 | }
|
---|
148 |
|
---|
149 | private Bid chooseBidAction() {
|
---|
150 | Bid possibleNextBid = null;
|
---|
151 | try {
|
---|
152 | if (cTime <= 0.02) {
|
---|
153 | possibleNextBid = maxBid;
|
---|
154 | } else {
|
---|
155 | possibleNextBid = getFinalBid();
|
---|
156 | }
|
---|
157 | } catch (Exception e) {
|
---|
158 |
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (possibleNextBid == null) {
|
---|
162 | // return (new Accept(getAgentID())); //need to break off
|
---|
163 | // negotiation now
|
---|
164 | endNegotiation = true;
|
---|
165 | return possibleNextBid;
|
---|
166 | }
|
---|
167 |
|
---|
168 | mBidHistory.addMyBid(possibleNextBid);
|
---|
169 | // System.out.println("Decoupled action: " + possibleNextBid);
|
---|
170 |
|
---|
171 | return possibleNextBid;
|
---|
172 | }
|
---|
173 |
|
---|
174 | private Bid getFinalBid() {
|
---|
175 | Bid bid = null;
|
---|
176 | double upper = 1.01;
|
---|
177 | double lower = 0.99;
|
---|
178 | double splitFactor = 3.0;
|
---|
179 | double val = 0.0;
|
---|
180 | double dval = 0.0;
|
---|
181 | int delay = 75;
|
---|
182 | double laTime = 0D;
|
---|
183 | double adp = 1.2;
|
---|
184 |
|
---|
185 | if (discount >= discountThreshold) {
|
---|
186 | // System.out.println("Decoupled discount > threshold");
|
---|
187 |
|
---|
188 | if (cTime <= (double) delay / 100.0) {
|
---|
189 | if (resU <= 0.3) {
|
---|
190 | return maxBid;
|
---|
191 | } else {
|
---|
192 | val = EU;
|
---|
193 | }
|
---|
194 |
|
---|
195 | dval = val * Math.pow(discount, cTime);
|
---|
196 | if (opponentModel instanceof NoModel) {
|
---|
197 | bid = genRanBid(val * lower, val * upper);
|
---|
198 | } else {
|
---|
199 | Range range = new Range(val * lower, val * upper);
|
---|
200 | bid = omStrategy.getBid(outcomespace, range).getBid();
|
---|
201 | }
|
---|
202 |
|
---|
203 | return bid;
|
---|
204 | } else if (cTime > 0.01 * (tCount + delay)) {
|
---|
205 | nextUti = getNextUti();
|
---|
206 | tCount++;
|
---|
207 | }
|
---|
208 | } else {
|
---|
209 | if (cTime <= discount / splitFactor) {
|
---|
210 | if (resU <= 0.3) {
|
---|
211 | return maxBid;
|
---|
212 | } else {
|
---|
213 | val = EU;
|
---|
214 | }
|
---|
215 |
|
---|
216 | dval = val * Math.pow(discount, cTime);
|
---|
217 |
|
---|
218 | if (opponentModel instanceof NoModel) {
|
---|
219 | bid = genRanBid(val * (1.0 - 0.02), val * (1.0 + 0.02));
|
---|
220 | } else {
|
---|
221 | Range range = new Range(val * (1.0 - 0.02), val * (1.0 + 0.02));
|
---|
222 | bid = omStrategy.getBid(outcomespace, range).getBid();
|
---|
223 | }
|
---|
224 | return bid;
|
---|
225 | } else if (cTime > 0.01 * (tCount + (int) Math.floor(discount / splitFactor * 100))) {
|
---|
226 | nextUti = getNextUti();
|
---|
227 | tCount++;
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | if (nextUti == -3.0) {
|
---|
232 | if (resU <= 0.3) {
|
---|
233 | return maxBid;
|
---|
234 | } else {
|
---|
235 | val = EU;
|
---|
236 | }
|
---|
237 | } else if (nextUti == -2.0) {
|
---|
238 | val = est_mu + (cTime - est_mt) * (est_u - est_mu) / (est_t - est_mt);
|
---|
239 | } else if (nextUti == -1.0) {
|
---|
240 | val = getOriU(cTime);
|
---|
241 | }
|
---|
242 |
|
---|
243 | laTime = mBidHistory.getMCtime() * maxTime;
|
---|
244 | if (cTime * maxTime - laTime > 1.5 || cTime > 0.995) {
|
---|
245 | dval = val * Math.pow(discount, cTime);
|
---|
246 |
|
---|
247 | if (opponentModel instanceof NoModel) {
|
---|
248 | bid = genRanBid(dval * lower, dval * upper);
|
---|
249 | } else {
|
---|
250 | Range range = new Range(dval * lower, dval * upper);
|
---|
251 | bid = omStrategy.getBid(outcomespace, range).getBid();
|
---|
252 | }
|
---|
253 |
|
---|
254 | // System.out.println("Decoupled genRandomBid3: " + bid);
|
---|
255 |
|
---|
256 | } else {
|
---|
257 | if (val * lower * adp >= maxBidU) {
|
---|
258 | bid = maxBid;
|
---|
259 | // System.out.println("Decoupled return maxBid3");
|
---|
260 | } else {
|
---|
261 | dval = adp * val * Math.pow(discount, cTime);
|
---|
262 | if (opponentModel instanceof NoModel) {
|
---|
263 | bid = genRanBid(dval * lower, dval * upper);
|
---|
264 | } else {
|
---|
265 | Range range = new Range(dval * lower, dval * upper);
|
---|
266 | bid = omStrategy.getBid(outcomespace, range).getBid();
|
---|
267 | }
|
---|
268 | // System.out.println("Decoupled genRandomBid4: " + bid);
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | if (bid == null)
|
---|
273 | bid = mBidHistory.getMyLastBid();
|
---|
274 |
|
---|
275 | if (getUtility(mBidHistory.bestOppBid) >= getUtility(bid)) {
|
---|
276 | // System.out.println("Decoupled bestOppBid1: " +
|
---|
277 | // mBidHistory.bestOppBid);
|
---|
278 | return mBidHistory.bestOppBid;
|
---|
279 | }
|
---|
280 |
|
---|
281 | if (cTime > 0.999 && getUtility(mBidHistory.bestOppBid) > MINIMUM_UTILITY * Math.pow(discount, cTime)) {
|
---|
282 | // System.out.println("Decoupled bestOppBid2: " +
|
---|
283 | // mBidHistory.bestOppBid);
|
---|
284 |
|
---|
285 | return mBidHistory.bestOppBid;
|
---|
286 | }
|
---|
287 |
|
---|
288 | return bid;
|
---|
289 | }
|
---|
290 |
|
---|
291 | private double getOriU(double t) {
|
---|
292 | double exp = 1D;
|
---|
293 | double maxUtil = maxBidU;
|
---|
294 | double minUtil = 0.69; // 0.7
|
---|
295 | if (minUtil < MINIMUM_UTILITY)
|
---|
296 | minUtil = MINIMUM_UTILITY * 1.05;
|
---|
297 |
|
---|
298 | double e1 = 0.033;
|
---|
299 | double e2 = 0.04;
|
---|
300 | double time = t;
|
---|
301 | double tMax = maxBidU;
|
---|
302 | double tMin = MINIMUM_UTILITY * 1.05; // Math.pow(discount, 0.33);
|
---|
303 |
|
---|
304 | if (discount >= discountThreshold) {
|
---|
305 | exp = minUtil + (1 - Math.pow(time, 1D / e1)) * (maxUtil - minUtil);
|
---|
306 | } else {
|
---|
307 | tMax = Math.pow(discount, 0.2);
|
---|
308 | exp = tMin + (1 - Math.pow(time, 1D / e2)) * (tMax - tMin);
|
---|
309 | }
|
---|
310 |
|
---|
311 | return exp;
|
---|
312 | }
|
---|
313 |
|
---|
314 | private double getPre() {
|
---|
315 | int len = 3;
|
---|
316 | double[] pmaxList = mBidHistory.getTimeBlockList();
|
---|
317 | int lenA = (int) Math.floor(cTime * 100); // don't count the current
|
---|
318 | // second as it is not
|
---|
319 | // complete
|
---|
320 | if (lenA < len) {
|
---|
321 | return -1.0;
|
---|
322 | }
|
---|
323 |
|
---|
324 | double[] maxList = new double[lenA];
|
---|
325 | double[] ma = new double[lenA];
|
---|
326 | double[] res = new double[lenA];
|
---|
327 | double exma = 0.0;
|
---|
328 |
|
---|
329 | for (int i = 0; i < lenA; i++) {
|
---|
330 | maxList[i] = pmaxList[i];
|
---|
331 | }
|
---|
332 |
|
---|
333 | for (int i = 0; i < len - 1; i++) {
|
---|
334 | ma[i] = 0;
|
---|
335 | }
|
---|
336 |
|
---|
337 | for (int i = len - 1; i < lenA; i++) {
|
---|
338 | ma[i] = (maxList[i] + maxList[i - 1] + maxList[i - 2]) / 3.0;
|
---|
339 | }
|
---|
340 |
|
---|
341 | for (int i = 0; i < lenA; i++) {
|
---|
342 | res[i] = maxList[i] - ma[i];
|
---|
343 | }
|
---|
344 |
|
---|
345 | exma = ma[lenA - 1] + avg(res)
|
---|
346 | + std(res) * (1.0 - Math.pow(maxList[lenA - 1], 4)) * (1.3 + 0.66 * Math.pow(1 - cTime * cTime, 0.4));
|
---|
347 |
|
---|
348 | return exma;
|
---|
349 | }
|
---|
350 |
|
---|
351 | public static double sum(double[] arr) {
|
---|
352 | double sum = 0.0;
|
---|
353 | int len = arr.length;
|
---|
354 | for (int i = 0; i < len; i++) {
|
---|
355 | sum += arr[i];
|
---|
356 | }
|
---|
357 | return sum;
|
---|
358 | }
|
---|
359 |
|
---|
360 | public static double avg(double[] arr) {
|
---|
361 | double avg = 0.0;
|
---|
362 | int len = arr.length;
|
---|
363 | avg = sum(arr) / (double) len;
|
---|
364 | return avg;
|
---|
365 | }
|
---|
366 |
|
---|
367 | public static double std(double[] arr) {
|
---|
368 | double std = 0.0;
|
---|
369 | int len = arr.length;
|
---|
370 | double ssum = 0.0;
|
---|
371 | for (int i = 0; i < len; i++) {
|
---|
372 | ssum += arr[i] * arr[i];
|
---|
373 | }
|
---|
374 |
|
---|
375 | std = ((double) len / (double) (len - 1.0)) * (ssum / (double) len - Math.pow(avg(arr), 2));
|
---|
376 | return Math.sqrt(std);
|
---|
377 | }
|
---|
378 |
|
---|
379 | private double getNextUti() {
|
---|
380 | double utiO = getOriU(cTime + timeInt);
|
---|
381 | exma = getPre();
|
---|
382 |
|
---|
383 | if (exma >= 1.0)
|
---|
384 | return -3.0;
|
---|
385 |
|
---|
386 | if (exma > utiO) {
|
---|
387 | est_t = cTime + timeInt;
|
---|
388 | est_u = exma;
|
---|
389 | est_mu = getOriU(cTime);
|
---|
390 | est_mt = cTime;
|
---|
391 | return -2.0;
|
---|
392 | } else {
|
---|
393 | return -1.0;
|
---|
394 | }
|
---|
395 |
|
---|
396 | }
|
---|
397 |
|
---|
398 | private int getMaxPoint(int cur, float ar[]) {
|
---|
399 | int temp = cur;
|
---|
400 |
|
---|
401 | for (int i = cur; i < 99; i++) {
|
---|
402 | if (ar[temp] < ar[i + 1])
|
---|
403 | temp = i + 1;
|
---|
404 | }
|
---|
405 |
|
---|
406 | return temp;
|
---|
407 | }
|
---|
408 |
|
---|
409 | private int getMinPoint(int cur, float ar[]) {
|
---|
410 | int temp = cur;
|
---|
411 |
|
---|
412 | for (int i = cur; i < 99; i++) {
|
---|
413 | if (ar[temp] > ar[i + 1])
|
---|
414 | temp = i + 1;
|
---|
415 | }
|
---|
416 |
|
---|
417 | return temp;
|
---|
418 | }
|
---|
419 |
|
---|
420 | private Bid genRanBid(double min, double max) {
|
---|
421 | HashMap<Integer, Value> values = new HashMap<Integer, Value>(); // pairs
|
---|
422 | // <issuenumber,chosen
|
---|
423 | // value
|
---|
424 | // string>
|
---|
425 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
426 | int counter = 0;
|
---|
427 | int limit = 1000;
|
---|
428 | double fmax = max;
|
---|
429 |
|
---|
430 | Bid bid = null;
|
---|
431 | do {
|
---|
432 | for (Issue lIssue : issues) {
|
---|
433 | switch (lIssue.getType()) {
|
---|
434 | case DISCRETE:
|
---|
435 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
436 | int optionIndex = randomnr.nextInt(lIssueDiscrete.getNumberOfValues());
|
---|
437 | values.put(lIssue.getNumber(), lIssueDiscrete.getValue(optionIndex));
|
---|
438 | break;
|
---|
439 | case REAL:
|
---|
440 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
441 | int optionInd = randomnr.nextInt(lIssueReal.getNumberOfDiscretizationSteps() - 1);
|
---|
442 | values.put(lIssueReal.getNumber(),
|
---|
443 | new ValueReal(lIssueReal.getLowerBound()
|
---|
444 | + (lIssueReal.getUpperBound() - lIssueReal.getLowerBound()) * (double) (optionInd)
|
---|
445 | / (double) (lIssueReal.getNumberOfDiscretizationSteps())));
|
---|
446 | break;
|
---|
447 | case INTEGER:
|
---|
448 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
449 | int optionIndex2 = lIssueInteger.getLowerBound()
|
---|
450 | + randomnr.nextInt(lIssueInteger.getUpperBound() - lIssueInteger.getLowerBound());
|
---|
451 | values.put(lIssueInteger.getNumber(), new ValueInteger(optionIndex2));
|
---|
452 | break;
|
---|
453 | default:
|
---|
454 | //
|
---|
455 | }
|
---|
456 | }
|
---|
457 |
|
---|
458 | try {
|
---|
459 | bid = new Bid(utilitySpace.getDomain(), values);
|
---|
460 | } catch (Exception e) {
|
---|
461 | System.out.println("error in generating random bids");
|
---|
462 | }
|
---|
463 |
|
---|
464 | counter++;
|
---|
465 | if (counter > limit) {
|
---|
466 | limit = limit + 500;
|
---|
467 | fmax += 0.005;
|
---|
468 | // return mBidHistory.getMyLastBid();
|
---|
469 | }
|
---|
470 |
|
---|
471 | if (counter > 4000)
|
---|
472 | return mBidHistory.getMyLastBid();
|
---|
473 |
|
---|
474 | } while (getUtility(bid) < min || getUtility(bid) > fmax);
|
---|
475 |
|
---|
476 | return bid;
|
---|
477 | }
|
---|
478 |
|
---|
479 | public double getUtility(Bid bid) {
|
---|
480 | return utilitySpace.getUtilityWithDiscount(bid, negotiationSession.getTimeline());
|
---|
481 | }
|
---|
482 |
|
---|
483 | @Override
|
---|
484 | public String getName() {
|
---|
485 | return "2012 - OMACagent";
|
---|
486 | }
|
---|
487 |
|
---|
488 | }
|
---|