1 | package agents.anac.y2016.ngent;
|
---|
2 |
|
---|
3 | import java.io.FileOutputStream;
|
---|
4 | import java.io.PrintStream;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.Comparator;
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.util.Iterator;
|
---|
10 | import java.util.LinkedList;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Map;
|
---|
13 | import java.util.Random;
|
---|
14 |
|
---|
15 | import genius.core.AgentID;
|
---|
16 | import genius.core.Bid;
|
---|
17 | import genius.core.BidIterator;
|
---|
18 | import genius.core.actions.Accept;
|
---|
19 | import genius.core.actions.Action;
|
---|
20 | import genius.core.actions.EndNegotiation;
|
---|
21 | import genius.core.actions.Offer;
|
---|
22 | import genius.core.issue.Issue;
|
---|
23 | import genius.core.issue.IssueDiscrete;
|
---|
24 | import genius.core.issue.IssueInteger;
|
---|
25 | import genius.core.issue.IssueReal;
|
---|
26 | import genius.core.issue.Value;
|
---|
27 | import genius.core.issue.ValueDiscrete;
|
---|
28 | import genius.core.issue.ValueInteger;
|
---|
29 | import genius.core.issue.ValueReal;
|
---|
30 | import genius.core.parties.AbstractNegotiationParty;
|
---|
31 | import genius.core.parties.NegotiationInfo;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | *
|
---|
35 | * @author Tom and Tommy
|
---|
36 | *
|
---|
37 | * Ngent: Bidding Method: create 3D Space of bid to find the Nash bid
|
---|
38 | * Only add the issue score using exponential function (Not normalize
|
---|
39 | * each issue score) For nonDF, concedeTime = 0.5 For smallDF, MinU will
|
---|
40 | * be calculated by CUHKAgent's function Turning point exists Using
|
---|
41 | * Max's function to adjust the adaptive minU Max num of bids: 7000 If
|
---|
42 | * domain size > 1000, use log freq. Otherwise, use freq
|
---|
43 | *
|
---|
44 | */
|
---|
45 | public class Ngent extends AbstractNegotiationParty {
|
---|
46 | boolean debug = false;
|
---|
47 |
|
---|
48 | private int round;
|
---|
49 | private final double totalTime = 180;
|
---|
50 | private OpponentBidHistory opponentBidHistory1;
|
---|
51 | private OpponentBidHistory opponentBidHistory2;
|
---|
52 | private double minimumUtilityThreshold;
|
---|
53 | private double avgUtilitythreshold;
|
---|
54 | private double avgConcedeTime;
|
---|
55 | private double MaximumUtility;
|
---|
56 | private int limit;// the maximimum number of trials for each searching range
|
---|
57 | private double numberOfRounds;
|
---|
58 | private double timeLeftBefore;
|
---|
59 | private double timeLeftAfter;
|
---|
60 | private double maximumTimeOfOpponent;
|
---|
61 | private double maximumTimeOfOwn;
|
---|
62 | private double discountingFactor;
|
---|
63 | private double concedeToDiscountingFactor;
|
---|
64 | private double concedeToDiscountingFactor_original;
|
---|
65 | private double minConcedeToDiscountingFactor;
|
---|
66 | private LinkedList<LinkedList<Bid>> bidsBetweenUtility;
|
---|
67 | private double previousToughnessDegree;
|
---|
68 | private boolean concedeToOpponent;
|
---|
69 | private boolean toughAgent; // if we propose a bid that was proposed by the
|
---|
70 | // opponnet, then it should be accepted.
|
---|
71 | private double alpha1;// the larger alpha is, the more tough the agent is.
|
---|
72 | private Bid bid_maximum_utility;// the bid with the maximum utility over the
|
---|
73 | // utility space.
|
---|
74 | private double reservationValue;
|
---|
75 |
|
---|
76 | /* UpdateConcede function's Constant */
|
---|
77 | private double k = 1;
|
---|
78 | private double N = 0;
|
---|
79 | private int FirstTimeInterval;
|
---|
80 | private int SecondTimeInterval;
|
---|
81 | private int ThirdTimeInterval;
|
---|
82 |
|
---|
83 | private double initialConcedeTime;
|
---|
84 | private double initialUtilitythreshold;
|
---|
85 | /* Agent 1 Analysis */
|
---|
86 | private AgentData agentData1;
|
---|
87 | /* Agent 2 Analysis */
|
---|
88 | private AgentData agentData2;
|
---|
89 |
|
---|
90 | private double MinimumUtility;
|
---|
91 | private double adaptiveMinUThreshold;
|
---|
92 | private double finalMinUAgent1 = 0;
|
---|
93 | private double finalMinUAgent2 = 0;
|
---|
94 | private double offeredBidsAvg;
|
---|
95 | private double offeredBidsSD;
|
---|
96 | private int offeredBidsRound;
|
---|
97 | private AgentID partyId;
|
---|
98 | private Action ActionOfOpponent = null;
|
---|
99 | private int NumberofDivisions;
|
---|
100 | private double SpacebetweenDivisions;
|
---|
101 | private int CurrentrangeNumber;
|
---|
102 | private int maximumOfRound;
|
---|
103 | private final int limitValue = 5;// 10;
|
---|
104 | private double delta; // searching range
|
---|
105 | private double concedeTime_original;
|
---|
106 | private double minConcedeTime;
|
---|
107 | private List<Issue> Issues;
|
---|
108 | private Bid bid_minimum_utility;// the bid with the minimum utility over the
|
---|
109 | // utility space.
|
---|
110 | private Bid myLastBid;
|
---|
111 |
|
---|
112 | private HashMap<Bid, Double> bidsUtilityScore;
|
---|
113 | private int size;
|
---|
114 | private double minUtilityUhreshold = 1.1;
|
---|
115 | private int countOpp = 0;
|
---|
116 | private int EachRoundCount = 0;
|
---|
117 | private final int maxNumOfBids = 7000; // the maximum number of bids to be
|
---|
118 | // considered in a round
|
---|
119 | private int largeDomainSize; // the maximum number of bids to be considered
|
---|
120 | // in a round
|
---|
121 | private boolean isInProfile3;
|
---|
122 | private boolean isNeededToMoveProfile3;
|
---|
123 | private double domainSize;
|
---|
124 |
|
---|
125 | PrintStream file, SysOut;
|
---|
126 | String fileName;
|
---|
127 | String string_AddIssueScore;
|
---|
128 | String string_SubtractIssueScore;
|
---|
129 | String string_agentData1Num;
|
---|
130 | String string_agentData2Num;
|
---|
131 |
|
---|
132 | private class AgentData {
|
---|
133 | LinkedList<Double> issueScoreBids;
|
---|
134 | ArrayList<ArrayList<Double>> issueScore;
|
---|
135 | double utility_maximum_from_opponent_Session1;
|
---|
136 | double utility_maximum_from_opponent_Session2;
|
---|
137 | double utility_maximum_from_opponent_Session3;
|
---|
138 | double count;
|
---|
139 | double concedeTime;
|
---|
140 | double oppFirstBidUtility;
|
---|
141 | double concedePartOfdiscountingFactor;
|
---|
142 | double concedePartOfOppBehaviour;
|
---|
143 | double minThreshold;
|
---|
144 | Bid oppFirstBid;
|
---|
145 | boolean startConcede;
|
---|
146 | double relCountUpperBoundMid1;
|
---|
147 | double relCountLowerBoundMid1;
|
---|
148 | double relCountUpperBoundMid2;
|
---|
149 | double relCountLowerBoundMid2;
|
---|
150 | double relStdevUtility;
|
---|
151 | double utility_FirstMaximum;
|
---|
152 | double utility_SecondMaximum;
|
---|
153 | double midPointOfSlopeSessionMax1;
|
---|
154 | double midPointOfSlopeSessionMax2;
|
---|
155 | double slopeOfSlopeOfSessionMax1;
|
---|
156 | double slopeOfSlopeOfSessionMax2;
|
---|
157 | boolean IsOppFirstBid;
|
---|
158 | Bid oppPreviousBid;
|
---|
159 | double MinimumUtility;
|
---|
160 | double utilitythreshold;
|
---|
161 | String agentNum;
|
---|
162 | double maxScore;
|
---|
163 | double avgScore;
|
---|
164 | boolean isReceivedOppFirstBid;
|
---|
165 |
|
---|
166 | private AgentData(double minimumUtility, double initialConcedeTime,
|
---|
167 | double initialUtilitythreshold, String agentNumber) {
|
---|
168 | utility_maximum_from_opponent_Session1 = 0;
|
---|
169 | utility_maximum_from_opponent_Session2 = 0;
|
---|
170 | utility_maximum_from_opponent_Session3 = 0;
|
---|
171 | count = -1;
|
---|
172 | startConcede = false;
|
---|
173 | relStdevUtility = 1;
|
---|
174 | utility_FirstMaximum = 0;
|
---|
175 | utility_SecondMaximum = 0;
|
---|
176 | midPointOfSlopeSessionMax1 = 0;
|
---|
177 | midPointOfSlopeSessionMax2 = 0;
|
---|
178 | slopeOfSlopeOfSessionMax1 = 0;
|
---|
179 | slopeOfSlopeOfSessionMax2 = 0;
|
---|
180 | MinimumUtility = minimumUtility;
|
---|
181 | concedeTime = initialConcedeTime;
|
---|
182 | oppFirstBidUtility = 0;
|
---|
183 | oppFirstBid = null;
|
---|
184 | IsOppFirstBid = true;
|
---|
185 | isReceivedOppFirstBid = false;
|
---|
186 | utilitythreshold = initialUtilitythreshold;
|
---|
187 | minThreshold = 0;
|
---|
188 | agentNum = agentNumber;
|
---|
189 | issueScore = new ArrayList<ArrayList<Double>>();
|
---|
190 | }
|
---|
191 |
|
---|
192 | private boolean GetIsReceivedOppFirstBid() {
|
---|
193 | return isReceivedOppFirstBid;
|
---|
194 | }
|
---|
195 |
|
---|
196 | private void SetIsReceivedOppFirstBid(boolean state) {
|
---|
197 | isReceivedOppFirstBid = state;
|
---|
198 | }
|
---|
199 |
|
---|
200 | private void ChangeIssueScore(Bid bid, String caseName) {
|
---|
201 | try {
|
---|
202 | double addedScore = 0;
|
---|
203 | if (caseName.equals(string_AddIssueScore)) {
|
---|
204 | addedScore = Math.exp(-timeline.getTime());
|
---|
205 | } else {
|
---|
206 | addedScore = -(1 - Math
|
---|
207 | .exp(-timeline.getTime() / discountingFactor * 50));
|
---|
208 | }
|
---|
209 | // if(debug)
|
---|
210 | // {
|
---|
211 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
212 | // System.setOut(file);
|
---|
213 | // System.out.println("bid:" + this.utilitySpace.getUtility(bid)
|
---|
214 | // + ", addedScore:" + addedScore);
|
---|
215 | // }
|
---|
216 | for (Issue lIssue : Issues) {
|
---|
217 | int issueNum = lIssue.getNumber();
|
---|
218 | switch (lIssue.getType()) {
|
---|
219 | case DISCRETE:
|
---|
220 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
221 | ValueDiscrete value = (ValueDiscrete) bid
|
---|
222 | .getValue(lIssue.getNumber());
|
---|
223 | int index = lIssueDiscrete.getValueIndex(value);
|
---|
224 | issueScore.get(issueNum - 1).set(index,
|
---|
225 | issueScore.get(issueNum - 1).get(index)
|
---|
226 | + addedScore);
|
---|
227 | break;
|
---|
228 | case REAL:
|
---|
229 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
230 | ValueReal valueReal = (ValueReal) bid
|
---|
231 | .getValue(lIssue.getNumber());
|
---|
232 | int indexReal = (int) ((valueReal.getValue()
|
---|
233 | - lIssueReal.getLowerBound())
|
---|
234 | / (lIssueReal.getUpperBound()
|
---|
235 | - lIssueReal.getLowerBound())
|
---|
236 | * lIssueReal.getNumberOfDiscretizationSteps());
|
---|
237 | issueScore.get(issueNum - 1).set(indexReal,
|
---|
238 | issueScore.get(issueNum - 1).get(indexReal)
|
---|
239 | + addedScore);
|
---|
240 | break;
|
---|
241 | case INTEGER:
|
---|
242 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
243 | ValueInteger valueInteger = (ValueInteger) bid
|
---|
244 | .getValue(lIssue.getNumber());
|
---|
245 | int indexInteger = valueInteger.getValue();
|
---|
246 | issueScore.get(issueNum - 1).set(indexInteger,
|
---|
247 | issueScore.get(issueNum - 1).get(indexInteger)
|
---|
248 | + addedScore);
|
---|
249 | break;
|
---|
250 | default:
|
---|
251 | throw new Exception("issue type " + lIssue.getType()
|
---|
252 | + " not supported");
|
---|
253 | }
|
---|
254 | }
|
---|
255 | } catch (Exception e) {
|
---|
256 | System.out.println(e.getMessage()
|
---|
257 | + "exception in method changeIssueScore");
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | private double calculateScoreValue(Bid Bid1) {
|
---|
262 | double score = 0;
|
---|
263 | try {
|
---|
264 | for (Issue Issue1 : Issues) {
|
---|
265 | int issueNum = Issue1.getNumber();
|
---|
266 | switch (Issue1.getType()) {
|
---|
267 | case DISCRETE:
|
---|
268 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) Issue1;
|
---|
269 | ValueDiscrete value1 = (ValueDiscrete) Bid1
|
---|
270 | .getValue(issueNum);
|
---|
271 | int index = lIssueDiscrete.getValueIndex(value1);
|
---|
272 | if (domainSize > largeDomainSize) {
|
---|
273 | score += Math.log(issueScore
|
---|
274 | .get(lIssueDiscrete.getNumber() - 1)
|
---|
275 | .get(index));
|
---|
276 | } else {
|
---|
277 | score += issueScore
|
---|
278 | .get(lIssueDiscrete.getNumber() - 1)
|
---|
279 | .get(index);
|
---|
280 | }
|
---|
281 | break;
|
---|
282 |
|
---|
283 | case REAL:
|
---|
284 | IssueReal lIssueReal = (IssueReal) Issue1;
|
---|
285 | ValueReal valueReal = (ValueReal) Bid1
|
---|
286 | .getValue(issueNum);
|
---|
287 | int indexReal = (int) ((valueReal.getValue()
|
---|
288 | - lIssueReal.getLowerBound())
|
---|
289 | / (lIssueReal.getUpperBound()
|
---|
290 | - lIssueReal.getLowerBound())
|
---|
291 | * lIssueReal.getNumberOfDiscretizationSteps());
|
---|
292 | if (domainSize > largeDomainSize) {
|
---|
293 | score += Math.log(
|
---|
294 | issueScore.get(lIssueReal.getNumber() - 1)
|
---|
295 | .get(indexReal));
|
---|
296 | } else {
|
---|
297 | score += issueScore.get(lIssueReal.getNumber() - 1)
|
---|
298 | .get(indexReal);
|
---|
299 | }
|
---|
300 | break;
|
---|
301 | case INTEGER:
|
---|
302 | IssueInteger lIssueInteger = (IssueInteger) Issue1;
|
---|
303 | ValueInteger valueInteger = (ValueInteger) Bid1
|
---|
304 | .getValue(issueNum);
|
---|
305 | int indexInteger = valueInteger.getValue();
|
---|
306 | if (domainSize > largeDomainSize) {
|
---|
307 | score += Math.log(issueScore
|
---|
308 | .get(lIssueInteger.getNumber() - 1)
|
---|
309 | .get(indexInteger));
|
---|
310 | } else {
|
---|
311 | score += issueScore
|
---|
312 | .get(lIssueInteger.getNumber() - 1)
|
---|
313 | .get(indexInteger);
|
---|
314 | }
|
---|
315 | break;
|
---|
316 | }
|
---|
317 | }
|
---|
318 | // if(debug)
|
---|
319 | // {
|
---|
320 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
321 | // System.setOut(file);
|
---|
322 | // System.out.println("Bid:" +
|
---|
323 | // this.utilitySpace.getUtility(Bid1) +
|
---|
324 | // ", NotNormalized IssueScore:" + score);
|
---|
325 | // }
|
---|
326 | } catch (Exception e) {
|
---|
327 | System.out.println(e.getMessage()
|
---|
328 | + " Exception in method calculateScoreValue");
|
---|
329 | return 0;
|
---|
330 | }
|
---|
331 | return score;
|
---|
332 | }
|
---|
333 |
|
---|
334 | private void calculateBidScore(Bid Bid1) {
|
---|
335 | try {
|
---|
336 | avgScore = calculateScoreValue(Bid1);
|
---|
337 | issueScoreBids.add(avgScore);
|
---|
338 | // if(debug)
|
---|
339 | // {
|
---|
340 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
341 | // System.setOut(file);
|
---|
342 | // System.out.println("Bid:" + utilitySpace.getUtility(Bid1) +
|
---|
343 | // ", AvgScore:" + this.avgScore);
|
---|
344 | // }
|
---|
345 | if (Math.abs(avgScore) > maxScore) {
|
---|
346 | maxScore = Math.abs(avgScore);
|
---|
347 | // if(debug)
|
---|
348 | // {
|
---|
349 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
350 | // true));
|
---|
351 | // System.setOut(file);
|
---|
352 | // System.out.println("Bid:" +
|
---|
353 | // this.utilitySpace.getUtility(Bid1) + ", Max IssueScore:"
|
---|
354 | // + this.maxScore);
|
---|
355 | // }
|
---|
356 | }
|
---|
357 | } catch (Exception e) {
|
---|
358 | System.out.println(e.getMessage()
|
---|
359 | + " Exception in method calculateBidScore");
|
---|
360 | }
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | @Override
|
---|
365 | public void init(NegotiationInfo info) {
|
---|
366 | super.init(info);
|
---|
367 | try {
|
---|
368 | // if(debug)
|
---|
369 | // {
|
---|
370 | // fileName = "OurBiddingData"+hashCode()+".txt";
|
---|
371 | // file = new PrintStream(new FileOutputStream(fileName, false));
|
---|
372 | // //file.println("\n");
|
---|
373 | // }
|
---|
374 | BidIterator myBidIterator = new BidIterator(
|
---|
375 | this.utilitySpace.getDomain());
|
---|
376 | double count = 0;
|
---|
377 | for (; myBidIterator.hasNext();) {
|
---|
378 | Bid bid = myBidIterator.next();
|
---|
379 | count = count + 1;
|
---|
380 | }
|
---|
381 | this.domainSize = count;
|
---|
382 | // if(debug)
|
---|
383 | // {
|
---|
384 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
385 | // System.setOut(file);
|
---|
386 | // System.out.println("Size:" + this.domainSize);
|
---|
387 | // }
|
---|
388 | this.largeDomainSize = 1000;
|
---|
389 | this.isInProfile3 = false;
|
---|
390 | this.isNeededToMoveProfile3 = false;
|
---|
391 | this.round = 0;
|
---|
392 | this.string_agentData1Num = "1";
|
---|
393 | this.string_agentData2Num = "2";
|
---|
394 | this.string_AddIssueScore = "addIssueScore";
|
---|
395 | this.string_SubtractIssueScore = "subtractIssueScore";
|
---|
396 | this.initialConcedeTime = 0.85;
|
---|
397 | this.agentData1 = new AgentData(this.reservationValue,
|
---|
398 | this.initialConcedeTime, this.initialUtilitythreshold,
|
---|
399 | this.string_agentData1Num);
|
---|
400 | this.agentData2 = new AgentData(this.reservationValue,
|
---|
401 | this.initialConcedeTime, this.initialUtilitythreshold,
|
---|
402 | this.string_agentData2Num);
|
---|
403 | this.countOpp = 0;
|
---|
404 | this.opponentBidHistory1 = new OpponentBidHistory();
|
---|
405 | this.opponentBidHistory2 = new OpponentBidHistory();
|
---|
406 | this.Issues = this.utilitySpace.getDomain().getIssues();
|
---|
407 | this.bid_maximum_utility = this.utilitySpace.getMaxUtilityBid();
|
---|
408 | this.bid_minimum_utility = this.utilitySpace.getMinUtilityBid();
|
---|
409 | this.MaximumUtility = this.utilitySpace
|
---|
410 | .getUtility(this.bid_maximum_utility);
|
---|
411 | this.offeredBidsAvg = this.MaximumUtility;
|
---|
412 | this.offeredBidsSD = (this.MaximumUtility
|
---|
413 | - this.utilitySpace.getUtility(this.bid_minimum_utility))
|
---|
414 | / 4;
|
---|
415 | this.offeredBidsRound = 0;
|
---|
416 | // if(debug)
|
---|
417 | // {
|
---|
418 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
419 | // System.setOut(file);
|
---|
420 | // System.out.println("OfferedBidsRound:" + this.offeredBidsRound +
|
---|
421 | // ", AdaptiveAvg: " + this.offeredBidsAvg + ", AdaptiveSD:" +
|
---|
422 | // this.offeredBidsSD);
|
---|
423 | // }
|
---|
424 | this.reservationValue = utilitySpace.getReservationValue();
|
---|
425 | this.delta = 0.01; // searching range
|
---|
426 | this.limit = 10;
|
---|
427 | this.previousToughnessDegree = 0;
|
---|
428 | this.numberOfRounds = 0;
|
---|
429 | this.timeLeftAfter = 0;
|
---|
430 | this.timeLeftBefore = 0;
|
---|
431 | this.maximumTimeOfOpponent = 0;
|
---|
432 | this.maximumTimeOfOwn = 0;
|
---|
433 | this.minConcedeTime = 0.08;// 0.1;
|
---|
434 | this.discountingFactor = 1;
|
---|
435 | if (utilitySpace.getDiscountFactor() <= 1D
|
---|
436 | && utilitySpace.getDiscountFactor() > 0D) {
|
---|
437 | this.discountingFactor = utilitySpace.getDiscountFactor();
|
---|
438 | }
|
---|
439 | this.NumberofDivisions = 20;
|
---|
440 | this.calculateBidsBetweenUtility();
|
---|
441 | if (this.discountingFactor <= 0.5D) {
|
---|
442 | this.chooseConcedeToDiscountingDegree();
|
---|
443 | }
|
---|
444 | this.opponentBidHistory1
|
---|
445 | .initializeDataStructures(utilitySpace.getDomain());
|
---|
446 | this.opponentBidHistory2
|
---|
447 | .initializeDataStructures(utilitySpace.getDomain());
|
---|
448 | this.timeLeftAfter = timeline.getCurrentTime();
|
---|
449 | this.concedeToOpponent = false;
|
---|
450 | this.toughAgent = false;
|
---|
451 | this.alpha1 = 2;
|
---|
452 |
|
---|
453 | if (this.domainSize < 100) {
|
---|
454 | this.k = 1;
|
---|
455 | } else if (this.domainSize < 1000) {
|
---|
456 | this.k = 2;
|
---|
457 | } else if (this.domainSize < 10000) {
|
---|
458 | this.k = 3;
|
---|
459 | } else {
|
---|
460 | this.k = 4;
|
---|
461 | }
|
---|
462 | this.FirstTimeInterval = 20;
|
---|
463 | this.SecondTimeInterval = 40;
|
---|
464 | this.ThirdTimeInterval = 60;
|
---|
465 | this.initialUtilitythreshold = 0.5;
|
---|
466 | this.avgUtilitythreshold = 0.5;
|
---|
467 | this.avgConcedeTime = 0.5;
|
---|
468 | this.EachRoundCount = 0;
|
---|
469 | this.myLastBid = this.bid_maximum_utility;
|
---|
470 | // this.issueScore = new ArrayList<ArrayList<Double>>();
|
---|
471 | // this.issueMaxScore = new ArrayList<Double>();
|
---|
472 | this.bidsUtilityScore = UpdateBidsUtilityScore(
|
---|
473 | this.bidsUtilityScore);
|
---|
474 | for (Issue lIssue : this.Issues) {
|
---|
475 | ArrayList<Double> templist1 = new ArrayList<Double>();
|
---|
476 | ArrayList<Double> templist2 = new ArrayList<Double>();
|
---|
477 | // int issueNum = lIssue.getNumber();
|
---|
478 | switch (lIssue.getType()) {
|
---|
479 | case DISCRETE:
|
---|
480 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
481 | // if(debug)
|
---|
482 | // {
|
---|
483 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
484 | // true));
|
---|
485 | // System.setOut(file);
|
---|
486 | // System.out.println("IssueNum:" + issueNum +
|
---|
487 | // ", NumOfValue:" + lIssueDiscrete.getNumberOfValues());
|
---|
488 | // }
|
---|
489 | for (int i = 0; i < lIssueDiscrete
|
---|
490 | .getNumberOfValues(); i++) {
|
---|
491 | templist1.add(i, Double.valueOf(1));
|
---|
492 | templist2.add(i, Double.valueOf(1));
|
---|
493 | // if(debug)
|
---|
494 | // {
|
---|
495 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
496 | // true));
|
---|
497 | // System.setOut(file);
|
---|
498 | // System.out.println("index:" + i);
|
---|
499 | // }
|
---|
500 | }
|
---|
501 | this.agentData1.issueScore.add(templist1);
|
---|
502 | this.agentData2.issueScore.add(templist2);
|
---|
503 | // this.agentData1.issueMaxScore.add(Double.valueOf(0));
|
---|
504 | // this.agentData2.issueMaxScore.add(Double.valueOf(0));
|
---|
505 | // if(debug)
|
---|
506 | // {
|
---|
507 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
508 | // true));
|
---|
509 | // System.setOut(file);
|
---|
510 | // System.out.println("End issueNum " + issueNum);
|
---|
511 | // }
|
---|
512 | break;
|
---|
513 | case REAL:
|
---|
514 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
515 | for (int i = 0; i < lIssueReal
|
---|
516 | .getNumberOfDiscretizationSteps(); i++) {
|
---|
517 | templist1.add(i, Double.valueOf(1));
|
---|
518 | templist2.add(i, Double.valueOf(1));
|
---|
519 | }
|
---|
520 | this.agentData1.issueScore.add(templist1);
|
---|
521 | this.agentData2.issueScore.add(templist2);
|
---|
522 | // this.agentData1.issueMaxScore.add(Double.valueOf(0));
|
---|
523 | // this.agentData2.issueMaxScore.add(Double.valueOf(0));
|
---|
524 | break;
|
---|
525 | case INTEGER:
|
---|
526 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
527 | for (int i = 0; i < lIssueInteger.getUpperBound()
|
---|
528 | - lIssueInteger.getLowerBound() + 1; i++) {
|
---|
529 | templist1.add(i, Double.valueOf(1));
|
---|
530 | templist2.add(i, Double.valueOf(1));
|
---|
531 | }
|
---|
532 | this.agentData1.issueScore.add(templist1);
|
---|
533 | this.agentData2.issueScore.add(templist2);
|
---|
534 | // this.agentData1.issueMaxScore.add(Double.valueOf(0));
|
---|
535 | // this.agentData2.issueMaxScore.add(Double.valueOf(0));
|
---|
536 | break;
|
---|
537 | default:
|
---|
538 | throw new Exception("issue type " + lIssue.getType()
|
---|
539 | + " not supported");
|
---|
540 | }
|
---|
541 | }
|
---|
542 | } catch (Exception e) {
|
---|
543 | System.out.println("initialization error" + e.getMessage());
|
---|
544 | }
|
---|
545 | }
|
---|
546 |
|
---|
547 | public String getVersion() {
|
---|
548 | return "Ngent";
|
---|
549 | }
|
---|
550 |
|
---|
551 | public String getName() {
|
---|
552 | return "Ngent";
|
---|
553 | }
|
---|
554 |
|
---|
555 | @Override
|
---|
556 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
557 | Action action = null;
|
---|
558 | this.EachRoundCount = this.countOpp;
|
---|
559 | this.round = this.round + 1;
|
---|
560 | try {
|
---|
561 | // System.out.println("i propose " + debug + " bid at time " +
|
---|
562 | // timeline.getTime());
|
---|
563 | this.timeLeftBefore = timeline.getCurrentTime();
|
---|
564 | Bid bid = null;
|
---|
565 | // we propose first and propose the bid with maximum utility
|
---|
566 | if (this.round == 1) {
|
---|
567 | bid = this.bid_maximum_utility;
|
---|
568 | UpdateOfferedBidsStat(this.utilitySpace.getUtility(bid));
|
---|
569 | action = new Offer(getPartyId(), bid);
|
---|
570 | }
|
---|
571 | // else if (ActionOfOpponent instanceof Offer)
|
---|
572 | else {
|
---|
573 | // the opponent propose first and we response secondly
|
---|
574 | // update opponent model first
|
---|
575 | this.opponentBidHistory1.updateOpponentModel(
|
---|
576 | this.agentData1.oppPreviousBid,
|
---|
577 | utilitySpace.getDomain(), this.utilitySpace);
|
---|
578 | this.opponentBidHistory2.updateOpponentModel(
|
---|
579 | this.agentData2.oppPreviousBid,
|
---|
580 | utilitySpace.getDomain(), this.utilitySpace);
|
---|
581 | if (this.discountingFactor == 1) {
|
---|
582 | this.agentData1 = updateConcedeDegree_nonDF(
|
---|
583 | this.agentData1);
|
---|
584 | this.agentData2 = updateConcedeDegree_nonDF(
|
---|
585 | this.agentData2);
|
---|
586 | } else if (this.discountingFactor <= 0.5) {
|
---|
587 | this.agentData1 = updateConcedeDegree_smallDF(
|
---|
588 | this.agentData1);
|
---|
589 | this.agentData2 = updateConcedeDegree_smallDF(
|
---|
590 | this.agentData2);
|
---|
591 | } else {
|
---|
592 | updateConcedeDegree_largeDF(this.agentData1);
|
---|
593 | updateConcedeDegree_largeDF(this.agentData2);
|
---|
594 | }
|
---|
595 | Bid oppPreBid;
|
---|
596 | if (this.isInProfile3) {
|
---|
597 | oppPreBid = this.agentData1.oppPreviousBid;
|
---|
598 | } else {
|
---|
599 | oppPreBid = this.agentData2.oppPreviousBid;
|
---|
600 | }
|
---|
601 | // update the estimation
|
---|
602 | if (estimateRoundLeft(true) > 10) {
|
---|
603 | // still have some rounds left to further negotiate (the
|
---|
604 | // major negotiation period)
|
---|
605 | bid = BidToOffer_original();
|
---|
606 | // if(debug)
|
---|
607 | // {
|
---|
608 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
609 | // true));
|
---|
610 | // System.setOut(file);
|
---|
611 | // System.out.println("Proposed Bid!");
|
---|
612 | // }
|
---|
613 | Boolean IsAccept = AcceptOpponentOffer(oppPreBid, bid);
|
---|
614 | IsAccept = OtherAcceptCondition(oppPreBid, IsAccept);
|
---|
615 |
|
---|
616 | Boolean IsTerminate = TerminateCurrentNegotiation(bid);
|
---|
617 | if (IsAccept && !IsTerminate) {
|
---|
618 | action = new Accept(getPartyId(), oppPreBid);
|
---|
619 | // if(debug)
|
---|
620 | // {
|
---|
621 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
622 | // true));
|
---|
623 | // System.setOut(file);
|
---|
624 | // System.out.println("Accept the offer");
|
---|
625 | // }
|
---|
626 | } else if (IsTerminate && !IsAccept) {
|
---|
627 | action = new EndNegotiation(getPartyId());
|
---|
628 | // System.out.println("we determine to terminate the
|
---|
629 | // negotiation");
|
---|
630 | } else if (IsAccept && IsTerminate) {
|
---|
631 | if (this.utilitySpace.getUtility(
|
---|
632 | oppPreBid) > this.reservationValue) {
|
---|
633 | action = new Accept(getPartyId(), oppPreBid);
|
---|
634 | // if(debug)
|
---|
635 | // {
|
---|
636 | // file = new PrintStream(new
|
---|
637 | // FileOutputStream(fileName, true));
|
---|
638 | // System.setOut(file);
|
---|
639 | // System.out.println("Compare Accept & Terminate,
|
---|
640 | // we accept the offer");
|
---|
641 | // }
|
---|
642 | } else {
|
---|
643 | action = new EndNegotiation(getPartyId());
|
---|
644 | // if(debug)
|
---|
645 | // {
|
---|
646 | // file = new PrintStream(new
|
---|
647 | // FileOutputStream(fileName, true));
|
---|
648 | // System.setOut(file);
|
---|
649 | // System.out.println("Compare Accept & Terminate,
|
---|
650 | // we terminate the negotiation");
|
---|
651 | // }
|
---|
652 | }
|
---|
653 | } else {
|
---|
654 | // we expect that the negotiation is over once we select
|
---|
655 | // a bid from the opponent's history.
|
---|
656 | if (this.concedeToOpponent == true) {
|
---|
657 | // bid =
|
---|
658 | // opponentBidHistory.chooseBestFromHistory(this.utilitySpace);
|
---|
659 | Bid bid1 = opponentBidHistory1
|
---|
660 | .getBestBidInHistory();
|
---|
661 | Bid bid2 = opponentBidHistory2
|
---|
662 | .getBestBidInHistory();
|
---|
663 | if (this.utilitySpace
|
---|
664 | .getUtility(bid1) > this.utilitySpace
|
---|
665 | .getUtility(bid2)) {
|
---|
666 | bid = bid2;
|
---|
667 | } else if (this.utilitySpace.getUtility(
|
---|
668 | bid1) == this.utilitySpace.getUtility(bid2)
|
---|
669 | && Math.random() < 0.5) {
|
---|
670 | bid = bid2;
|
---|
671 | } else {
|
---|
672 | bid = bid1;
|
---|
673 | }
|
---|
674 | action = new Offer(getPartyId(), bid);
|
---|
675 | // System.out.println("we offer the best bid in the
|
---|
676 | // history and the opponent should accept it");
|
---|
677 | this.toughAgent = true;
|
---|
678 | this.concedeToOpponent = false;
|
---|
679 | // if(debug)
|
---|
680 | // {
|
---|
681 | // file = new PrintStream(new
|
---|
682 | // FileOutputStream(fileName, true));
|
---|
683 | // System.setOut(file);
|
---|
684 | // System.out.println("we offer the best bid in the
|
---|
685 | // history and the opponent should accept it. Bid:"
|
---|
686 | // + this.utilitySpace.getUtility(bid));
|
---|
687 | // }
|
---|
688 | } else {
|
---|
689 | action = new Offer(getPartyId(), bid);
|
---|
690 | this.toughAgent = false;
|
---|
691 | // if(debug)
|
---|
692 | // {
|
---|
693 | // file = new PrintStream(new
|
---|
694 | // FileOutputStream(fileName, true));
|
---|
695 | // System.setOut(file);
|
---|
696 | // System.out.println("Propose Bid: " +
|
---|
697 | // this.utilitySpace.getUtility(bid) + " at time " +
|
---|
698 | // timeline.getTime());
|
---|
699 | // }
|
---|
700 | }
|
---|
701 | }
|
---|
702 | } else {// this is the last chance and we concede by providing
|
---|
703 | // the opponent the best offer he ever proposed to us
|
---|
704 | // in this case, it corresponds to an opponent whose
|
---|
705 | // decision time is short
|
---|
706 |
|
---|
707 | if (timeline.getTime() > 0.99
|
---|
708 | && estimateRoundLeft(true) < 5) {
|
---|
709 | if (this.utilitySpace.getUtility(
|
---|
710 | oppPreBid) > this.avgUtilitythreshold) {
|
---|
711 | action = new Accept(getPartyId(), oppPreBid);
|
---|
712 | bid = oppPreBid;
|
---|
713 | } else {
|
---|
714 | bid = BidToOffer_original();
|
---|
715 |
|
---|
716 | Boolean IsAccept = AcceptOpponentOffer(oppPreBid,
|
---|
717 | bid);
|
---|
718 | IsAccept = OtherAcceptCondition(oppPreBid,
|
---|
719 | IsAccept);
|
---|
720 |
|
---|
721 | Boolean IsTerminate = TerminateCurrentNegotiation(
|
---|
722 | bid);
|
---|
723 | if (IsAccept && !IsTerminate) {
|
---|
724 | action = new Accept(getPartyId(), oppPreBid);
|
---|
725 | // System.out.println("accept the offer");
|
---|
726 | } else if (IsTerminate && !IsAccept) {
|
---|
727 | action = new EndNegotiation(getPartyId());
|
---|
728 | // System.out.println("we determine to terminate
|
---|
729 | // the negotiation");
|
---|
730 | } else if (IsTerminate && IsAccept) {
|
---|
731 | if (this.utilitySpace.getUtility(
|
---|
732 | oppPreBid) > this.reservationValue) {
|
---|
733 | action = new Accept(getPartyId(),
|
---|
734 | oppPreBid);
|
---|
735 | // System.out.println("we accept the offer
|
---|
736 | // RANDOMLY");
|
---|
737 | } else {
|
---|
738 | action = new EndNegotiation(getPartyId());
|
---|
739 | // System.out.println("we determine to
|
---|
740 | // terminate the negotiation RANDOMLY");
|
---|
741 | }
|
---|
742 | } else {
|
---|
743 | if (this.toughAgent == true) {
|
---|
744 | action = new Accept(getPartyId(),
|
---|
745 | oppPreBid);
|
---|
746 | // System.out.println("the opponent is tough
|
---|
747 | // and the deadline is approching thus we
|
---|
748 | // accept the offer");
|
---|
749 | } else {
|
---|
750 | action = new Offer(getPartyId(), bid);
|
---|
751 | // this.toughAgent = true;
|
---|
752 | // System.out.println("this is really the
|
---|
753 | // last chance"
|
---|
754 | // + bid.toString() + " with utility of " +
|
---|
755 | // utilitySpace.getUtility(bid));
|
---|
756 | }
|
---|
757 | }
|
---|
758 | // in this case, it corresponds to the situation
|
---|
759 | // that we encounter an opponent who needs more
|
---|
760 | // computation to make decision each round
|
---|
761 | }
|
---|
762 | } else {// we still have some time to negotiate,
|
---|
763 | // and be tough by sticking with the lowest one in
|
---|
764 | // previous offer history.
|
---|
765 | // we also have to make the decisin fast to avoid
|
---|
766 | // reaching the deadline before the decision is made
|
---|
767 | // bid = ownBidHistory.GetMinBidInHistory();//reduce
|
---|
768 | // the computational cost
|
---|
769 | bid = BidToOffer_original();
|
---|
770 | // System.out.println("test----------------------------------------------------------"
|
---|
771 | // + timeline.getTime());
|
---|
772 | Boolean IsAccept = AcceptOpponentOffer(oppPreBid, bid);
|
---|
773 | IsAccept = OtherAcceptCondition(oppPreBid, IsAccept);
|
---|
774 |
|
---|
775 | Boolean IsTerminate = TerminateCurrentNegotiation(bid);
|
---|
776 | if (IsAccept && !IsTerminate) {
|
---|
777 | action = new Accept(getPartyId(), oppPreBid);
|
---|
778 | // System.out.println("accept the offer");
|
---|
779 | } else if (IsTerminate && !IsAccept) {
|
---|
780 | action = new EndNegotiation(getPartyId());
|
---|
781 | // System.out.println("we determine to terminate the
|
---|
782 | // negotiation");
|
---|
783 | } else if (IsAccept && IsTerminate) {
|
---|
784 | if (this.utilitySpace.getUtility(
|
---|
785 | oppPreBid) > this.reservationValue) {
|
---|
786 | action = new Accept(getPartyId(), oppPreBid);
|
---|
787 | // System.out.println("we accept the offer
|
---|
788 | // RANDOMLY");
|
---|
789 | } else {
|
---|
790 | action = new EndNegotiation(getPartyId());
|
---|
791 | // System.out.println("we determine to terminate
|
---|
792 | // the negotiation RANDOMLY");
|
---|
793 | }
|
---|
794 | } else {
|
---|
795 | action = new Offer(getPartyId(), bid);
|
---|
796 | // System.out.println("we have to be tough now" +
|
---|
797 | // bid.toString() + " with utility of " +
|
---|
798 | // utilitySpace.getUtility(bid));
|
---|
799 | }
|
---|
800 | }
|
---|
801 | }
|
---|
802 | }
|
---|
803 | this.myLastBid = bid;
|
---|
804 |
|
---|
805 | // System.out.println("i propose " + debug + " bid at time " +
|
---|
806 | // timeline.getTime());
|
---|
807 | // this.ownBidHistory.addBid(bid, utilitySpace);
|
---|
808 | this.timeLeftAfter = timeline.getCurrentTime();
|
---|
809 | if (this.timeLeftAfter
|
---|
810 | - this.timeLeftBefore > this.maximumTimeOfOwn) {
|
---|
811 | this.maximumTimeOfOwn = this.timeLeftAfter
|
---|
812 | - this.timeLeftBefore;
|
---|
813 | } // update the estimation
|
---|
814 | // System.out.println(this.utilitythreshold + "-***-----" +
|
---|
815 | // this.timeline.getElapsedSeconds());
|
---|
816 |
|
---|
817 | // if(debug)
|
---|
818 | // {
|
---|
819 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
820 | // System.setOut(file);
|
---|
821 | // //System.out.println("Size: " + this.numberOfBids + ". Res: " +
|
---|
822 | // Double.toString(this.reservationValue) + ". Dis: " +
|
---|
823 | // Double.toString(this.discountingFactor) + "\n");
|
---|
824 | // System.out.println("Round:" + this.round + ", Time: " +
|
---|
825 | // this.timeline.getTime()+", Avg:" +
|
---|
826 | // this.avgUtilitythreshold+", MinAccept:" +
|
---|
827 | // this.minUtilityUhreshold);
|
---|
828 | // System.out.println("NormalMinThreAgent1: " +
|
---|
829 | // this.agentData1.minThreshold + ", NormalMinThreAgent2: " +
|
---|
830 | // this.agentData2.minThreshold);
|
---|
831 | // System.out.println("AdaptiveMinU: " + this.adaptiveMinUThreshold
|
---|
832 | // + ", finalMinUAgent1:" + this.finalMinUAgent1 +
|
---|
833 | // ", finalMinUAgent2:" + this.finalMinUAgent2);
|
---|
834 | // }
|
---|
835 | } catch (Exception e) {
|
---|
836 | System.out.println("Exception in chooseAction:" + e.getMessage());
|
---|
837 | action = new EndNegotiation(getPartyId()); // terminate if anything
|
---|
838 | // goes wrong.
|
---|
839 | }
|
---|
840 | return action;
|
---|
841 | }
|
---|
842 |
|
---|
843 | @Override
|
---|
844 | public void receiveMessage(AgentID sender, Action opponentAction) {
|
---|
845 | super.receiveMessage(sender, opponentAction);
|
---|
846 | // sender.getClass().getName();
|
---|
847 | this.ActionOfOpponent = opponentAction;
|
---|
848 |
|
---|
849 | try {
|
---|
850 | this.countOpp = this.countOpp + 1;
|
---|
851 | // if(debug)
|
---|
852 | // {
|
---|
853 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
854 | // System.setOut(file);
|
---|
855 | // System.out.println("Enter receiveMessage! round:" + round +
|
---|
856 | // ", CountOpp:" + countOpp + ", EachRoundCount:" + EachRoundCount);
|
---|
857 | // }
|
---|
858 | if (this.countOpp == this.EachRoundCount + 3) {
|
---|
859 | this.EachRoundCount = this.EachRoundCount + 2;
|
---|
860 | this.isNeededToMoveProfile3 = true;
|
---|
861 | // if(debug)
|
---|
862 | // {
|
---|
863 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
864 | // System.setOut(file);
|
---|
865 | // System.out.println("Abnormal! round:" + round + ", CountOpp:"
|
---|
866 | // + countOpp + ", EachRoundCount:" + EachRoundCount);
|
---|
867 | // }
|
---|
868 | }
|
---|
869 | if (!this.isInProfile3) {
|
---|
870 | // In Profile 1 or 2
|
---|
871 | System.out.println("Current Profile: 1 or 2");
|
---|
872 | if (this.countOpp == this.EachRoundCount + 1)// Next Agent
|
---|
873 | // w.r.t. us
|
---|
874 | {
|
---|
875 | // if(debug)
|
---|
876 | // {
|
---|
877 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
878 | // true));
|
---|
879 | // System.setOut(file);
|
---|
880 | // System.out.println("Enter AgentData1! round:" + round +
|
---|
881 | // ", CountOpp:" + countOpp + ", EachRoundCount:" +
|
---|
882 | // EachRoundCount);
|
---|
883 | // }
|
---|
884 | if ((this.ActionOfOpponent instanceof Offer)) {
|
---|
885 | // if(debug)
|
---|
886 | // {
|
---|
887 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
888 | // true));
|
---|
889 | // System.setOut(file);
|
---|
890 | // System.out.println("AgentData1 Action: Offer! round:"
|
---|
891 | // + round + ", CountOpp:" + countOpp +
|
---|
892 | // ", EachRoundCount:" + EachRoundCount);
|
---|
893 | // }
|
---|
894 | if (!this.agentData1.GetIsReceivedOppFirstBid()) {
|
---|
895 | this.agentData1.oppFirstBid = ((Offer) this.ActionOfOpponent)
|
---|
896 | .getBid();
|
---|
897 | this.agentData1.oppFirstBidUtility = this.utilitySpace
|
---|
898 | .getUtility(this.agentData1.oppFirstBid);
|
---|
899 | // if(debug)
|
---|
900 | // {
|
---|
901 | // file = new PrintStream(new
|
---|
902 | // FileOutputStream(fileName, true));
|
---|
903 | // System.setOut(file);
|
---|
904 | // System.out.println("Enter SetFirstBidInform
|
---|
905 | // AgentData1! round:"
|
---|
906 | // + round + ", CountOpp:" + countOpp +
|
---|
907 | // ", EachRoundCount:" + EachRoundCount);
|
---|
908 | // }
|
---|
909 | this.agentData1.SetIsReceivedOppFirstBid(true);
|
---|
910 | }
|
---|
911 | this.agentData1.oppPreviousBid = ((Offer) this.ActionOfOpponent)
|
---|
912 | .getBid();
|
---|
913 | this.agentData1.ChangeIssueScore(
|
---|
914 | this.agentData1.oppPreviousBid,
|
---|
915 | this.string_AddIssueScore);
|
---|
916 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
917 | .getUtility(this.agentData1.oppPreviousBid));
|
---|
918 | } else if ((this.ActionOfOpponent instanceof Accept)) {
|
---|
919 | this.agentData1.oppPreviousBid = this.myLastBid;
|
---|
920 | this.agentData1.ChangeIssueScore(
|
---|
921 | this.agentData1.oppPreviousBid,
|
---|
922 | this.string_AddIssueScore);
|
---|
923 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
924 | .getUtility(this.agentData1.oppPreviousBid));
|
---|
925 | }
|
---|
926 | } else if (this.countOpp == this.EachRoundCount + 2) // Previous
|
---|
927 | // Agent
|
---|
928 | // w.r.t.
|
---|
929 | // us
|
---|
930 | {
|
---|
931 | // if(debug)
|
---|
932 | // {
|
---|
933 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
934 | // true));
|
---|
935 | // System.setOut(file);
|
---|
936 | // System.out.println("Enter AgentData2! round:" + round +
|
---|
937 | // ", CountOpp:" + countOpp + ", EachRoundCount:" +
|
---|
938 | // EachRoundCount);
|
---|
939 | // }
|
---|
940 | if ((this.ActionOfOpponent instanceof Offer)) {
|
---|
941 | // if(debug)
|
---|
942 | // {
|
---|
943 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
944 | // true));
|
---|
945 | // System.setOut(file);
|
---|
946 | // System.out.println("AgentData2 Action: Offer! round:"
|
---|
947 | // + round + ", CountOpp:" + countOpp +
|
---|
948 | // ", EachRoundCount:" + EachRoundCount);
|
---|
949 | // }
|
---|
950 | if (!this.agentData2.GetIsReceivedOppFirstBid()) {
|
---|
951 | this.agentData2.oppFirstBid = ((Offer) this.ActionOfOpponent)
|
---|
952 | .getBid();
|
---|
953 | this.agentData2.oppFirstBidUtility = this.utilitySpace
|
---|
954 | .getUtility(this.agentData2.oppFirstBid);
|
---|
955 | // if(debug)
|
---|
956 | // {
|
---|
957 | // file = new PrintStream(new
|
---|
958 | // FileOutputStream(fileName, true));
|
---|
959 | // System.setOut(file);
|
---|
960 | // System.out.println("Enter SetFirstBidInform
|
---|
961 | // AgentData2! round:"
|
---|
962 | // + round + ", CountOpp:" + countOpp +
|
---|
963 | // ", EachRoundCount:" + EachRoundCount);
|
---|
964 | // }
|
---|
965 | this.agentData2.SetIsReceivedOppFirstBid(true);
|
---|
966 | }
|
---|
967 | this.agentData2.oppPreviousBid = ((Offer) this.ActionOfOpponent)
|
---|
968 | .getBid();
|
---|
969 | this.agentData2.ChangeIssueScore(
|
---|
970 | this.agentData2.oppPreviousBid,
|
---|
971 | this.string_AddIssueScore);
|
---|
972 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
973 | .getUtility(this.agentData2.oppPreviousBid));
|
---|
974 | } else if ((this.ActionOfOpponent instanceof Accept)) {
|
---|
975 | this.agentData2.oppPreviousBid = this.agentData1.oppPreviousBid;
|
---|
976 | this.agentData2.ChangeIssueScore(
|
---|
977 | this.agentData2.oppPreviousBid,
|
---|
978 | this.string_AddIssueScore);
|
---|
979 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
980 | .getUtility(this.agentData2.oppPreviousBid));
|
---|
981 | }
|
---|
982 | }
|
---|
983 |
|
---|
984 | if (this.isNeededToMoveProfile3) {
|
---|
985 | this.isInProfile3 = true;
|
---|
986 | }
|
---|
987 | } else {
|
---|
988 | // In Profile 3
|
---|
989 | System.out.println("Current Profile: 3");
|
---|
990 | if (this.countOpp == this.EachRoundCount + 2)// Previous Agent
|
---|
991 | // w.r.t. us
|
---|
992 | {
|
---|
993 | // if(debug)
|
---|
994 | // {
|
---|
995 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
996 | // true));
|
---|
997 | // System.setOut(file);
|
---|
998 | // System.out.println("Enter AgentData1! round:" + round +
|
---|
999 | // ", CountOpp:" + countOpp + ", EachRoundCount:" +
|
---|
1000 | // EachRoundCount);
|
---|
1001 | // }
|
---|
1002 | if ((this.ActionOfOpponent instanceof Offer)) {
|
---|
1003 | // if(debug)
|
---|
1004 | // {
|
---|
1005 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1006 | // true));
|
---|
1007 | // System.setOut(file);
|
---|
1008 | // System.out.println("AgentData1 Action: Offer! round:"
|
---|
1009 | // + round + ", CountOpp:" + countOpp +
|
---|
1010 | // ", EachRoundCount:" + EachRoundCount);
|
---|
1011 | // }
|
---|
1012 | if (!this.agentData1.GetIsReceivedOppFirstBid()) {
|
---|
1013 | this.agentData1.oppFirstBid = ((Offer) this.ActionOfOpponent)
|
---|
1014 | .getBid();
|
---|
1015 | this.agentData1.oppFirstBidUtility = this.utilitySpace
|
---|
1016 | .getUtility(this.agentData1.oppFirstBid);
|
---|
1017 | // if(debug)
|
---|
1018 | // {
|
---|
1019 | // file = new PrintStream(new
|
---|
1020 | // FileOutputStream(fileName, true));
|
---|
1021 | // System.setOut(file);
|
---|
1022 | // System.out.println("Enter SetFirstBidInform
|
---|
1023 | // AgentData1! round:"
|
---|
1024 | // + round + ", CountOpp:" + countOpp +
|
---|
1025 | // ", EachRoundCount:" + EachRoundCount);
|
---|
1026 | // }
|
---|
1027 | this.agentData1.SetIsReceivedOppFirstBid(true);
|
---|
1028 | }
|
---|
1029 | this.agentData1.oppPreviousBid = ((Offer) this.ActionOfOpponent)
|
---|
1030 | .getBid();
|
---|
1031 | this.agentData1.ChangeIssueScore(
|
---|
1032 | this.agentData1.oppPreviousBid,
|
---|
1033 | this.string_AddIssueScore);
|
---|
1034 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
1035 | .getUtility(this.agentData1.oppPreviousBid));
|
---|
1036 | // if(debug)
|
---|
1037 | // {
|
---|
1038 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1039 | // true));
|
---|
1040 | // System.setOut(file);
|
---|
1041 | // System.out.println("AgentData1 Action: Offer! Bid:" +
|
---|
1042 | // this.utilitySpace.getUtility(this.agentData1.oppPreviousBid));
|
---|
1043 | // }
|
---|
1044 | } else if ((this.ActionOfOpponent instanceof Accept)) {
|
---|
1045 | this.agentData1.oppPreviousBid = this.agentData2.oppPreviousBid;
|
---|
1046 | this.agentData1.ChangeIssueScore(
|
---|
1047 | this.agentData1.oppPreviousBid,
|
---|
1048 | this.string_AddIssueScore);
|
---|
1049 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
1050 | .getUtility(this.agentData1.oppPreviousBid));
|
---|
1051 | }
|
---|
1052 | } else if (this.countOpp == this.EachRoundCount + 1) // Next
|
---|
1053 | // Agent
|
---|
1054 | // w.r.t.
|
---|
1055 | // us
|
---|
1056 | {
|
---|
1057 | // if(debug)
|
---|
1058 | // {
|
---|
1059 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1060 | // true));
|
---|
1061 | // System.setOut(file);
|
---|
1062 | // System.out.println("Enter AgentData2! round:" + round +
|
---|
1063 | // ", CountOpp:" + countOpp + ", EachRoundCount:" +
|
---|
1064 | // EachRoundCount);
|
---|
1065 | // }
|
---|
1066 | if ((this.ActionOfOpponent instanceof Offer)) {
|
---|
1067 | // if(debug)
|
---|
1068 | // {
|
---|
1069 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1070 | // true));
|
---|
1071 | // System.setOut(file);
|
---|
1072 | // System.out.println("AgentData2 Action: Offer! round:"
|
---|
1073 | // + round + ", CountOpp:" + countOpp +
|
---|
1074 | // ", EachRoundCount:" + EachRoundCount);
|
---|
1075 | // }
|
---|
1076 | if (!this.agentData2.GetIsReceivedOppFirstBid()) {
|
---|
1077 | this.agentData2.oppFirstBid = ((Offer) this.ActionOfOpponent)
|
---|
1078 | .getBid();
|
---|
1079 | this.agentData2.oppFirstBidUtility = this.utilitySpace
|
---|
1080 | .getUtility(this.agentData2.oppFirstBid);
|
---|
1081 | // if(debug)
|
---|
1082 | // {
|
---|
1083 | // file = new PrintStream(new
|
---|
1084 | // FileOutputStream(fileName, true));
|
---|
1085 | // System.setOut(file);
|
---|
1086 | // System.out.println("Enter SetFirstBidInform
|
---|
1087 | // AgentData2! round:"
|
---|
1088 | // + round + ", CountOpp:" + countOpp +
|
---|
1089 | // ", EachRoundCount:" + EachRoundCount);
|
---|
1090 | // }
|
---|
1091 | this.agentData2.SetIsReceivedOppFirstBid(true);
|
---|
1092 | }
|
---|
1093 | this.agentData2.oppPreviousBid = ((Offer) this.ActionOfOpponent)
|
---|
1094 | .getBid();
|
---|
1095 | this.agentData2.ChangeIssueScore(
|
---|
1096 | this.agentData2.oppPreviousBid,
|
---|
1097 | this.string_AddIssueScore);
|
---|
1098 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
1099 | .getUtility(this.agentData2.oppPreviousBid));
|
---|
1100 | } else if ((this.ActionOfOpponent instanceof Accept)) {
|
---|
1101 | this.agentData2.oppPreviousBid = this.myLastBid;
|
---|
1102 | this.agentData2.ChangeIssueScore(
|
---|
1103 | this.agentData2.oppPreviousBid,
|
---|
1104 | this.string_AddIssueScore);
|
---|
1105 | UpdateOfferedBidsStat(this.utilitySpace
|
---|
1106 | .getUtility(this.agentData2.oppPreviousBid));
|
---|
1107 | }
|
---|
1108 | }
|
---|
1109 | }
|
---|
1110 | } catch (Exception e) {
|
---|
1111 | System.out.println(
|
---|
1112 | e.getMessage() + " exception in method receiveMessage");
|
---|
1113 | }
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | private void UpdateOfferedBidsStat(double bidU) {
|
---|
1117 | try {
|
---|
1118 | int newOfferedBidsRound = this.offeredBidsRound + 1;
|
---|
1119 | // if(debug)
|
---|
1120 | // {
|
---|
1121 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1122 | // System.setOut(file);
|
---|
1123 | // System.out.println("OfferedBidsRound:" + this.offeredBidsRound +
|
---|
1124 | // ", AdaptiveAvg: " + this.offeredBidsAvg + ", AdaptiveSD:" +
|
---|
1125 | // this.offeredBidsSD + ", bidU:" + bidU);
|
---|
1126 | // }
|
---|
1127 | this.offeredBidsAvg = (bidU - this.offeredBidsAvg)
|
---|
1128 | / newOfferedBidsRound + this.offeredBidsAvg;
|
---|
1129 | this.offeredBidsSD = Math.sqrt((this.offeredBidsRound
|
---|
1130 | * this.offeredBidsSD * this.offeredBidsSD
|
---|
1131 | + (bidU - this.offeredBidsAvg)
|
---|
1132 | * (bidU - this.offeredBidsAvg))
|
---|
1133 | / newOfferedBidsRound);
|
---|
1134 | this.offeredBidsRound = newOfferedBidsRound;
|
---|
1135 | // if(debug)
|
---|
1136 | // {
|
---|
1137 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1138 | // System.setOut(file);
|
---|
1139 | // System.out.println("OfferedBidsRound:" + this.offeredBidsRound +
|
---|
1140 | // ", AdaptiveAvg: " + this.offeredBidsAvg + ", AdaptiveSD:" +
|
---|
1141 | // this.offeredBidsSD + ", bidU:" + bidU);
|
---|
1142 | // }
|
---|
1143 | } catch (Exception e) {
|
---|
1144 | System.out.println(e.getMessage()
|
---|
1145 | + " exception in method UpdateOfferedBidsStat");
|
---|
1146 | }
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | /*
|
---|
1150 | * decide whether to accept the current offer or not
|
---|
1151 | */
|
---|
1152 | private boolean AcceptOpponentOffer(Bid opponentBid, Bid ownBid) {
|
---|
1153 | try {
|
---|
1154 | double currentUtility = 0;
|
---|
1155 | double nextRoundUtility = 0;
|
---|
1156 | double maximumUtility = 0;
|
---|
1157 | this.concedeToOpponent = false;
|
---|
1158 | currentUtility = this.utilitySpace.getUtility(opponentBid);
|
---|
1159 | maximumUtility = this.MaximumUtility;// utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
|
---|
1160 | nextRoundUtility = this.utilitySpace.getUtility(ownBid);
|
---|
1161 |
|
---|
1162 | // System.out.println(this.utilitythreshold +"at time "+
|
---|
1163 | // timeline.getTime());
|
---|
1164 | if (currentUtility >= this.avgUtilitythreshold
|
---|
1165 | || currentUtility >= nextRoundUtility) {
|
---|
1166 | // if(debug)
|
---|
1167 | // {
|
---|
1168 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1169 | // System.setOut(file);
|
---|
1170 | // System.out.println("currentUtility >=
|
---|
1171 | // this.avgUtilitythreshold || currentUtility >=
|
---|
1172 | // nextRoundUtility: true, AvgU:"
|
---|
1173 | // + this.avgUtilitythreshold + ", currentU:" + currentUtility +
|
---|
1174 | // ", nextRoundUtility:" + nextRoundUtility);
|
---|
1175 | // }
|
---|
1176 | return true;
|
---|
1177 | } else {
|
---|
1178 | // if the current utility with discount is larger than the
|
---|
1179 | // predicted maximum utility with discount
|
---|
1180 | // then accept it.
|
---|
1181 | double predictMaximumUtility = maximumUtility
|
---|
1182 | * this.discountingFactor;
|
---|
1183 | // double currentMaximumUtility =
|
---|
1184 | // this.utilitySpace.getUtilityWithDiscount(opponentBidHistory.chooseBestFromHistory(utilitySpace),
|
---|
1185 | // timeline);
|
---|
1186 | double currentMaximumUtility1 = this.utilitySpace
|
---|
1187 | .getUtilityWithDiscount(
|
---|
1188 | opponentBidHistory1.getBestBidInHistory(),
|
---|
1189 | timeline);
|
---|
1190 | double currentMaximumUtility2 = this.utilitySpace
|
---|
1191 | .getUtilityWithDiscount(
|
---|
1192 | opponentBidHistory2.getBestBidInHistory(),
|
---|
1193 | timeline);
|
---|
1194 | double currentMaximumUtility = Math.min(currentMaximumUtility1,
|
---|
1195 | currentMaximumUtility2);
|
---|
1196 | if (currentMaximumUtility > predictMaximumUtility
|
---|
1197 | && timeline.getTime() > this.avgConcedeTime) {
|
---|
1198 | // if(debug)
|
---|
1199 | // {
|
---|
1200 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1201 | // true));
|
---|
1202 | // System.setOut(file);
|
---|
1203 | // System.out.println("currentMaximumUtility >
|
---|
1204 | // predictMaximumUtility && timeline.getTime() >
|
---|
1205 | // this.avgConcedeTime: true, currentMaximumUtility:"
|
---|
1206 | // + currentMaximumUtility + ", predictMaximumUtility:" +
|
---|
1207 | // predictMaximumUtility + ", avgConcedeTime:" +
|
---|
1208 | // this.avgConcedeTime);
|
---|
1209 | // }
|
---|
1210 | // if the current offer is approximately as good as the best
|
---|
1211 | // one in the history, then accept it.
|
---|
1212 | if (utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
1213 | timeline) >= currentMaximumUtility - 0.01) {
|
---|
1214 | // System.out.println("he offered me " +
|
---|
1215 | // currentMaximumUtility +
|
---|
1216 | // " we predict we can get at most " +
|
---|
1217 | // predictMaximumUtility +
|
---|
1218 | // "we concede now to avoid lower payoff due to
|
---|
1219 | // conflict");
|
---|
1220 | // if(debug)
|
---|
1221 | // {
|
---|
1222 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1223 | // true));
|
---|
1224 | // System.setOut(file);
|
---|
1225 | // System.out.println("utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
1226 | // timeline) >= currentMaximumUtility - 0.01: true,
|
---|
1227 | // DFoppBid:"
|
---|
1228 | // + utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
1229 | // timeline) + ", currentMaximumUtility - 0.01:" +
|
---|
1230 | // (currentMaximumUtility - 0.01));
|
---|
1231 | // }
|
---|
1232 | return true;
|
---|
1233 | } else {
|
---|
1234 | this.concedeToOpponent = true;
|
---|
1235 | return false;
|
---|
1236 | }
|
---|
1237 | }
|
---|
1238 | // retrieve the opponent's biding history and utilize it
|
---|
1239 | else if (currentMaximumUtility > this.avgUtilitythreshold * Math
|
---|
1240 | .pow(this.discountingFactor, timeline.getTime())) {
|
---|
1241 | // if(debug)
|
---|
1242 | // {
|
---|
1243 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1244 | // true));
|
---|
1245 | // System.setOut(file);
|
---|
1246 | // System.out.println("currentMaximumUtility >
|
---|
1247 | // this.avgUtilitythreshold *
|
---|
1248 | // Math.pow(this.discountingFactor, timeline.getTime()):
|
---|
1249 | // true, currentMaximumUtility:"
|
---|
1250 | // + currentMaximumUtility + ", avgU:" + avgUtilitythreshold
|
---|
1251 | // + ", DFavgU:" + this.avgUtilitythreshold *
|
---|
1252 | // Math.pow(this.discountingFactor, timeline.getTime()));
|
---|
1253 | // }
|
---|
1254 | // if the current offer is approximately as good as the best
|
---|
1255 | // one in the history, then accept it.
|
---|
1256 | if (utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
1257 | timeline) >= currentMaximumUtility - 0.01) {
|
---|
1258 | // if(debug)
|
---|
1259 | // {
|
---|
1260 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1261 | // true));
|
---|
1262 | // System.setOut(file);
|
---|
1263 | // System.out.println("utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
1264 | // timeline) >= currentMaximumUtility - 0.01: true,
|
---|
1265 | // DFoppBid:"
|
---|
1266 | // + utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
1267 | // timeline) + ", currentMaximumUtility - 0.01:" +
|
---|
1268 | // (currentMaximumUtility - 0.01));
|
---|
1269 | // }
|
---|
1270 | return true;
|
---|
1271 | } else {
|
---|
1272 | // System.out.println("test" +
|
---|
1273 | // utilitySpace.getUtility(opponentBid) +
|
---|
1274 | // this.AvgUtilitythreshold);
|
---|
1275 | this.concedeToOpponent = true;
|
---|
1276 | return false;
|
---|
1277 | }
|
---|
1278 | } else {
|
---|
1279 | return false;
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 | } catch (Exception e) {
|
---|
1283 | System.out.println(e.getMessage()
|
---|
1284 | + " Exception in method AcceptOpponentOffer");
|
---|
1285 | return true;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | /*
|
---|
1291 | * decide whether or not to terminate now
|
---|
1292 | */
|
---|
1293 | private boolean TerminateCurrentNegotiation(Bid ownBid) {
|
---|
1294 | double currentUtility = 0;
|
---|
1295 | double nextRoundUtility = 0;
|
---|
1296 | double maximumUtility = 0;
|
---|
1297 | this.concedeToOpponent = false;
|
---|
1298 | try {
|
---|
1299 | currentUtility = this.reservationValue;
|
---|
1300 | nextRoundUtility = this.utilitySpace.getUtility(ownBid);
|
---|
1301 | maximumUtility = this.MaximumUtility;
|
---|
1302 |
|
---|
1303 | if (this.discountingFactor == 1 || this.reservationValue == 0) {
|
---|
1304 | return false;
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | if (currentUtility >= nextRoundUtility) {
|
---|
1308 | return true;
|
---|
1309 | } else {
|
---|
1310 | // if the current reseravation utility with discount is larger
|
---|
1311 | // than the predicted maximum utility with discount
|
---|
1312 | // then terminate the negotiation.
|
---|
1313 | double predictMaximumUtility = maximumUtility
|
---|
1314 | * this.discountingFactor;
|
---|
1315 | double currentMaximumUtility = this.utilitySpace
|
---|
1316 | .getReservationValueWithDiscount(timeline);
|
---|
1317 | // System.out.println("the current reserved value is "+
|
---|
1318 | // this.reservationValue+" after discounting is
|
---|
1319 | // "+currentMaximumUtility);
|
---|
1320 | if (currentMaximumUtility > predictMaximumUtility
|
---|
1321 | && timeline.getTime() > this.avgConcedeTime) {
|
---|
1322 | return true;
|
---|
1323 | } else {
|
---|
1324 | return false;
|
---|
1325 | }
|
---|
1326 | }
|
---|
1327 | } catch (Exception e) {
|
---|
1328 | System.out.println(e.getMessage()
|
---|
1329 | + " Exception in method TerminateCurrentNegotiation");
|
---|
1330 | return true;
|
---|
1331 | }
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | /*
|
---|
1335 | * estimate the number of rounds left before reaching the deadline @param
|
---|
1336 | * opponent @return
|
---|
1337 | */
|
---|
1338 | private int estimateRoundLeft(boolean opponent) {
|
---|
1339 | double round;
|
---|
1340 | try {
|
---|
1341 | if (opponent == true) {
|
---|
1342 | if (this.timeLeftBefore
|
---|
1343 | - this.timeLeftAfter > this.maximumTimeOfOpponent) {
|
---|
1344 | this.maximumTimeOfOpponent = this.timeLeftBefore
|
---|
1345 | - this.timeLeftAfter;
|
---|
1346 | }
|
---|
1347 | } else {
|
---|
1348 | if (this.timeLeftAfter
|
---|
1349 | - this.timeLeftBefore > this.maximumTimeOfOwn) {
|
---|
1350 | this.maximumTimeOfOwn = this.timeLeftAfter
|
---|
1351 | - this.timeLeftBefore;
|
---|
1352 | }
|
---|
1353 | }
|
---|
1354 | if (this.maximumTimeOfOpponent + this.maximumTimeOfOwn == 0) {
|
---|
1355 | System.out.println("divided by zero exception");
|
---|
1356 | }
|
---|
1357 | round = (this.totalTime - timeline.getCurrentTime())
|
---|
1358 | / (this.maximumTimeOfOpponent + this.maximumTimeOfOwn);
|
---|
1359 | // System.out.println("current time is " +
|
---|
1360 | // timeline.getElapsedSeconds() + "---" + round + "----" +
|
---|
1361 | // this.maximumTimeOfOpponent);
|
---|
1362 | } catch (Exception e) {
|
---|
1363 | System.out.println(e.getMessage()
|
---|
1364 | + " Exception in method TerminateCurrentNegotiation");
|
---|
1365 | return 20;
|
---|
1366 | }
|
---|
1367 | return ((int) (round));
|
---|
1368 | }
|
---|
1369 |
|
---|
1370 | /*
|
---|
1371 | * pre-processing to save the computational time each round
|
---|
1372 | */
|
---|
1373 | private void calculateBidsBetweenUtility() {
|
---|
1374 | try {
|
---|
1375 | this.MinimumUtility = Math.min(this.agentData1.MinimumUtility,
|
---|
1376 | this.agentData2.MinimumUtility);
|
---|
1377 | this.SpacebetweenDivisions = (this.MaximumUtility
|
---|
1378 | - this.MinimumUtility) / this.NumberofDivisions;
|
---|
1379 | // initalization for each LinkedList storing the bids between each
|
---|
1380 | // range
|
---|
1381 | this.bidsBetweenUtility = new LinkedList<LinkedList<Bid>>();
|
---|
1382 | for (int i = 0; i < this.NumberofDivisions; i++) {
|
---|
1383 | LinkedList<Bid> BidList = new LinkedList<Bid>();
|
---|
1384 | // BidList.add(this.bid_maximum_utility);
|
---|
1385 | this.bidsBetweenUtility.add(i, BidList);
|
---|
1386 | }
|
---|
1387 | // this.bidsBetweenUtility.get(this.NumberofDivisions-1).add(this.bid_maximum_utility);
|
---|
1388 | // note that here we may need to use some trick to reduce the
|
---|
1389 | // computation cost (to be checked later);
|
---|
1390 | // add those bids in each range into the corresponding LinkedList
|
---|
1391 | BidIterator myBidIterator = new BidIterator(
|
---|
1392 | this.utilitySpace.getDomain());
|
---|
1393 | while (myBidIterator.hasNext()) {
|
---|
1394 | Bid b = myBidIterator.next();
|
---|
1395 | for (int i = 0; i < this.NumberofDivisions; i++) {
|
---|
1396 | if (this.utilitySpace.getUtility(
|
---|
1397 | b) <= (i + 1) * this.SpacebetweenDivisions
|
---|
1398 | + this.MinimumUtility
|
---|
1399 | && this.utilitySpace.getUtility(
|
---|
1400 | b) >= i * this.SpacebetweenDivisions
|
---|
1401 | + this.MinimumUtility) {
|
---|
1402 | this.bidsBetweenUtility.get(i).add(b);
|
---|
1403 | break;
|
---|
1404 | }
|
---|
1405 | }
|
---|
1406 | }
|
---|
1407 | } catch (Exception e) {
|
---|
1408 | System.out.println(e.getMessage()
|
---|
1409 | + " Exception in method calculateBidsBetweenUtility");
|
---|
1410 | }
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | private LinkedList<Bid> calculateBidsAboveUtility(double bidutil) {
|
---|
1414 | BidIterator myBidIterator = null;
|
---|
1415 | myBidIterator = new BidIterator(this.utilitySpace.getDomain());
|
---|
1416 |
|
---|
1417 | // initalization for each LinkedList storing the bids between each range
|
---|
1418 | LinkedList<Bid> Bids = new LinkedList<Bid>();
|
---|
1419 | try {
|
---|
1420 | // note that here we may need to use some trick to reduce the
|
---|
1421 | // computation cost (to be checked later);
|
---|
1422 | // add those bids in each range into the corresponding LinkedList
|
---|
1423 | while (myBidIterator.hasNext()) {
|
---|
1424 | Bid b = myBidIterator.next();
|
---|
1425 | if (this.utilitySpace.getUtility(b) > bidutil) {
|
---|
1426 | Bids.add(b);
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 | } catch (Exception e) {
|
---|
1430 | System.out.println(e.getMessage()
|
---|
1431 | + " Exception in method calculateBidsAboveUtility");
|
---|
1432 | }
|
---|
1433 | return Bids;
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | private Bid RandomSearchBid() throws Exception {
|
---|
1437 | HashMap<Integer, Value> values = new HashMap<Integer, Value>();
|
---|
1438 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
1439 | Bid bid = null;
|
---|
1440 |
|
---|
1441 | for (Issue lIssue : issues) {
|
---|
1442 | Random random = new Random();
|
---|
1443 | switch (lIssue.getType()) {
|
---|
1444 | case DISCRETE:
|
---|
1445 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
1446 | int optionIndex = random
|
---|
1447 | .nextInt(lIssueDiscrete.getNumberOfValues());
|
---|
1448 | values.put(lIssue.getNumber(),
|
---|
1449 | lIssueDiscrete.getValue(optionIndex));
|
---|
1450 | break;
|
---|
1451 | case REAL:
|
---|
1452 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
1453 | int optionInd = random.nextInt(
|
---|
1454 | lIssueReal.getNumberOfDiscretizationSteps() - 1);
|
---|
1455 | values.put(lIssueReal.getNumber(),
|
---|
1456 | new ValueReal(lIssueReal.getLowerBound() + (lIssueReal
|
---|
1457 | .getUpperBound() - lIssueReal.getLowerBound())
|
---|
1458 | * (optionInd) / (lIssueReal
|
---|
1459 | .getNumberOfDiscretizationSteps())));
|
---|
1460 | break;
|
---|
1461 | case INTEGER:
|
---|
1462 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
1463 | int optionIndex2 = lIssueInteger.getLowerBound()
|
---|
1464 | + random.nextInt(lIssueInteger.getUpperBound()
|
---|
1465 | - lIssueInteger.getLowerBound());
|
---|
1466 | values.put(lIssueInteger.getNumber(),
|
---|
1467 | new ValueInteger(optionIndex2));
|
---|
1468 | break;
|
---|
1469 | default:
|
---|
1470 | throw new Exception("issue type " + lIssue.getType()
|
---|
1471 | + " not supported. Exception in method RandomSearchBid");
|
---|
1472 | }
|
---|
1473 | }
|
---|
1474 | bid = new Bid(utilitySpace.getDomain(), values);
|
---|
1475 | return bid;
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | /*
|
---|
1479 | * Get all the bids within a given utility range.
|
---|
1480 | */
|
---|
1481 | private List<Bid> getBidsBetweenUtility(double lowerBound,
|
---|
1482 | double upperBound) {
|
---|
1483 | List<Bid> bidsInRange = new LinkedList<Bid>();
|
---|
1484 | try {
|
---|
1485 | int range = (int) ((upperBound - this.minimumUtilityThreshold)
|
---|
1486 | / 0.01);
|
---|
1487 | int initial = (int) ((lowerBound - this.minimumUtilityThreshold)
|
---|
1488 | / 0.01);
|
---|
1489 | // System.out.println(range+"---"+initial);
|
---|
1490 | for (int i = initial; i < range; i++) {
|
---|
1491 | bidsInRange.addAll(i, this.bidsBetweenUtility.get(i));
|
---|
1492 | }
|
---|
1493 | if (bidsInRange.isEmpty()) {
|
---|
1494 | bidsInRange.add(range - 1, this.bid_maximum_utility);
|
---|
1495 | }
|
---|
1496 | } catch (Exception e) {
|
---|
1497 | System.out.println(e.getMessage()
|
---|
1498 | + " Exception in method getBidsBetweenUtility");
|
---|
1499 | }
|
---|
1500 | return bidsInRange;
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 | /*
|
---|
1504 | * determine concede-to-time degree based on the discounting factor.
|
---|
1505 | */
|
---|
1506 | private void chooseConcedeToDiscountingDegree() {
|
---|
1507 | try {
|
---|
1508 | double alpha = 0;
|
---|
1509 | double beta = 1.5;// 1.3;//this value controls the rate at which the
|
---|
1510 | // agent concedes to the discouting factor.
|
---|
1511 | // the larger beta is, the more the agent makes concesions.
|
---|
1512 | // if (utilitySpace.getDomain().getNumberOfPossibleBids() > 100) {
|
---|
1513 | /*
|
---|
1514 | * if (this.maximumOfBid > 100) { beta = 2;//1.3; } else { beta =
|
---|
1515 | * 1.5; }
|
---|
1516 | */
|
---|
1517 | // the vaule of beta depends on the discounting factor (trade-off
|
---|
1518 | // between concede-to-time degree and discouting factor)
|
---|
1519 | if (this.discountingFactor > 0.75) {
|
---|
1520 | beta = 1.8;
|
---|
1521 | } else if (this.discountingFactor > 0.5) {
|
---|
1522 | beta = 1.5;
|
---|
1523 | } else {
|
---|
1524 | beta = 1.2;
|
---|
1525 | }
|
---|
1526 | alpha = Math.pow(this.discountingFactor, beta);
|
---|
1527 | this.avgConcedeTime = this.minConcedeTime
|
---|
1528 | + (1 - this.minConcedeTime) * alpha;
|
---|
1529 | this.concedeTime_original = this.avgConcedeTime;
|
---|
1530 | // System.out.println("concedeToDiscountingFactor is " +
|
---|
1531 | // this.AvgConcedeTime + "current time is " + timeline.getTime());
|
---|
1532 | } catch (Exception e) {
|
---|
1533 | System.out.println(e.getMessage()
|
---|
1534 | + " Exception in method chooseConcedeToDiscountingDegree");
|
---|
1535 | }
|
---|
1536 | }
|
---|
1537 |
|
---|
1538 | /*
|
---|
1539 | * update the concede-to-time degree based on the predicted toughness degree
|
---|
1540 | * of the opponent
|
---|
1541 | */
|
---|
1542 |
|
---|
1543 | private Bid regeneratebid(double bidUtil) {
|
---|
1544 | Bid ans = null;
|
---|
1545 | LinkedList<Bid> Bids = new LinkedList<Bid>();
|
---|
1546 | // LinkedList <Bid> Bids = calculateBidsAboveUtility(bidutil);
|
---|
1547 | this.agentData1.maxScore = -1;
|
---|
1548 | this.agentData2.maxScore = -1;
|
---|
1549 | this.agentData1.avgScore = 0;
|
---|
1550 | this.agentData2.avgScore = 0;
|
---|
1551 | try {
|
---|
1552 | // if(this.OppFinalBids1.get(this.storingcapacity - 1) == null ||
|
---|
1553 | // this.OppFinalBids2.get(this.storingcapacity - 1) == null)
|
---|
1554 | // {
|
---|
1555 | // ans = this.bid_maximum_utility;
|
---|
1556 | // }
|
---|
1557 | // else
|
---|
1558 | // {
|
---|
1559 | // if(debug)
|
---|
1560 | // {
|
---|
1561 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1562 | // System.setOut(file);
|
---|
1563 | // System.out.println("----regeneatebid---- bidUtil:" + bidUtil);
|
---|
1564 | // }
|
---|
1565 | // if(this.numberOfBids > 1000)
|
---|
1566 | // {
|
---|
1567 | int check = 0;
|
---|
1568 | for (this.CurrentrangeNumber = this.NumberofDivisions
|
---|
1569 | - 1; check == 0; this.CurrentrangeNumber--) {
|
---|
1570 | if (bidUtil > ((this.CurrentrangeNumber + 1)
|
---|
1571 | * this.SpacebetweenDivisions + this.MinimumUtility)) {
|
---|
1572 | break;
|
---|
1573 | }
|
---|
1574 | Bids.addAll(
|
---|
1575 | this.bidsBetweenUtility.get(this.CurrentrangeNumber));
|
---|
1576 | }
|
---|
1577 | // }
|
---|
1578 | // else
|
---|
1579 | // {
|
---|
1580 | // BidIterator myBidIterator = new
|
---|
1581 | // BidIterator(this.utilitySpace.getDomain());
|
---|
1582 | // for (;myBidIterator.hasNext();)
|
---|
1583 | // {
|
---|
1584 | // Bid bid = myBidIterator.next();
|
---|
1585 | // if(bidUtil <= this.utilitySpace.getUtility(bid))
|
---|
1586 | // {
|
---|
1587 | // // if(debug)
|
---|
1588 | // // {
|
---|
1589 | // // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1590 | // // System.setOut(file);
|
---|
1591 | // // System.out.println("myBidIterator:" +
|
---|
1592 | // this.utilitySpace.getUtility(bid));
|
---|
1593 | // // }
|
---|
1594 | // Bids.add(bid);
|
---|
1595 | // }
|
---|
1596 | // }
|
---|
1597 | // }
|
---|
1598 | if (Bids.isEmpty()) {
|
---|
1599 | ans = this.myLastBid;
|
---|
1600 | } else {
|
---|
1601 | // if(debug)
|
---|
1602 | // {
|
---|
1603 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1604 | // System.setOut(file);
|
---|
1605 | // System.out.println("Enter loop!");
|
---|
1606 | // }
|
---|
1607 | LinkedList<Bid> Bidsconsider = new LinkedList<Bid>();
|
---|
1608 | if (Bids.size() >= this.maxNumOfBids) {
|
---|
1609 | int i = 0;
|
---|
1610 | while (i < this.maxNumOfBids) {
|
---|
1611 | // boolean isContinue = true;
|
---|
1612 | // int oldSize = Bids.size();
|
---|
1613 | int ran = (int) (Math.random() * Bids.size());
|
---|
1614 | // for(Bid rejectedBid: this.RejectedBids)
|
---|
1615 | // {
|
---|
1616 | // //if(this.utilitySpace.getUtility(Bids.get(ran)) ==
|
---|
1617 | // this.utilitySpace.getUtility(rejectedBid))
|
---|
1618 | // if(Bids.get(ran).equals(rejectedBid))
|
---|
1619 | // {
|
---|
1620 | // Bids.remove(ran);
|
---|
1621 | // isContinue = false;
|
---|
1622 | // break;
|
---|
1623 | // }
|
---|
1624 | // }
|
---|
1625 | // Bids = removeRejectedBid(Bids, ran);
|
---|
1626 | // if(isContinue)
|
---|
1627 | // {
|
---|
1628 | Bidsconsider.add(Bids.remove(ran));
|
---|
1629 | // }
|
---|
1630 | i++;
|
---|
1631 | }
|
---|
1632 | Bids = Bidsconsider;
|
---|
1633 | }
|
---|
1634 | // else
|
---|
1635 | // {
|
---|
1636 | // for(int i = 0; i < Bids.size(); i++)
|
---|
1637 | // {
|
---|
1638 | // boolean isContinue = true;
|
---|
1639 | // for(Bid rejectedBid: this.RejectedBids)
|
---|
1640 | // {
|
---|
1641 | // //if(this.utilitySpace.getUtility(Bids.get(ran)) ==
|
---|
1642 | // this.utilitySpace.getUtility(rejectedBid))
|
---|
1643 | // if(Bids.get(i).equals(rejectedBid))
|
---|
1644 | // {
|
---|
1645 | // isContinue = false;
|
---|
1646 | // break;
|
---|
1647 | // }
|
---|
1648 | // }
|
---|
1649 | // if(isContinue)
|
---|
1650 | // {
|
---|
1651 | // Bidsconsider.add(Bids.get(i));
|
---|
1652 | // }
|
---|
1653 | // }
|
---|
1654 | // }
|
---|
1655 | // Bids = Bidsconsider;
|
---|
1656 | // if(debug)
|
---|
1657 | // {
|
---|
1658 | // System.out.println(">0.95!");
|
---|
1659 | // }
|
---|
1660 | if (Bids.isEmpty()) {
|
---|
1661 | ans = this.myLastBid;
|
---|
1662 | } else {
|
---|
1663 | this.agentData1.issueScoreBids = new LinkedList<Double>();
|
---|
1664 | this.agentData2.issueScoreBids = new LinkedList<Double>();
|
---|
1665 | // this.agentData1.ChangeIssueMaxScore();
|
---|
1666 | // this.agentData2.ChangeIssueMaxScore();
|
---|
1667 | for (Bid Bid1 : Bids) {
|
---|
1668 | // if(debug)
|
---|
1669 | // {
|
---|
1670 | // System.out.println("Enter second for loop! i=" + i);
|
---|
1671 | // }
|
---|
1672 | // Cal Total score From all Bids and add it to
|
---|
1673 | // agentData's List
|
---|
1674 | this.agentData1.calculateBidScore(Bid1);
|
---|
1675 | this.agentData2.calculateBidScore(Bid1);
|
---|
1676 | }
|
---|
1677 | double min = 1.1;
|
---|
1678 | double dist;
|
---|
1679 | LinkedList<Double> distList = new LinkedList<Double>();
|
---|
1680 | for (int i = 0; i < Bids.size(); i++) {
|
---|
1681 | // temp = (Issuescorebid.get(i)/this.maxScore * 1 / 5) +
|
---|
1682 | // (this.bidsUtilityScore.get(Bids.get(i)) * 4 / 5);
|
---|
1683 | Bid bid = Bids.get(i);
|
---|
1684 | double agent1BidScore = this.agentData1.issueScoreBids
|
---|
1685 | .get(i) / this.agentData1.maxScore;
|
---|
1686 | double agent2BidScore = this.agentData2.issueScoreBids
|
---|
1687 | .get(i) / this.agentData2.maxScore;
|
---|
1688 | double ourBidScore = this.utilitySpace.getUtility(bid);
|
---|
1689 | dist = (1 - agent1BidScore) * (1 - agent1BidScore)
|
---|
1690 | + (1 - agent2BidScore) * (1 - agent2BidScore)
|
---|
1691 | + (1 - ourBidScore) * (1 - ourBidScore);
|
---|
1692 | // if(debug)
|
---|
1693 | // {
|
---|
1694 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1695 | // true));
|
---|
1696 | // System.setOut(file);
|
---|
1697 | // System.out.println("Bid:" +
|
---|
1698 | // this.utilitySpace.getUtility(bid) + ", dist:" +
|
---|
1699 | // dist);
|
---|
1700 | // System.out.println("agent1BidScore:" +
|
---|
1701 | // this.agentData1.issueScoreBids.get(i)
|
---|
1702 | // +"/"+this.agentData1.maxScore + " = " +
|
---|
1703 | // agent1BidScore);
|
---|
1704 | // System.out.println("agent2BidScore:" +
|
---|
1705 | // this.agentData2.issueScoreBids.get(i)
|
---|
1706 | // +"/"+this.agentData2.maxScore + " = " +
|
---|
1707 | // agent2BidScore);
|
---|
1708 | // }
|
---|
1709 | distList.add(dist);
|
---|
1710 | if (dist < min) {
|
---|
1711 | min = dist;
|
---|
1712 | ans = bid;
|
---|
1713 | // if(debug)
|
---|
1714 | // {
|
---|
1715 | // file = new PrintStream(new
|
---|
1716 | // FileOutputStream(fileName, true));
|
---|
1717 | // System.setOut(file);
|
---|
1718 | // System.out.println("Ans Bid:" +
|
---|
1719 | // this.utilitySpace.getUtility(ans) +
|
---|
1720 | // ", Max Score:" + max);
|
---|
1721 | // for (Issue Issue1 : this.Issues)
|
---|
1722 | // {
|
---|
1723 | // int issueNum = Issue1.getNumber();
|
---|
1724 | // switch (Issue1.getType())
|
---|
1725 | // {
|
---|
1726 | // case DISCRETE:
|
---|
1727 | // IssueDiscrete lIssueDiscrete =
|
---|
1728 | // (IssueDiscrete)Issue1;
|
---|
1729 | // ValueDiscrete value1 = (ValueDiscrete)
|
---|
1730 | // ans.getValue(issueNum);
|
---|
1731 | // int index = lIssueDiscrete.getValueIndex(value1);
|
---|
1732 | // if(debug)
|
---|
1733 | // {
|
---|
1734 | // file = new PrintStream(new
|
---|
1735 | // FileOutputStream(fileName, true));
|
---|
1736 | // System.setOut(file);
|
---|
1737 | // System.out.println("DISCRETE - IssueNum:" +
|
---|
1738 | // issueNum + ", Index:" + index + ", Score:" +
|
---|
1739 | // this.issueScore.get(lIssueDiscrete.getNumber() -
|
---|
1740 | // 1).get(index) /
|
---|
1741 | // this.issueMaxScore.get(lIssueDiscrete.getNumber()
|
---|
1742 | // - 1));
|
---|
1743 | // }
|
---|
1744 | // break;
|
---|
1745 | // case REAL:
|
---|
1746 | // IssueReal lIssueReal = (IssueReal) Issue1;
|
---|
1747 | // ValueReal valueReal = (ValueReal)
|
---|
1748 | // ans.getValue(issueNum);
|
---|
1749 | // int indexReal = (int)((valueReal.getValue() -
|
---|
1750 | // lIssueReal.getLowerBound()) /
|
---|
1751 | // (lIssueReal.getUpperBound() -
|
---|
1752 | // lIssueReal.getLowerBound()) *
|
---|
1753 | // lIssueReal.getNumberOfDiscretizationSteps());
|
---|
1754 | // if(debug)
|
---|
1755 | // {
|
---|
1756 | // file = new PrintStream(new
|
---|
1757 | // FileOutputStream(fileName, true));
|
---|
1758 | // System.setOut(file);
|
---|
1759 | // System.out.println("REAL - IssueNum:" + issueNum
|
---|
1760 | // + ", Index:" + indexReal + ", Score:" +
|
---|
1761 | // this.issueScore.get(lIssueReal.getNumber() -
|
---|
1762 | // 1).get(indexReal) /
|
---|
1763 | // this.issueMaxScore.get(lIssueReal.getNumber() -
|
---|
1764 | // 1));
|
---|
1765 | // }
|
---|
1766 | // break;
|
---|
1767 | // case INTEGER:
|
---|
1768 | // IssueInteger lIssueInteger = (IssueInteger)
|
---|
1769 | // Issue1;
|
---|
1770 | // ValueInteger valueInteger = (ValueInteger)
|
---|
1771 | // ans.getValue(issueNum);
|
---|
1772 | // int indexInteger = valueInteger.getValue();
|
---|
1773 | // if(debug)
|
---|
1774 | // {
|
---|
1775 | // file = new PrintStream(new
|
---|
1776 | // FileOutputStream(fileName, true));
|
---|
1777 | // System.setOut(file);
|
---|
1778 | // System.out.println("INTEGER - IssueNum:" +
|
---|
1779 | // issueNum + ", Index:" + indexInteger + ", Score:"
|
---|
1780 | // + this.issueScore.get(lIssueInteger.getNumber() -
|
---|
1781 | // 1).get(indexInteger).doubleValue() /
|
---|
1782 | // this.issueMaxScore.get(lIssueInteger.getNumber()
|
---|
1783 | // - 1));
|
---|
1784 | // }
|
---|
1785 | // break;
|
---|
1786 | // }
|
---|
1787 | // }
|
---|
1788 | // }
|
---|
1789 |
|
---|
1790 | } else if (dist == min && this.utilitySpace.getUtility(
|
---|
1791 | bid) > this.utilitySpace.getUtility(ans)) {
|
---|
1792 | ans = bid;
|
---|
1793 | }
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 | if (Math.random() > 0.95) {
|
---|
1797 | LinkedList<Bid> sortedBidsList = SortBidsList(Bids,
|
---|
1798 | distList);
|
---|
1799 | ans = sortedBidsList.get(sortedBidsList.size() / 2
|
---|
1800 | + (int) (Math.random() * (Bids.size()
|
---|
1801 | - sortedBidsList.size() / 2)));
|
---|
1802 | // if(debug)
|
---|
1803 | // {
|
---|
1804 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
1805 | // true));
|
---|
1806 | // System.setOut(file);
|
---|
1807 | // System.out.println(">0.95! rand ans:" +
|
---|
1808 | // this.utilitySpace.getUtility(ans));
|
---|
1809 | // }
|
---|
1810 | }
|
---|
1811 | }
|
---|
1812 | }
|
---|
1813 | // }
|
---|
1814 | // if(debug)
|
---|
1815 | // {
|
---|
1816 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1817 | // System.setOut(file);
|
---|
1818 | // System.out.println("ans:" + this.utilitySpace.getUtility(ans));
|
---|
1819 | // }
|
---|
1820 | } catch (Exception e) {
|
---|
1821 | System.out.println(
|
---|
1822 | e.getMessage() + " Exception in method regeneratebid");
|
---|
1823 | ans = this.bid_maximum_utility;
|
---|
1824 | }
|
---|
1825 |
|
---|
1826 | return ans;
|
---|
1827 | }
|
---|
1828 |
|
---|
1829 | private HashMap<Bid, Double> UpdateBidsUtilityScore(
|
---|
1830 | HashMap<Bid, Double> bidsUtilityScore) {
|
---|
1831 | try {
|
---|
1832 | bidsUtilityScore = new HashMap<Bid, Double>();
|
---|
1833 |
|
---|
1834 | BidIterator myBidIterator = new BidIterator(
|
---|
1835 | this.utilitySpace.getDomain());
|
---|
1836 | for (; myBidIterator.hasNext();) {
|
---|
1837 | Bid bid = myBidIterator.next();
|
---|
1838 | bidsUtilityScore.put(bid, (this.utilitySpace.getUtility(bid)
|
---|
1839 | / this.MaximumUtility));
|
---|
1840 | }
|
---|
1841 | } catch (Exception e) {
|
---|
1842 | System.out.println(
|
---|
1843 | "Exception in UpdateBidsUtilityScore: " + e.getMessage());
|
---|
1844 | }
|
---|
1845 | return bidsUtilityScore;
|
---|
1846 | }
|
---|
1847 |
|
---|
1848 | private AgentData updateConcedeDegree_smallDF(AgentData agentData) {
|
---|
1849 | double gama = 10;
|
---|
1850 | double weight = 0.1;
|
---|
1851 | double opponnetToughnessDegree = 1;
|
---|
1852 |
|
---|
1853 | try {
|
---|
1854 | if (agentData.agentNum.equals(this.string_agentData1Num)) {
|
---|
1855 | opponnetToughnessDegree = this.opponentBidHistory1
|
---|
1856 | .getConcessionDegree();
|
---|
1857 | // if(debug)
|
---|
1858 | // {
|
---|
1859 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1860 | // System.setOut(file);
|
---|
1861 | // System.out.println("agentData1 - getConcessionDegree:" +
|
---|
1862 | // opponnetToughnessDegree);
|
---|
1863 | // }
|
---|
1864 | } else {
|
---|
1865 | opponnetToughnessDegree = this.opponentBidHistory2
|
---|
1866 | .getConcessionDegree();
|
---|
1867 | // if(debug)
|
---|
1868 | // {
|
---|
1869 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1870 | // System.setOut(file);
|
---|
1871 | // System.out.println("agentData2 - getConcessionDegree:" +
|
---|
1872 | // opponnetToughnessDegree);
|
---|
1873 | // }
|
---|
1874 | }
|
---|
1875 |
|
---|
1876 | agentData = updateConcedeDegree_UpdateMinU(agentData, "Small");
|
---|
1877 | double temp = this.concedeTime_original
|
---|
1878 | + weight * (1 - this.concedeTime_original)
|
---|
1879 | * Math.pow(opponnetToughnessDegree, gama);
|
---|
1880 | agentData = updateConcedeDegree_smallDF_UpdateConcedeTime(agentData,
|
---|
1881 | temp);
|
---|
1882 | // if(debug)
|
---|
1883 | // {
|
---|
1884 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1885 | // System.setOut(file);
|
---|
1886 | // System.out.println("concedeTime:" + agentData.concedeTime);
|
---|
1887 | // }
|
---|
1888 | } catch (Exception e) {
|
---|
1889 | System.out.println(e.getMessage()
|
---|
1890 | + " Exception in method updateConcedeDegree_smallDF");
|
---|
1891 | }
|
---|
1892 | // System.out.println("concedeToDiscountingFactor is " +
|
---|
1893 | // this.concedeToDiscountingFactor + "current time is " +
|
---|
1894 | // timeline.getTime() + "original concedetodiscoutingfactor is " +
|
---|
1895 | // this.concedeToDiscountingFactor_original);
|
---|
1896 | return agentData;
|
---|
1897 | }
|
---|
1898 |
|
---|
1899 | private AgentData updateConcedeDegree_smallDF_UpdateConcedeTime(
|
---|
1900 | AgentData agentData, double newConcedeTime) {
|
---|
1901 | try {
|
---|
1902 | agentData.concedeTime = newConcedeTime;
|
---|
1903 | if (agentData.concedeTime >= 1) {
|
---|
1904 | agentData.concedeTime = 1;
|
---|
1905 | }
|
---|
1906 | } catch (Exception e) {
|
---|
1907 | System.out.println(e.getMessage()
|
---|
1908 | + " exception in method updateConcedeDegree_smallDF_UpdateConcedeTime");
|
---|
1909 | }
|
---|
1910 | // System.out.println("concedeToDiscountingFactor is " +
|
---|
1911 | // this.concedeToDiscountingFactor + "current time is " +
|
---|
1912 | // timeline.getTime() + "original concedetodiscoutingfactor is " +
|
---|
1913 | // this.concedeToDiscountingFactor_original);
|
---|
1914 | return agentData;
|
---|
1915 | }
|
---|
1916 |
|
---|
1917 | private AgentData updateConcedeDegree_UpdateMinU(AgentData agentData,
|
---|
1918 | String DFname) {
|
---|
1919 | try {
|
---|
1920 | if (agentData.IsOppFirstBid) {
|
---|
1921 | // if(debug)
|
---|
1922 | // {
|
---|
1923 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
1924 | // System.setOut(file);
|
---|
1925 | // System.out.println("Enter updateConcedeDegree_UpdateMinU");
|
---|
1926 | // }
|
---|
1927 | if (DFname.equals("Small")) {
|
---|
1928 | if (this.reservationValue <= agentData.oppFirstBidUtility) {
|
---|
1929 | agentData.MinimumUtility = agentData.oppFirstBidUtility;
|
---|
1930 | }
|
---|
1931 | } else {
|
---|
1932 | LinkedList<Double> bidsUtil = new LinkedList();
|
---|
1933 | LinkedList<Bid> Bids = new LinkedList<Bid>();
|
---|
1934 | BidIterator myBidIterator = new BidIterator(
|
---|
1935 | this.utilitySpace.getDomain());
|
---|
1936 | for (; myBidIterator.hasNext();) {
|
---|
1937 | Bid bid = myBidIterator.next();
|
---|
1938 | bidsUtil.add(this.utilitySpace.getUtility(bid));
|
---|
1939 | Bids.add(bid);
|
---|
1940 | }
|
---|
1941 | double relSumUtility = 0;
|
---|
1942 | double relCountUtility = 0;
|
---|
1943 |
|
---|
1944 | if (this.domainSize > 100) {
|
---|
1945 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
1946 | double bidUtil = (Double) e.next();
|
---|
1947 | if (agentData.utility_FirstMaximum < bidUtil) {
|
---|
1948 | agentData.utility_FirstMaximum = bidUtil;
|
---|
1949 | } else if (agentData.utility_SecondMaximum < bidUtil) {
|
---|
1950 | agentData.utility_SecondMaximum = bidUtil;
|
---|
1951 | }
|
---|
1952 |
|
---|
1953 | if (bidUtil >= agentData.oppFirstBidUtility) {
|
---|
1954 | relSumUtility += bidUtil;
|
---|
1955 | relCountUtility += 1;
|
---|
1956 | }
|
---|
1957 | }
|
---|
1958 | agentData = calMinU(bidsUtil, agentData, relSumUtility,
|
---|
1959 | relCountUtility);
|
---|
1960 | } else {
|
---|
1961 | double relAvgUtility = 0;
|
---|
1962 | double relSqRootOfAvgUtility = 0;
|
---|
1963 |
|
---|
1964 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
1965 | double bidUtil = (Double) e.next();
|
---|
1966 | if (agentData.utility_FirstMaximum < bidUtil) {
|
---|
1967 | agentData.utility_FirstMaximum = bidUtil;
|
---|
1968 | } else if (agentData.utility_SecondMaximum < bidUtil) {
|
---|
1969 | agentData.utility_SecondMaximum = bidUtil;
|
---|
1970 | }
|
---|
1971 |
|
---|
1972 | if (bidUtil >= agentData.oppFirstBidUtility) {
|
---|
1973 | relSumUtility += bidUtil;
|
---|
1974 | relCountUtility += 1;
|
---|
1975 | }
|
---|
1976 | }
|
---|
1977 |
|
---|
1978 | if (relCountUtility > (bidsUtil.size() / 2)) {
|
---|
1979 | agentData = calMinU(bidsUtil, agentData,
|
---|
1980 | relSumUtility, relCountUtility);
|
---|
1981 | } else {
|
---|
1982 | // if(debug)
|
---|
1983 | // {
|
---|
1984 | // file = new PrintStream(new
|
---|
1985 | // FileOutputStream(fileName, true));
|
---|
1986 | // System.setOut(file);
|
---|
1987 | // System.out.println("updateConcedeDegree_UpdateMinU:
|
---|
1988 | // numOfBids < 100, above medium:");
|
---|
1989 | // }
|
---|
1990 |
|
---|
1991 | LinkedList<Bid> sortedBidsList = SortBidsList(Bids);
|
---|
1992 | for (int i = sortedBidsList.size()
|
---|
1993 | / 2; i < sortedBidsList.size(); i++) {
|
---|
1994 | double bidUtil = this.utilitySpace
|
---|
1995 | .getUtility(sortedBidsList.get(i));
|
---|
1996 | // if(debug)
|
---|
1997 | // {
|
---|
1998 | // file = new PrintStream(new
|
---|
1999 | // FileOutputStream(fileName, true));
|
---|
2000 | // System.setOut(file);
|
---|
2001 | // System.out.println("Bid Utility:" + bidUtil);
|
---|
2002 | // }
|
---|
2003 | if (agentData.utility_FirstMaximum < bidUtil) {
|
---|
2004 | agentData.utility_FirstMaximum = bidUtil;
|
---|
2005 | } else if (agentData.utility_SecondMaximum < bidUtil) {
|
---|
2006 | agentData.utility_SecondMaximum = bidUtil;
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | relSumUtility += bidUtil;
|
---|
2010 | relCountUtility += 1;
|
---|
2011 | }
|
---|
2012 |
|
---|
2013 | relAvgUtility = relSumUtility / relCountUtility;
|
---|
2014 | for (Iterator f = bidsUtil.iterator(); f
|
---|
2015 | .hasNext();) {
|
---|
2016 | double bidUtil = (Double) f.next();
|
---|
2017 |
|
---|
2018 | if (bidUtil >= agentData.oppFirstBidUtility) {
|
---|
2019 | relSqRootOfAvgUtility += (bidUtil
|
---|
2020 | - relAvgUtility)
|
---|
2021 | * (bidUtil - relAvgUtility);
|
---|
2022 | }
|
---|
2023 | }
|
---|
2024 | agentData.relStdevUtility = Math.sqrt(
|
---|
2025 | relSqRootOfAvgUtility / relCountUtility);
|
---|
2026 | agentData.minThreshold = relAvgUtility;
|
---|
2027 | }
|
---|
2028 | }
|
---|
2029 |
|
---|
2030 | // if(debug)
|
---|
2031 | // {
|
---|
2032 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
2033 | // true));
|
---|
2034 | // System.setOut(file);
|
---|
2035 | // System.out.println("Before minThreshold:" +
|
---|
2036 | // agentData.minThreshold);
|
---|
2037 | // }
|
---|
2038 | agentData.minThreshold = CalWhetherOppFirstBidGoodEnough(
|
---|
2039 | agentData.minThreshold,
|
---|
2040 | agentData.oppFirstBidUtility);
|
---|
2041 | // if(debug)
|
---|
2042 | // {
|
---|
2043 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
2044 | // true));
|
---|
2045 | // System.setOut(file);
|
---|
2046 | // System.out.println("Middle minThreshold:" +
|
---|
2047 | // agentData.minThreshold);
|
---|
2048 | // }
|
---|
2049 | agentData.minThreshold = Compare_MinThreshold_And_SecondMax(
|
---|
2050 | agentData.minThreshold,
|
---|
2051 | agentData.utility_SecondMaximum);
|
---|
2052 | // if(debug)
|
---|
2053 | // {
|
---|
2054 | // file = new PrintStream(new FileOutputStream(fileName,
|
---|
2055 | // true));
|
---|
2056 | // System.setOut(file);
|
---|
2057 | // System.out.println("After minThreshold:" +
|
---|
2058 | // agentData.minThreshold);
|
---|
2059 | // }
|
---|
2060 | }
|
---|
2061 | agentData.IsOppFirstBid = false;
|
---|
2062 | }
|
---|
2063 | } catch (Exception e) {
|
---|
2064 | System.out.println(e.getMessage()
|
---|
2065 | + " exception in method updateConcedeDegree_UpdateMinU");
|
---|
2066 | }
|
---|
2067 | // System.out.println("concedeToDiscountingFactor is " +
|
---|
2068 | // this.concedeToDiscountingFactor + "current time is " +
|
---|
2069 | // timeline.getTime() + "original concedetodiscoutingfactor is " +
|
---|
2070 | // this.concedeToDiscountingFactor_original);
|
---|
2071 | return agentData;
|
---|
2072 | }
|
---|
2073 |
|
---|
2074 | private AgentData calMinU(LinkedList<Double> bidsUtil, AgentData agentData,
|
---|
2075 | double relSumUtility, double relCountUtility) {
|
---|
2076 | try {
|
---|
2077 | double relAvgUtility = 0;
|
---|
2078 | double relSqRootOfAvgUtility = 0;
|
---|
2079 | double relStdevUtility = 0;
|
---|
2080 |
|
---|
2081 | relAvgUtility = relSumUtility / relCountUtility;
|
---|
2082 |
|
---|
2083 | for (Iterator f = bidsUtil.iterator(); f.hasNext();) {
|
---|
2084 | double bidUtil = (Double) f.next();
|
---|
2085 |
|
---|
2086 | if (bidUtil >= agentData.oppFirstBidUtility) {
|
---|
2087 | relSqRootOfAvgUtility += (bidUtil - relAvgUtility)
|
---|
2088 | * (bidUtil - relAvgUtility);
|
---|
2089 | }
|
---|
2090 | }
|
---|
2091 | relStdevUtility = Math
|
---|
2092 | .sqrt(relSqRootOfAvgUtility / relCountUtility);
|
---|
2093 |
|
---|
2094 | if (relStdevUtility < 0.1) {
|
---|
2095 | relSqRootOfAvgUtility = 0;
|
---|
2096 | double relCountUtilityInSmallSD = 0;
|
---|
2097 | for (Iterator g = bidsUtil.iterator(); g.hasNext();) {
|
---|
2098 | double bidUtil = (Double) g.next();
|
---|
2099 |
|
---|
2100 | if (bidUtil >= agentData.oppFirstBidUtility
|
---|
2101 | && (bidUtil < (relAvgUtility - relStdevUtility)
|
---|
2102 | || bidUtil > (relAvgUtility
|
---|
2103 | + relStdevUtility))) {
|
---|
2104 | relSqRootOfAvgUtility += (bidUtil - relAvgUtility)
|
---|
2105 | * (bidUtil - relAvgUtility);
|
---|
2106 | relCountUtilityInSmallSD++;
|
---|
2107 | }
|
---|
2108 | }
|
---|
2109 | relStdevUtility = Math
|
---|
2110 | .sqrt(relSqRootOfAvgUtility / relCountUtilityInSmallSD);
|
---|
2111 | }
|
---|
2112 | agentData.relStdevUtility = relStdevUtility;
|
---|
2113 |
|
---|
2114 | if (relCountUtility < 51) {
|
---|
2115 | // if(debug)
|
---|
2116 | // {
|
---|
2117 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2118 | // System.setOut(file);
|
---|
2119 | // System.out.println("relCountUtility <= 50");
|
---|
2120 | // }
|
---|
2121 | agentData.minThreshold = relAvgUtility;
|
---|
2122 | } else {
|
---|
2123 | // if(debug)
|
---|
2124 | // {
|
---|
2125 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2126 | // System.setOut(file);
|
---|
2127 | // System.out.println("relCountUtility > 50");
|
---|
2128 | // System.out.println("RelAvg: " + relAvgUtility + "RelStd: " +
|
---|
2129 | // relStdevUtility);
|
---|
2130 | // }
|
---|
2131 | agentData.minThreshold = relAvgUtility + this.discountingFactor
|
---|
2132 | * relStdevUtility * this.reservationValue;
|
---|
2133 | }
|
---|
2134 | } catch (Exception e) {
|
---|
2135 | System.out.println(e.getMessage() + " exception in method calMinU");
|
---|
2136 | }
|
---|
2137 |
|
---|
2138 | return agentData;
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | private void updateConcedeDegree_largeDF(AgentData agentData) {
|
---|
2142 | try {
|
---|
2143 | double i = 0;
|
---|
2144 | agentData = updateConcedeDegree_UpdateMinU(agentData, "Large");
|
---|
2145 | agentData = MeasureConcedePartOfOppBehaviour(agentData);
|
---|
2146 |
|
---|
2147 | agentData.concedePartOfdiscountingFactor = this.discountingFactor
|
---|
2148 | - 1;
|
---|
2149 | agentData.concedePartOfOppBehaviour = (((((agentData.relCountLowerBoundMid2
|
---|
2150 | / agentData.relCountUpperBoundMid2)
|
---|
2151 | * agentData.slopeOfSlopeOfSessionMax2)
|
---|
2152 | - ((agentData.relCountLowerBoundMid1
|
---|
2153 | / agentData.relCountUpperBoundMid1)
|
---|
2154 | * agentData.slopeOfSlopeOfSessionMax1))
|
---|
2155 | / this.k) / agentData.relStdevUtility) - this.N;
|
---|
2156 | if (agentData.startConcede == true) {
|
---|
2157 | i = agentData.concedePartOfdiscountingFactor
|
---|
2158 | + agentData.concedePartOfOppBehaviour;
|
---|
2159 | agentData.concedeTime = Math.exp(i);
|
---|
2160 | if (agentData.concedeTime > 1) {
|
---|
2161 | agentData.concedeTime = 1;
|
---|
2162 | }
|
---|
2163 | } else {
|
---|
2164 | agentData.concedeTime = this.initialConcedeTime;
|
---|
2165 | }
|
---|
2166 | } catch (Exception e) {
|
---|
2167 | System.out.println(e.getMessage()
|
---|
2168 | + " exception in method updateConcedeDegree_largeDF");
|
---|
2169 | }
|
---|
2170 | }
|
---|
2171 |
|
---|
2172 | private AgentData MeasureConcedePartOfOppBehaviour(AgentData agentData) {
|
---|
2173 | try {
|
---|
2174 | agentData.count++;
|
---|
2175 |
|
---|
2176 | if (agentData.count < this.FirstTimeInterval) {
|
---|
2177 | if (utilitySpace.getUtility(
|
---|
2178 | agentData.oppPreviousBid) > agentData.utility_maximum_from_opponent_Session1) {
|
---|
2179 | agentData.utility_maximum_from_opponent_Session1 = utilitySpace
|
---|
2180 | .getUtility(agentData.oppPreviousBid);
|
---|
2181 | }
|
---|
2182 | } else if (agentData.count < this.SecondTimeInterval) {
|
---|
2183 | if (utilitySpace.getUtility(
|
---|
2184 | agentData.oppPreviousBid) > agentData.utility_maximum_from_opponent_Session2) {
|
---|
2185 | agentData.utility_maximum_from_opponent_Session2 = utilitySpace
|
---|
2186 | .getUtility(agentData.oppPreviousBid);
|
---|
2187 | }
|
---|
2188 | } else if (agentData.count < this.ThirdTimeInterval) {
|
---|
2189 | if (utilitySpace.getUtility(
|
---|
2190 | agentData.oppPreviousBid) > agentData.utility_maximum_from_opponent_Session3) {
|
---|
2191 | agentData.utility_maximum_from_opponent_Session3 = utilitySpace
|
---|
2192 | .getUtility(agentData.oppPreviousBid);
|
---|
2193 | }
|
---|
2194 | } else {
|
---|
2195 | agentData.relCountUpperBoundMid1 = 0;
|
---|
2196 | agentData.relCountUpperBoundMid2 = 0;
|
---|
2197 | agentData.relCountLowerBoundMid1 = 0;
|
---|
2198 | agentData.relCountLowerBoundMid2 = 0;
|
---|
2199 | agentData.midPointOfSlopeSessionMax1 = (agentData.utility_maximum_from_opponent_Session2
|
---|
2200 | + agentData.utility_maximum_from_opponent_Session1) / 2;
|
---|
2201 | agentData.midPointOfSlopeSessionMax2 = (agentData.utility_maximum_from_opponent_Session3
|
---|
2202 | + agentData.utility_maximum_from_opponent_Session2) / 2;
|
---|
2203 | agentData.slopeOfSlopeOfSessionMax1 = agentData.utility_maximum_from_opponent_Session2
|
---|
2204 | - agentData.utility_maximum_from_opponent_Session1;
|
---|
2205 | agentData.slopeOfSlopeOfSessionMax2 = agentData.utility_maximum_from_opponent_Session3
|
---|
2206 | - agentData.utility_maximum_from_opponent_Session2;
|
---|
2207 |
|
---|
2208 | LinkedList<Double> bidsUtil = new LinkedList();
|
---|
2209 | BidIterator myBidIterator = new BidIterator(
|
---|
2210 | this.utilitySpace.getDomain());
|
---|
2211 | for (; myBidIterator.hasNext();) {
|
---|
2212 | bidsUtil.add(
|
---|
2213 | this.utilitySpace.getUtility(myBidIterator.next()));
|
---|
2214 | }
|
---|
2215 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
2216 | double bidUtil = (Double) e.next();
|
---|
2217 | if (bidUtil >= agentData.midPointOfSlopeSessionMax1) {
|
---|
2218 | agentData.relCountUpperBoundMid1 += 1;
|
---|
2219 | } else {
|
---|
2220 | agentData.relCountLowerBoundMid1 += 1;
|
---|
2221 | }
|
---|
2222 |
|
---|
2223 | if (bidUtil >= agentData.midPointOfSlopeSessionMax2) {
|
---|
2224 | agentData.relCountUpperBoundMid2 += 1;
|
---|
2225 | } else {
|
---|
2226 | agentData.relCountLowerBoundMid2 += 1;
|
---|
2227 | }
|
---|
2228 | }
|
---|
2229 | agentData.utility_maximum_from_opponent_Session1 = agentData.utility_maximum_from_opponent_Session2;
|
---|
2230 | agentData.utility_maximum_from_opponent_Session2 = agentData.utility_maximum_from_opponent_Session3;
|
---|
2231 | agentData.utility_maximum_from_opponent_Session3 = 0;
|
---|
2232 | agentData.count = this.SecondTimeInterval - 1;
|
---|
2233 | agentData.startConcede = true;
|
---|
2234 | }
|
---|
2235 | } catch (Exception e) {
|
---|
2236 | System.out.println(e.getMessage()
|
---|
2237 | + " exception in method MeasureConcedePartOfOppBehaviour");
|
---|
2238 | }
|
---|
2239 | return agentData;
|
---|
2240 | }
|
---|
2241 |
|
---|
2242 | private AgentData updateConcedeDegree_nonDF(AgentData agentData) {
|
---|
2243 | try {
|
---|
2244 | if (agentData.IsOppFirstBid) {
|
---|
2245 | updateConcedeDegree_UpdateMinU(agentData, "Non");
|
---|
2246 | agentData.IsOppFirstBid = false;
|
---|
2247 | }
|
---|
2248 |
|
---|
2249 | // if(debug)
|
---|
2250 | // {
|
---|
2251 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2252 | // System.setOut(file);
|
---|
2253 | // System.out.println("Returned minThreshold:" +
|
---|
2254 | // agentData.minThreshold);
|
---|
2255 | // }
|
---|
2256 | // agentData.concedeTime = 0.85;
|
---|
2257 | } catch (Exception e) {
|
---|
2258 | System.out.println(e.getMessage()
|
---|
2259 | + " exception in method updateConcedeDegree_nonDF");
|
---|
2260 | }
|
---|
2261 |
|
---|
2262 | return agentData;
|
---|
2263 | }
|
---|
2264 |
|
---|
2265 | private LinkedList<Bid> SortBidsList(LinkedList<Bid> Bids) {
|
---|
2266 | LinkedList<Bid> sortedBidsList = new LinkedList<Bid>();
|
---|
2267 | try {
|
---|
2268 | HashMap<Bid, Double> sortedBidsMap = new HashMap<Bid, Double>();
|
---|
2269 |
|
---|
2270 | for (Bid bid : Bids) {
|
---|
2271 | sortedBidsMap.put(bid, this.utilitySpace.getUtility(bid));
|
---|
2272 | }
|
---|
2273 |
|
---|
2274 | List<Map.Entry<Bid, Double>> list_Data = new LinkedList<Map.Entry<Bid, Double>>(
|
---|
2275 | sortedBidsMap.entrySet());
|
---|
2276 |
|
---|
2277 | // Sorting
|
---|
2278 | Collections.sort(list_Data,
|
---|
2279 | new Comparator<Map.Entry<Bid, Double>>() {
|
---|
2280 | @Override
|
---|
2281 | public int compare(Map.Entry<Bid, Double> entry1,
|
---|
2282 | Map.Entry<Bid, Double> entry2) {
|
---|
2283 | return (entry1.getValue()
|
---|
2284 | .compareTo(entry2.getValue()));
|
---|
2285 | }
|
---|
2286 | });
|
---|
2287 |
|
---|
2288 | for (Map.Entry<Bid, Double> entry : list_Data) {
|
---|
2289 | sortedBidsList.add(entry.getKey());
|
---|
2290 | }
|
---|
2291 | } catch (Exception e) {
|
---|
2292 | System.out.println(
|
---|
2293 | e.getMessage() + " exception in method SortBidsList");
|
---|
2294 | }
|
---|
2295 |
|
---|
2296 | return sortedBidsList;
|
---|
2297 | }
|
---|
2298 |
|
---|
2299 | private LinkedList<Bid> SortBidsList(LinkedList<Bid> Bids,
|
---|
2300 | LinkedList<Double> distList) {
|
---|
2301 | LinkedList<Bid> sortedBidsList = new LinkedList<Bid>();
|
---|
2302 | try {
|
---|
2303 | HashMap<Bid, Double> sortedBidsMap = new HashMap<Bid, Double>();
|
---|
2304 |
|
---|
2305 | for (int i = 0; i < Bids.size(); i++) {
|
---|
2306 | sortedBidsMap.put(Bids.get(i), distList.get(i));
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | List<Map.Entry<Bid, Double>> list_Data = new LinkedList<Map.Entry<Bid, Double>>(
|
---|
2310 | sortedBidsMap.entrySet());
|
---|
2311 |
|
---|
2312 | // Sorting
|
---|
2313 | Collections.sort(list_Data,
|
---|
2314 | new Comparator<Map.Entry<Bid, Double>>() {
|
---|
2315 | @Override
|
---|
2316 | public int compare(Map.Entry<Bid, Double> entry1,
|
---|
2317 | Map.Entry<Bid, Double> entry2) {
|
---|
2318 | return (entry1.getValue()
|
---|
2319 | .compareTo(entry2.getValue()));
|
---|
2320 | }
|
---|
2321 | });
|
---|
2322 |
|
---|
2323 | for (Map.Entry<Bid, Double> entry : list_Data) {
|
---|
2324 | sortedBidsList.add(entry.getKey());
|
---|
2325 | }
|
---|
2326 | } catch (Exception e) {
|
---|
2327 | System.out.println(e.getMessage()
|
---|
2328 | + " exception in method SortBidsList (Distance)");
|
---|
2329 | }
|
---|
2330 |
|
---|
2331 | return sortedBidsList;
|
---|
2332 | }
|
---|
2333 |
|
---|
2334 | private double CalWhetherOppFirstBidGoodEnough(double minThreshold,
|
---|
2335 | double oppFirstBidUtility) {
|
---|
2336 | try {
|
---|
2337 | LinkedList<Bid> Bids = new LinkedList<Bid>();
|
---|
2338 | BidIterator myBidIterator = new BidIterator(
|
---|
2339 | this.utilitySpace.getDomain());
|
---|
2340 | for (; myBidIterator.hasNext();) {
|
---|
2341 | Bids.add(myBidIterator.next());
|
---|
2342 | }
|
---|
2343 | LinkedList<Bid> sortedBidsList = SortBidsList(Bids);
|
---|
2344 | double relSumUtility = 0;
|
---|
2345 | double relCountUtility = 0;
|
---|
2346 | for (int i = sortedBidsList.size() / 2; i < sortedBidsList
|
---|
2347 | .size(); i++) {
|
---|
2348 | relSumUtility += this.utilitySpace
|
---|
2349 | .getUtility(sortedBidsList.get(i));
|
---|
2350 | relCountUtility += 1;
|
---|
2351 | // if(debug)
|
---|
2352 | // {
|
---|
2353 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2354 | // System.setOut(file);
|
---|
2355 | // System.out.println("Selected Bid Utility:" +
|
---|
2356 | // this.utilitySpace.getUtility(sortedBidsList.get(i)));
|
---|
2357 | // }
|
---|
2358 | }
|
---|
2359 |
|
---|
2360 | double relAvgUtility = relSumUtility / relCountUtility;
|
---|
2361 | // if(debug)
|
---|
2362 | // {
|
---|
2363 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2364 | // System.setOut(file);
|
---|
2365 | // System.out.println("Selected Bids Avg Utility:" + relAvgUtility +
|
---|
2366 | // ", oppFirstBidUtility:" + oppFirstBidUtility);
|
---|
2367 | // }
|
---|
2368 | if (oppFirstBidUtility >= relAvgUtility) {
|
---|
2369 | return oppFirstBidUtility;
|
---|
2370 | }
|
---|
2371 | } catch (Exception e) {
|
---|
2372 | System.out.println(e.getMessage()
|
---|
2373 | + " exception in method IsOppFirstBidGoodEnough");
|
---|
2374 | }
|
---|
2375 |
|
---|
2376 | return minThreshold;
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | private double Compare_MinThreshold_And_SecondMax(double minThreshold,
|
---|
2380 | double utility_SecondMaximum) {
|
---|
2381 | try {
|
---|
2382 | if (minThreshold > utility_SecondMaximum) {
|
---|
2383 | return (utility_SecondMaximum * 0.9);
|
---|
2384 | }
|
---|
2385 | } catch (Exception e) {
|
---|
2386 | System.out.println(e.getMessage()
|
---|
2387 | + "exception in method Compare_MinThreshold_And_SecondMax");
|
---|
2388 | }
|
---|
2389 |
|
---|
2390 | return minThreshold;
|
---|
2391 | }
|
---|
2392 |
|
---|
2393 | private void PrintAllBids() {
|
---|
2394 | try {
|
---|
2395 | LinkedList<Bid> bids = new LinkedList();
|
---|
2396 |
|
---|
2397 | BidIterator myBidIterator = new BidIterator(
|
---|
2398 | this.utilitySpace.getDomain());
|
---|
2399 | for (; myBidIterator.hasNext();) {
|
---|
2400 | try {
|
---|
2401 | bids.add(myBidIterator.next());
|
---|
2402 | } catch (Exception e) {
|
---|
2403 | System.out.println(e.getMessage()
|
---|
2404 | + "exception in method PrintAllBids");
|
---|
2405 | }
|
---|
2406 | }
|
---|
2407 |
|
---|
2408 | for (Iterator e = bids.iterator(); e.hasNext();) {
|
---|
2409 | Bid bid = (Bid) e.next();
|
---|
2410 |
|
---|
2411 | // if(debug)
|
---|
2412 | // {
|
---|
2413 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2414 | // System.setOut(file);
|
---|
2415 | // System.out.println(Double.toString(this.utilitySpace.getUtility(bid))
|
---|
2416 | // + "\n");
|
---|
2417 | // }
|
---|
2418 |
|
---|
2419 | for (Issue lIssue : this.Issues) {
|
---|
2420 | int issueNum = lIssue.getNumber();
|
---|
2421 | Value v = bid.getValue(issueNum);
|
---|
2422 |
|
---|
2423 | if (debug) {
|
---|
2424 | file = new PrintStream(
|
---|
2425 | new FileOutputStream(fileName, true));
|
---|
2426 | System.setOut(file);
|
---|
2427 | System.out.print(v.toString() + ",");
|
---|
2428 | }
|
---|
2429 | }
|
---|
2430 |
|
---|
2431 | if (debug) {
|
---|
2432 | file = new PrintStream(
|
---|
2433 | new FileOutputStream(fileName, true));
|
---|
2434 | System.setOut(file);
|
---|
2435 | System.out.println();
|
---|
2436 | }
|
---|
2437 | }
|
---|
2438 | } catch (Exception e) {
|
---|
2439 | System.out.println(
|
---|
2440 | e.getMessage() + "exception in method PrintAllBids");
|
---|
2441 | }
|
---|
2442 | }
|
---|
2443 |
|
---|
2444 | private void printBidAllValues(Bid bid) {
|
---|
2445 | try {
|
---|
2446 | for (Issue lIssue : this.Issues) {
|
---|
2447 | int issueNum = lIssue.getNumber();
|
---|
2448 | Value v = bid.getValue(issueNum);
|
---|
2449 |
|
---|
2450 | if (debug) {
|
---|
2451 | file = new PrintStream(
|
---|
2452 | new FileOutputStream(fileName, true));
|
---|
2453 | System.setOut(file);
|
---|
2454 | System.out.print(v.toString() + "\t");
|
---|
2455 | }
|
---|
2456 | }
|
---|
2457 |
|
---|
2458 | if (debug) {
|
---|
2459 | file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2460 | System.setOut(file);
|
---|
2461 | System.out.println();
|
---|
2462 | }
|
---|
2463 | } catch (Exception e) {
|
---|
2464 | System.out.println(
|
---|
2465 | "Exception in printAllBidValues(): " + e.getMessage());
|
---|
2466 | }
|
---|
2467 | }
|
---|
2468 |
|
---|
2469 | private double CompareAdaptiveMinUAndNormalMinU(double adaptiveMinU,
|
---|
2470 | double normalMinU, double timeControl) {
|
---|
2471 | if (adaptiveMinU > normalMinU) {
|
---|
2472 | return (normalMinU + (adaptiveMinU - normalMinU) * timeControl);
|
---|
2473 | }
|
---|
2474 | return normalMinU;
|
---|
2475 | }
|
---|
2476 |
|
---|
2477 | private Bid BidToOffer_original() {
|
---|
2478 | Bid bidReturned = null;
|
---|
2479 |
|
---|
2480 | try {
|
---|
2481 | if (this.agentData1.minThreshold <= this.agentData2.minThreshold) {
|
---|
2482 | this.agentData2.minThreshold = this.agentData1.minThreshold;
|
---|
2483 | } else {
|
---|
2484 | this.agentData1.minThreshold = this.agentData2.minThreshold;
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | this.adaptiveMinUThreshold = this.offeredBidsAvg
|
---|
2488 | - this.offeredBidsSD * (1 - this.discountingFactor);
|
---|
2489 | // if(debug)
|
---|
2490 | // {
|
---|
2491 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2492 | // System.setOut(file);
|
---|
2493 | // System.out.println("calAdaptiveMinU:" + (this.offeredBidsAvg -
|
---|
2494 | // this.offeredBidsSD * (1 - this.discountingFactor)) +
|
---|
2495 | // ", AdaptiveAvg: " + this.offeredBidsAvg + ", AdaptiveSD:" +
|
---|
2496 | // this.offeredBidsSD + ", controlSD" + (this.offeredBidsSD * (1 -
|
---|
2497 | // this.discountingFactor)) + ", (1 - DF):" + (1 -
|
---|
2498 | // this.discountingFactor));
|
---|
2499 | // }
|
---|
2500 | double currentTIme = timeline.getTime();
|
---|
2501 | this.avgConcedeTime = (this.agentData2.concedeTime
|
---|
2502 | + this.agentData1.concedeTime) / 2;
|
---|
2503 | double timeControlAdaptiveMinU = currentTIme / this.avgConcedeTime;
|
---|
2504 | if (currentTIme <= this.avgConcedeTime) {
|
---|
2505 | if (this.discountingFactor <= 0.5) {
|
---|
2506 | this.agentData1.minThreshold = (this.MaximumUtility
|
---|
2507 | * this.discountingFactor)
|
---|
2508 | / Math.pow(this.discountingFactor,
|
---|
2509 | this.agentData1.concedeTime);
|
---|
2510 | this.agentData2.minThreshold = (this.MaximumUtility
|
---|
2511 | * this.discountingFactor)
|
---|
2512 | / Math.pow(this.discountingFactor,
|
---|
2513 | this.agentData2.concedeTime);
|
---|
2514 |
|
---|
2515 | double minThresholdAgent1 = CompareAdaptiveMinUAndNormalMinU(
|
---|
2516 | this.adaptiveMinUThreshold,
|
---|
2517 | this.agentData1.minThreshold,
|
---|
2518 | timeControlAdaptiveMinU);
|
---|
2519 | double minThresholdAgent2 = CompareAdaptiveMinUAndNormalMinU(
|
---|
2520 | this.adaptiveMinUThreshold,
|
---|
2521 | this.agentData2.minThreshold,
|
---|
2522 | timeControlAdaptiveMinU);
|
---|
2523 |
|
---|
2524 | this.finalMinUAgent1 = minThresholdAgent1;
|
---|
2525 | this.finalMinUAgent2 = minThresholdAgent2;
|
---|
2526 | this.agentData1.utilitythreshold = this.MaximumUtility
|
---|
2527 | - (this.MaximumUtility - minThresholdAgent1)
|
---|
2528 | * Math.pow(
|
---|
2529 | (currentTIme
|
---|
2530 | / this.agentData1.concedeTime),
|
---|
2531 | alpha1);
|
---|
2532 | this.agentData2.utilitythreshold = this.MaximumUtility
|
---|
2533 | - (this.MaximumUtility - minThresholdAgent2)
|
---|
2534 | * Math.pow(
|
---|
2535 | (currentTIme
|
---|
2536 | / this.agentData2.concedeTime),
|
---|
2537 | alpha1);
|
---|
2538 | } else {
|
---|
2539 | double minThresholdAgent1 = CompareAdaptiveMinUAndNormalMinU(
|
---|
2540 | this.adaptiveMinUThreshold,
|
---|
2541 | this.agentData1.minThreshold,
|
---|
2542 | timeControlAdaptiveMinU);
|
---|
2543 | double minThresholdAgent2 = CompareAdaptiveMinUAndNormalMinU(
|
---|
2544 | this.adaptiveMinUThreshold,
|
---|
2545 | this.agentData2.minThreshold,
|
---|
2546 | timeControlAdaptiveMinU);
|
---|
2547 | this.finalMinUAgent1 = minThresholdAgent1;
|
---|
2548 | this.finalMinUAgent2 = minThresholdAgent2;
|
---|
2549 |
|
---|
2550 | this.agentData1.utilitythreshold = minThresholdAgent1
|
---|
2551 | + (this.MaximumUtility - minThresholdAgent1)
|
---|
2552 | * (1 - Math.sin((Math.PI / 2) * (currentTIme
|
---|
2553 | / this.agentData1.concedeTime)));
|
---|
2554 | this.agentData2.utilitythreshold = minThresholdAgent2
|
---|
2555 | + (this.MaximumUtility - minThresholdAgent2)
|
---|
2556 | * (1 - Math.sin((Math.PI / 2) * (currentTIme
|
---|
2557 | / this.agentData2.concedeTime)));
|
---|
2558 | }
|
---|
2559 | } else {
|
---|
2560 | if (this.discountingFactor <= 0.5) {
|
---|
2561 | this.agentData1.utilitythreshold = (this.MaximumUtility
|
---|
2562 | * this.discountingFactor)
|
---|
2563 | / Math.pow(this.discountingFactor, currentTIme);
|
---|
2564 | this.agentData2.utilitythreshold = (this.MaximumUtility
|
---|
2565 | * this.discountingFactor)
|
---|
2566 | / Math.pow(this.discountingFactor, currentTIme);
|
---|
2567 | } else if (this.discountingFactor == 1) {
|
---|
2568 | this.agentData1.utilitythreshold = CompareAdaptiveMinUAndNormalMinU(
|
---|
2569 | this.adaptiveMinUThreshold,
|
---|
2570 | this.agentData1.minThreshold, 1);
|
---|
2571 | this.agentData2.utilitythreshold = CompareAdaptiveMinUAndNormalMinU(
|
---|
2572 | this.adaptiveMinUThreshold,
|
---|
2573 | this.agentData2.minThreshold, 1);
|
---|
2574 | this.finalMinUAgent1 = this.agentData1.utilitythreshold;
|
---|
2575 | this.finalMinUAgent2 = this.agentData2.utilitythreshold;
|
---|
2576 | } else {
|
---|
2577 | double minThresholdAgent1 = CompareAdaptiveMinUAndNormalMinU(
|
---|
2578 | this.adaptiveMinUThreshold,
|
---|
2579 | this.agentData1.minThreshold,
|
---|
2580 | timeControlAdaptiveMinU);
|
---|
2581 | double minThresholdAgent2 = CompareAdaptiveMinUAndNormalMinU(
|
---|
2582 | this.adaptiveMinUThreshold,
|
---|
2583 | this.agentData2.minThreshold,
|
---|
2584 | timeControlAdaptiveMinU);
|
---|
2585 |
|
---|
2586 | this.agentData1.utilitythreshold = minThresholdAgent1
|
---|
2587 | + (this.MaximumUtility - minThresholdAgent1)
|
---|
2588 | / (1 - this.agentData1.concedeTime)
|
---|
2589 | * Math.pow(
|
---|
2590 | (currentTIme
|
---|
2591 | - this.agentData1.concedeTime),
|
---|
2592 | this.discountingFactor);
|
---|
2593 | this.agentData2.utilitythreshold = minThresholdAgent2
|
---|
2594 | + (this.MaximumUtility - minThresholdAgent2)
|
---|
2595 | / (1 - this.agentData2.concedeTime)
|
---|
2596 | * Math.pow(
|
---|
2597 | (currentTIme
|
---|
2598 | - this.agentData2.concedeTime),
|
---|
2599 | this.discountingFactor);
|
---|
2600 | }
|
---|
2601 | }
|
---|
2602 | this.avgUtilitythreshold = (this.agentData1.utilitythreshold
|
---|
2603 | + this.agentData2.utilitythreshold) / 2;
|
---|
2604 | if (this.avgUtilitythreshold > this.MaximumUtility) {
|
---|
2605 | this.avgUtilitythreshold = this.MaximumUtility;
|
---|
2606 | }
|
---|
2607 |
|
---|
2608 | /*
|
---|
2609 | * if(minimumOfBid < 0.9 && this.guessOpponentType == false){
|
---|
2610 | * if(this.opponentBidHistory.getSize() <= 2){ this.opponentType =
|
---|
2611 | * 1;//tough opponent alpha1 = 2; } else{ this.opponentType = 0;
|
---|
2612 | * alpha1 = 4; } this.guessOpponentType = true;//we only guess the
|
---|
2613 | * opponent type once here System.out.println("we guess the opponent
|
---|
2614 | * type is "+this.opponentType); }
|
---|
2615 | */
|
---|
2616 |
|
---|
2617 | bidReturned = this.regeneratebid(this.avgUtilitythreshold);
|
---|
2618 | if (bidReturned == null) {
|
---|
2619 | // System.out.println("no bid is searched warning");
|
---|
2620 | bidReturned = this.bid_maximum_utility;
|
---|
2621 | }
|
---|
2622 | UpdateOfferedBidsStat(this.utilitySpace.getUtility(bidReturned));
|
---|
2623 | // if(debug)
|
---|
2624 | // {
|
---|
2625 | // //SysOut = System.out;
|
---|
2626 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2627 | // System.setOut(file);
|
---|
2628 | // System.out.println(Double.toString(bidReturned) + "\n");
|
---|
2629 | // //System.setOut(SysOut);
|
---|
2630 | // }
|
---|
2631 | MinAcceptCondition(bidReturned);
|
---|
2632 | } catch (Exception e) {
|
---|
2633 | System.out.println(e.getMessage()
|
---|
2634 | + " exception in method BidToOffer_original");
|
---|
2635 | return this.bid_maximum_utility;
|
---|
2636 | }
|
---|
2637 | // System.out.println("the current threshold is " +
|
---|
2638 | // this.utilitythreshold + " with the value of alpha1 is " + alpha1);
|
---|
2639 | return bidReturned;
|
---|
2640 | }
|
---|
2641 |
|
---|
2642 | private boolean OtherAcceptCondition(Bid oppPreviousBid, boolean IsAccept) {
|
---|
2643 | try {
|
---|
2644 | if (timeline
|
---|
2645 | .getTime() >= ((this.agentData1.concedeTime
|
---|
2646 | + this.agentData2.concedeTime) / 2)
|
---|
2647 | && this.utilitySpace.getUtility(
|
---|
2648 | oppPreviousBid) >= this.minUtilityUhreshold) {
|
---|
2649 | // if(debug)
|
---|
2650 | // {
|
---|
2651 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2652 | // System.setOut(file);
|
---|
2653 | // System.out.println("OtherAcceptCondition: true, minU:" +
|
---|
2654 | // this.minUtilityUhreshold + ", bidReturned:" +
|
---|
2655 | // this.utilitySpace.getUtility(oppPreviousBid));
|
---|
2656 | // }
|
---|
2657 | return true;
|
---|
2658 | }
|
---|
2659 | } catch (Exception e) {
|
---|
2660 | System.out.println(e.getMessage()
|
---|
2661 | + " exception in method OtherAcceptCondition");
|
---|
2662 | return IsAccept;
|
---|
2663 | }
|
---|
2664 | return IsAccept;
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | private void MinAcceptCondition(Bid bidReturned) {
|
---|
2668 | try {
|
---|
2669 | if (this.minUtilityUhreshold > this.utilitySpace
|
---|
2670 | .getUtility(bidReturned)) {
|
---|
2671 | this.minUtilityUhreshold = this.utilitySpace
|
---|
2672 | .getUtility(bidReturned);
|
---|
2673 | // if(debug)
|
---|
2674 | // {
|
---|
2675 | // file = new PrintStream(new FileOutputStream(fileName, true));
|
---|
2676 | // System.setOut(file);
|
---|
2677 | // System.out.println("Changed minU:" + this.minUtilityUhreshold
|
---|
2678 | // + ", bidReturned:" +
|
---|
2679 | // this.utilitySpace.getUtility(bidReturned));
|
---|
2680 | // }
|
---|
2681 | }
|
---|
2682 | } catch (Exception e) {
|
---|
2683 | System.out.println(
|
---|
2684 | e.getMessage() + " exception in method MinAcceptCondition");
|
---|
2685 | }
|
---|
2686 | }
|
---|
2687 |
|
---|
2688 | @Override
|
---|
2689 | public String getDescription() {
|
---|
2690 | return "ANAC2016";
|
---|
2691 | }
|
---|
2692 | }
|
---|