source: src/main/java/agents/anac/y2011/Gahboninho/IssueManager.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 23.1 KB
Line 
1package agents.anac.y2011.Gahboninho;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.Iterator;
6import java.util.Map.Entry;
7
8import genius.core.Bid;
9import genius.core.issue.ISSUETYPE;
10import genius.core.issue.Issue;
11import genius.core.issue.IssueDiscrete;
12import genius.core.issue.IssueInteger;
13import genius.core.issue.IssueReal;
14import genius.core.issue.Value;
15import genius.core.issue.ValueDiscrete;
16import genius.core.issue.ValueInteger;
17import genius.core.issue.ValueReal;
18import genius.core.timeline.TimeLineInfo;
19import genius.core.utility.AdditiveUtilitySpace;
20
21import java.util.Random;
22import java.util.TreeMap;
23
24public class IssueManager {
25 // world state :
26 TimeLineInfo T;
27 AdditiveUtilitySpace US;
28 int TotalBiddingPossibilities; // amount of all possible bidsd
29 // oponent properties :
30 Bid OpponentBestBid; // the first bid opponent gave us
31 double MyUtilityOnOpponentBestBid = 0;
32 double Noise = 0.4; // 0 to 1 - Tells us how varied the opponent's bids are,
33 // lately
34 // My State:
35 double NextOfferUtility = 1;
36 boolean FirstOfferGiven = false;
37 TreeMap<Double, Bid> Bids;
38 HashMap<Issue, ArrayList<Value>> relevantValuesPerIssue = new HashMap<Issue, ArrayList<Value>>();
39 Bid maxBid = null;
40 final int PlayerCount = 8; // if player count is 10, then we
41 OpponnentModel OM;
42
43 private final boolean TEST_EQUIVALENCE = false;
44
45 private Random random100;
46 private Random random200;
47 private Random random300;
48 private Random random400;
49
50 boolean InFrenzy = false;
51
52 public Bid GetMaxBidWithNoCost() throws Exception {
53 Bid maxBid = this.US.getDomain().getRandomBid(random100);
54 Bid justBidding = this.US.getDomain().getRandomBid(random100);
55
56 for (Issue issue : this.US.getDomain().getIssues()) {
57 double tmpUtil;
58 double maxUtil = 0;
59 int maxUtilValIndex = 0;
60
61 switch (issue.getType()) {
62
63 case INTEGER:
64
65 IssueInteger integerIssue = (IssueInteger) issue;
66
67 justBidding = justBidding.putValue(issue.getNumber(), new ValueInteger(integerIssue.getUpperBound()));
68 maxUtil = US.getUtility(justBidding);
69
70 justBidding = justBidding.putValue(issue.getNumber(), new ValueInteger(integerIssue.getLowerBound()));
71 tmpUtil = US.getUtility(justBidding);
72
73 if (maxUtil > tmpUtil)
74 maxBid = maxBid.putValue(issue.getNumber(), new ValueInteger(integerIssue.getUpperBound()));
75 else
76 maxBid = maxBid.putValue(issue.getNumber(), new ValueInteger(integerIssue.getLowerBound()));
77
78 break;
79
80 case REAL:
81
82 IssueReal realIssue = (IssueReal) issue;
83
84 justBidding = justBidding.putValue(issue.getNumber(), new ValueReal(realIssue.getUpperBound()));
85 maxUtil = US.getUtility(justBidding);
86
87 justBidding = justBidding.putValue(issue.getNumber(), new ValueReal(realIssue.getLowerBound()));
88 tmpUtil = US.getUtility(justBidding);
89
90 if (maxUtil > tmpUtil)
91 maxBid = maxBid.putValue(issue.getNumber(), new ValueReal(realIssue.getUpperBound()));
92 else
93 maxBid = maxBid.putValue(issue.getNumber(), new ValueReal(realIssue.getLowerBound()));
94
95 break;
96 case DISCRETE:
97 IssueDiscrete discreteIssue = (IssueDiscrete) issue;
98 int size = discreteIssue.getNumberOfValues();
99 for (int i = 0; i < size; i++) {
100 justBidding = justBidding.putValue(issue.getNumber(), discreteIssue.getValue(i));
101 tmpUtil = US.getUtility(justBidding);
102 if (tmpUtil > maxUtil) {
103 maxUtilValIndex = i;
104 maxUtil = tmpUtil;
105 }
106 }
107
108 maxBid = maxBid.putValue(issue.getNumber(), discreteIssue.getValue(maxUtilValIndex));
109 break;
110 }
111 }
112
113 return maxBid;
114 }
115
116 // fill utility-to-bid map here:
117 public IssueManager(AdditiveUtilitySpace US, TimeLineInfo T, OpponnentModel om) {
118 if (TEST_EQUIVALENCE) {
119 random100 = new Random(100);
120 random200 = new Random(200);
121 random300 = new Random(300);
122 random400 = new Random(400);
123 } else {
124 random100 = new Random();
125 random200 = new Random();
126 random300 = new Random();
127 random400 = new Random();
128 }
129
130 this.T = T;
131 this.US = US;
132 this.OM = om;
133 try {
134 maxBid = GetMaxBidWithNoCost(); // try sparing the brute force
135 double maxBidUtil = US.getUtility(maxBid);
136 if (maxBidUtil == 0) // in case cost comes into play
137 this.maxBid = this.US.getMaxUtilityBid(); // use only if the
138 // simpler function
139 // won't work
140
141 } catch (Exception e) {
142 try {
143 this.maxBid = this.US.getMaxUtilityBid();
144 } catch (Exception e2) {
145 }
146 }
147
148 Bids = new TreeMap<Double, Bid>();
149
150 for (int i = 0; i < US.getDomain().getIssues().size(); ++i) {
151 Issue I = (Issue) US.getDomain().getIssues().get(i);
152 if (I.getType() == ISSUETYPE.DISCRETE) {
153 IssueDiscrete ID = (IssueDiscrete) I;
154
155 DifferentValuesCountPerIssueNum.put(ID.getNumber(), ID.getNumberOfValues());
156 OutgoingValueAppeareancesByIssueNum.put(ID.getNumber(), new TreeMap<String, Integer>());
157 } else if (I.getType() == ISSUETYPE.REAL) {
158 DifferentValuesCountPerIssueNum.put(I.getNumber(), (int) DiscretisationSteps);
159 OutgoingValueAppeareancesByIssueNum.put(I.getNumber(), new TreeMap<String, Integer>());
160 } else if (I.getType() == ISSUETYPE.INTEGER) {
161 IssueInteger II = (IssueInteger) I;
162 DifferentValuesCountPerIssueNum.put(I.getNumber(),
163 Math.min((int) DiscretisationSteps, II.getUpperBound() - II.getLowerBound() + 1));
164
165 OutgoingValueAppeareancesByIssueNum.put(I.getNumber(), new TreeMap<String, Integer>());
166 }
167 }
168 ClearIncommingStatistics();
169 }
170
171 void ClearIncommingStatistics() {
172 for (Issue I : US.getDomain().getIssues())
173 IncomingValueAppeareancesByIssueNum.put(I.getNumber(), new TreeMap<String, Integer>());
174
175 }
176
177 public Bid getMaxBid() {
178 return maxBid;
179 }
180
181 public double GetDiscountFactor() {
182 if (US.getDiscountFactor() <= 0.001 || US.getDiscountFactor() > 1)
183 return 1;
184 return US.getDiscountFactor();
185 }
186
187 private void addPossibleValue(Issue issue, Value val) {
188 if (!this.relevantValuesPerIssue.containsKey(issue)) {
189 this.relevantValuesPerIssue.put(issue, new ArrayList<Value>());
190 }
191
192 int randIndex = 0;
193 if (this.relevantValuesPerIssue.get(issue).size() > 0)
194 randIndex = Math.abs(random200.nextInt()) % this.relevantValuesPerIssue.get(issue).size();
195 this.relevantValuesPerIssue.get(issue).add(randIndex, val);
196 }
197
198 final double DiscretisationSteps = 20; // minimum 2
199
200 private void buildIssueValues(Bid firstOppBid) throws Exception {
201
202 Bid justBidding = this.US.getDomain().getRandomBid(random300);
203
204 for (Issue issue : this.US.getDomain().getIssues()) {
205 int AddedValues = 0;
206
207 justBidding = justBidding.putValue(issue.getNumber(), firstOppBid.getValue(issue.getNumber()));
208 double utilityWithOpp = this.US.getEvaluation(issue.getNumber(), justBidding);
209
210 switch (issue.getType()) {
211 case INTEGER:
212 IssueInteger intIssue = (IssueInteger) issue;
213
214 int iStep;
215 int totalSteps = (int) Math.min(DiscretisationSteps - 1,
216 intIssue.getUpperBound() - intIssue.getLowerBound());
217 iStep = Math.max(1, (int) ((intIssue.getUpperBound() - intIssue.getLowerBound()) / totalSteps));
218
219 for (int i = intIssue.getLowerBound(); i <= intIssue.getUpperBound(); i += iStep) {
220 justBidding = justBidding.putValue(issue.getNumber(), new ValueInteger(i));
221 double utilityWithCurrent = this.US.getEvaluation(issue.getNumber(), justBidding);
222
223 // Only see it as a possible value if it is better for us
224 // than the opponent offer
225 if (utilityWithCurrent >= utilityWithOpp) {
226 this.addPossibleValue(issue, new ValueInteger(i));
227 }
228 }
229
230 AddedValues += Math.abs(intIssue.getUpperBound() - intIssue.getLowerBound());
231 break;
232 case REAL:
233
234 IssueReal realIssue = (IssueReal) issue;
235 double oneStep = (realIssue.getUpperBound() - realIssue.getLowerBound()) / (DiscretisationSteps - 1);
236 for (double curr = realIssue.getLowerBound(); curr <= realIssue.getUpperBound(); curr += oneStep) {
237 justBidding = justBidding.putValue(issue.getNumber(), new ValueReal(curr));
238 double utilityWithCurrent = this.US.getEvaluation(issue.getNumber(), justBidding);
239 // Only see it as a possible value if it is better for us
240 // than the opponent offer
241 if (utilityWithCurrent >= utilityWithOpp) {
242 this.addPossibleValue(issue, new ValueReal(curr));
243 AddedValues += 1000;
244 }
245 }
246
247 break;
248 case DISCRETE:
249 IssueDiscrete discreteIssue = (IssueDiscrete) issue;
250 int size = discreteIssue.getNumberOfValues();
251 for (int i = 0; i < size; i++) {
252 ValueDiscrete curr = discreteIssue.getValue(i);
253 justBidding = justBidding.putValue(issue.getNumber(), curr);
254 double utilityWithCurrent = this.US.getEvaluation(issue.getNumber(), justBidding);
255 // Only see it as a possible value if it is better for us
256 // than the opponent offer
257 if (utilityWithCurrent >= utilityWithOpp) {
258 this.addPossibleValue(issue, curr);
259 AddedValues += 1;
260 }
261
262 }
263 break;
264 }
265
266 EffectiveDomainBids *= AddedValues;
267 }
268 }
269
270 Double BidsCreationTime = 0.0;
271 double EffectiveDomainBids = 1;
272
273 public void learnBids(Bid firstOppBid) throws Exception {
274 this.buildIssueValues(firstOppBid);
275
276 double startTime = T.getTime();
277
278 // very hard to deal with hash map, so copy it to arraylist:
279 Iterator<Entry<Issue, ArrayList<Value>>> MyIssueIterator = relevantValuesPerIssue.entrySet().iterator();
280 while (MyIssueIterator.hasNext())
281 IssueEntries.add(MyIssueIterator.next());
282
283 // if there is a discount factor, don't take your time searching for
284 // bids
285 BuildBid(new HashMap<Integer, Value>(), 0, 0.05 * Math.pow(GetDiscountFactor(), 0.6) + startTime);
286 BidsCreationTime = T.getTime() - startTime;
287
288 // if there are about 5000 turns for the opponent, I expect him to be
289 // able to
290 // give a good bid every few turns
291 NoiseDecreaseRate = 0.01 * EffectiveDomainBids / (400);
292 NoiseDecreaseRate = Math.min(0.015, NoiseDecreaseRate); // beware of a
293 // too large
294 // rate
295 NoiseDecreaseRate = Math.max(0.003, NoiseDecreaseRate);
296
297 }
298
299 private ArrayList<Entry<Issue, ArrayList<Value>>> IssueEntries = new ArrayList<Entry<Issue, ArrayList<Value>>>();
300
301 int UtilityCollisionsLeft = 200000;
302
303 private void BuildBid(HashMap<Integer, Value> B, int EntrySetIndex, double EndTime) {
304 // TODO : build only bids with at least X util.
305 // after some time, when we need lower utilities, re-build bid map, only
306 // this time consider
307 // opponent's preferences: just build a method that tells us if one bid
308 // is preferrable (from opponent's point of view)
309 // and if the less preferable one gives us less utility than the other
310 // bid, simply remove the bid from map
311
312 if (T.getTime() < EndTime) {
313 if (EntrySetIndex < IssueEntries.size()) {
314 Entry<Issue, ArrayList<Value>> currentEntry = IssueEntries.get(EntrySetIndex);
315 for (Value v : currentEntry.getValue()) {
316 B.put(currentEntry.getKey().getNumber(), v);
317 BuildBid(B, EntrySetIndex + 1, EndTime);
318 }
319 } else {
320 try {
321
322 Bid newBid = new Bid(US.getDomain(), new HashMap<Integer, Value>(B));
323
324 double BidUtil = US.getUtility(newBid);
325
326 while (UtilityCollisionsLeft > 0 && Bids.containsKey(BidUtil)) {
327 --UtilityCollisionsLeft;
328 BidUtil -= 0.002 / (random400.nextInt() % 9999999);
329 }
330
331 Bids.put(BidUtil, newBid);
332 } catch (Exception e) {
333 e.printStackTrace();
334 }
335 }
336
337 }
338 }
339
340 public double CompromosingFactor = 0.95;
341 // returns the minimum utility we want in the next offer we send
342
343 double TimeDiffStart = -1;
344 double TimeDiffEnd = -1;
345 double RoundCountBeforePanic = 1;
346
347 double PrevRecommendation = 1;
348 double MaximalUtilityDecreaseRate = 0.0009;
349
350 public double GetNextRecommendedOfferUtility() {
351 if (FirstOfferGiven == false) {
352 FirstOfferGiven = true;
353 return 1;
354 }
355
356 double Time = T.getTime();
357 double Min = Math.pow(GetDiscountFactor(), 2 * Time);
358 double Max = Min * (1 + 6 * Noise * Math.pow(GetDiscountFactor(), 5));
359
360 if (Time < 0.85 * GetDiscountFactor())
361 Min *= Math.max(BestEverOpponentBidUtil, 0.9125);
362 else if (Time <= 0.92 * GetDiscountFactor()) {
363 CompromosingFactor = 0.94;
364 Min *= Math.max(BestEverOpponentBidUtil, 0.84); // never ever accept
365 // an offer with
366 // less than that
367 // utility
368
369 Max /= Min; // slow down the decreasing
370
371 } else if (Time <= 0.94 * GetDiscountFactor()) {
372 CompromosingFactor = 0.93;
373 Min *= Math.max(BestEverOpponentBidUtil, 0.775);
374 Max /= Min;
375 } else if (Time <= 0.985 * Min && (BestEverOpponentBidUtil <= 2 * (1.0 / PlayerCount) || // never
376 // accept
377 // an
378 // offer
379 // with
380 // less
381 // utility
382 // than
383 // that
384 Time <= (1 - 3 * (TimeDiffEnd - TimeDiffStart) / RoundCountBeforePanic))) {
385 CompromosingFactor = 0.91;
386 MaximalUtilityDecreaseRate = 0.001;
387
388 Min *= Math.max(BestEverOpponentBidUtil, 0.7);
389 Max /= Min;
390
391 TimeDiffEnd = TimeDiffStart = Time;
392 } else if (Time <= 0.9996 && (BestEverOpponentBidUtil <= 2 * (1.0 / PlayerCount) || // never
393 // accept
394 // an
395 // offer
396 // with
397 // less
398 // utility
399 // than
400 // that
401 Time <= (1 - 3 * (TimeDiffEnd - TimeDiffStart) / RoundCountBeforePanic))) // until
402 // last
403 // few
404 // rounds
405 {
406 TimeDiffEnd = Time;
407 ++RoundCountBeforePanic;
408
409 MaximalUtilityDecreaseRate = 0.001 + 0.01 * (Time - 0.985) / (0.015);
410
411 // MaximalUtilityDecreaseRate = 0.0018;
412 // MaximalUtilityDecreaseRate = 0.0009;
413
414 if (3 * (1.0 / PlayerCount) > BestEverOpponentBidUtil) {
415 Min *= 3.5 * (1.0 / PlayerCount);
416 CompromosingFactor = 0.8;
417 } else {
418 Min *= BestEverOpponentBidUtil;
419 CompromosingFactor = 0.95;
420 }
421
422 Max /= Min;
423 } else {
424
425 CompromosingFactor = 0.92;
426
427 // as low as I can go!
428 if (BestEverOpponentBidUtil < 2 * (1.0 / PlayerCount)) {
429 Min = 2 * (1.0 / PlayerCount); // 0.25 if 8 players
430 Max = 1;
431 } else {
432 Max = Min = BestEverOpponentBidUtil;
433 InFrenzy = true;
434 }
435 MaximalUtilityDecreaseRate = 1;
436 }
437
438 // the more eager the opponent is to settle, the slower we give up our
439 // utility.
440 // the higher the discount factor loss, the faster we give it up
441
442 Max = Math.max(Max, Min);
443 NextOfferUtility = Math.min(1, Max - (Max - Min) * T.getTime());
444
445 // slow down the change:
446 if (NextOfferUtility + MaximalUtilityDecreaseRate < PrevRecommendation)
447 NextOfferUtility = PrevRecommendation - MaximalUtilityDecreaseRate;
448 else if (NextOfferUtility - 0.005 > PrevRecommendation)
449 NextOfferUtility = PrevRecommendation + 0.005;
450
451 PrevRecommendation = NextOfferUtility;
452 return NextOfferUtility;
453 }
454
455 public double GetMinimumUtilityToAccept() // changes over time
456 {
457 double util1 = CompromosingFactor;
458 double util2 = GetNextRecommendedOfferUtility();
459 return util1 * util2;
460 }
461
462 int CountdownToNoiseReestimation;
463
464 String EstimateValue(Issue I, Value v) throws Exception {
465 switch (I.getType()) {
466 case DISCRETE:
467 ValueDiscrete DV = (ValueDiscrete) v;
468 return DV.getValue();
469 case INTEGER:
470 int ValueIndex = 0;
471 IssueInteger II = (IssueInteger) I;
472 ValueInteger IV = (ValueInteger) v;
473 double Step = II.getUpperBound() - II.getLowerBound();
474 if (Step != 0) {
475 int totalSteps = (int) Math.min(DiscretisationSteps, II.getUpperBound() - II.getLowerBound() + 1);
476 Step /= totalSteps;
477 ValueIndex = (int) (IV.getValue() / Step);
478 }
479 return String.valueOf(ValueIndex);
480 case REAL:
481 IssueReal RI = (IssueReal) I;
482 ValueReal RV = (ValueReal) v;
483 double StepR = RI.getUpperBound() - RI.getLowerBound();
484 ValueIndex = 0;
485 if (StepR != 0) {
486 StepR /= DiscretisationSteps;
487 ValueIndex = (int) (RV.getValue() / StepR);
488 }
489 return String.valueOf(ValueIndex);
490 }
491
492 throw new Exception("illegal issue");
493 }
494
495 TreeMap<Integer, TreeMap<String/* value.ToString() */, Integer>> IncomingValueAppeareancesByIssueNum = new TreeMap<Integer, TreeMap<String, Integer>>(); // tells
496 // how
497 // many
498 // times
499 // each
500 // value
501 // has
502 // appeared
503 // in
504 // all
505 // incoming
506 // bids
507 TreeMap<Integer, TreeMap<String/* value.ToString() */, Integer>> OutgoingValueAppeareancesByIssueNum = new TreeMap<Integer, TreeMap<String, Integer>>(); // tells
508 // how
509 // many
510 // times
511 // each
512 // value
513 // has
514 // appeared
515 // in
516 // all
517 // incoming
518 // bids
519 TreeMap<Integer, Integer> DifferentValuesCountPerIssueNum = new TreeMap<Integer, Integer>(); // tells
520 // how
521 // many
522 // different
523 // values
524 // are
525 // per
526 // Issue
527 int CountdownToStatisticsRefreshing = 20; // when hits zero, recalculate
528 // AverageDistance and reset
529 // Noise
530 double PreviousAverageDistance = 0.2; // 0 to 1
531 double PreviousCountdownOpponentBestBidUtil = 1;
532 double BestEverOpponentBidUtil = 0;
533 double WorstOpponentBidEvaluatedOpponentUtil = 1;
534 double PrevWorstOpponentBidEvaluatedOpponentUtil = 1;
535 double PrevRoundWorstOpponentBidEvaluatedOpponentUtil = 1;
536 Bid BestEverOpponentBid = null;
537
538 int OutgoingBidsCount = 0;
539
540 void AddMyBidToStatistics(Bid OutgoingBid) throws Exception {
541 ++OutgoingBidsCount;
542 for (Issue I : US.getDomain().getIssues()) {
543 String bidValueEstimation = EstimateValue(I, OutgoingBid.getValue(I.getNumber()));
544 if (OutgoingValueAppeareancesByIssueNum.get(I.getNumber()).containsKey(bidValueEstimation)) {
545 OutgoingValueAppeareancesByIssueNum.get(I.getNumber()).put(bidValueEstimation,
546 OutgoingValueAppeareancesByIssueNum.get(I.getNumber()).get(bidValueEstimation) + 1);
547 } else {
548 OutgoingValueAppeareancesByIssueNum.get(I.getNumber()).put(bidValueEstimation, 1);
549 }
550 }
551 }
552
553 double NoiseDecreaseRate = 0.01;
554 final int CountdownLength = 20;
555
556 // receiveMessage noise here
557 public void ProcessOpponentBid(Bid IncomingBid) throws Exception {
558 if (CountdownToStatisticsRefreshing > 0) {
559 if (US.getUtility(IncomingBid) > BestEverOpponentBidUtil) {
560 BestEverOpponentBidUtil = US.getUtility(IncomingBid);
561 BestEverOpponentBid = IncomingBid;
562 Bids.put(BestEverOpponentBidUtil, BestEverOpponentBid);
563 }
564
565 double getopUtil = OM.EvaluateOpponentUtility(IncomingBid);
566
567 if (PrevRoundWorstOpponentBidEvaluatedOpponentUtil < getopUtil)
568 PrevRoundWorstOpponentBidEvaluatedOpponentUtil = getopUtil;
569 if (WorstOpponentBidEvaluatedOpponentUtil > getopUtil) {
570 WorstOpponentBidEvaluatedOpponentUtil = getopUtil;
571
572 }
573
574 --CountdownToStatisticsRefreshing;
575 for (Issue I : US.getDomain().getIssues()) {
576 String bidValueEstimation = EstimateValue(I, IncomingBid.getValue(I.getNumber()));
577 if (IncomingValueAppeareancesByIssueNum.get(I.getNumber()).containsKey(bidValueEstimation)) {
578 IncomingValueAppeareancesByIssueNum.get(I.getNumber()).put(bidValueEstimation,
579 IncomingValueAppeareancesByIssueNum.get(I.getNumber()).get(bidValueEstimation) + 1);
580 } else {
581 IncomingValueAppeareancesByIssueNum.get(I.getNumber()).put(bidValueEstimation, 1);
582 }
583 }
584 } else {
585 double CurrentSimilarity = 0;
586
587 for (Issue I : US.getDomain().getIssues()) {
588 for (String val : OutgoingValueAppeareancesByIssueNum.get(I.getNumber()).keySet()) {
589 if (IncomingValueAppeareancesByIssueNum.get(I.getNumber()).containsKey(val)) {
590 float outgoingVal = ((float) (OutgoingValueAppeareancesByIssueNum.get(I.getNumber()).get(val)))
591 / OutgoingBidsCount;
592 float incomingVal = (((float) (IncomingValueAppeareancesByIssueNum.get(I.getNumber()).get(val)))
593 / CountdownLength);
594 float diff = outgoingVal - incomingVal;
595 float diffSqr = diff * diff; // 0 to 1
596
597 CurrentSimilarity += (1.0 / US.getDomain().getIssues().size())
598 * (1.0 / DifferentValuesCountPerIssueNum.get(I.getNumber())) * (1 - diffSqr);
599 }
600 }
601 }
602
603 if (CurrentSimilarity > PreviousAverageDistance) {
604 Noise += 0.05; // opponent is trying harder to search
605 } else if (BestEverOpponentBidUtil < PreviousCountdownOpponentBestBidUtil
606 || WorstOpponentBidEvaluatedOpponentUtil < PrevWorstOpponentBidEvaluatedOpponentUtil) {
607 Noise += NoiseDecreaseRate; // Apparently, the opponent just
608 // gave up some of his util
609 } else {
610 Noise -= NoiseDecreaseRate;
611
612 if (PrevRoundWorstOpponentBidEvaluatedOpponentUtil > WorstOpponentBidEvaluatedOpponentUtil * 1.2)
613 Noise -= NoiseDecreaseRate;
614 if (CurrentSimilarity * 1.1 < PreviousAverageDistance)
615 Noise -= NoiseDecreaseRate;
616 }
617 // if (CurrentSimilarity > PreviousAverageDistance ||
618 // BestEverOpponentBidUtil > PreviousCountdownOpponentBestBidUtil)
619 // {
620 // Noise += 0.02;
621 // }
622 // else
623 // {
624 // Noise -= 0.02;
625 // }
626
627 // if (CurrentSimilarity > PreviousAverageDistance ||
628 // BestEverOpponentBidUtil > PreviousCountdownOpponentBestBidUtil)
629 // {
630 // Noise += 0.02;
631 // }
632 // else if (CurrentSimilarity < PreviousAverageDistance &&
633 // BestEverOpponentBidUtil < PreviousCountdownOpponentBestBidUtil)
634 // {
635 // Noise -= 0.06;
636 // }
637 // else
638 // Noise -= 0.005;
639
640 Noise = Math.min(Math.max(Noise, 0), 1);
641 PreviousAverageDistance = CurrentSimilarity;
642 CountdownToStatisticsRefreshing = CountdownLength;
643 PreviousCountdownOpponentBestBidUtil = BestEverOpponentBidUtil;
644 PrevRoundWorstOpponentBidEvaluatedOpponentUtil = 1;
645 PrevWorstOpponentBidEvaluatedOpponentUtil = WorstOpponentBidEvaluatedOpponentUtil;
646 ClearIncommingStatistics();
647 }
648 }
649
650 public Bid GenerateBidWithAtleastUtilityOf(double MinUtility) {
651 Entry<Double, Bid> e = Bids.ceilingEntry(MinUtility);
652 if (e == null) {
653 try {
654 } catch (Exception e1) {
655 e1.printStackTrace();
656 }
657 return this.maxBid;
658 }
659
660 return e.getValue();
661 }
662
663}
Note: See TracBrowser for help on using the repository browser.