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