source: src/main/java/agents/anac/y2014/BraveCat/OpponentModels/DBOMModel/OpponentUtilitySimilarityBasedEstimator.java

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

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

File size: 4.4 KB
Line 
1package agents.anac.y2014.BraveCat.OpponentModels.DBOMModel;
2
3import java.util.List;
4
5import agents.anac.y2014.BraveCat.necessaryClasses.NegotiationSession;
6import genius.core.Bid;
7import genius.core.bidding.BidDetails;
8import genius.core.issue.Issue;
9import genius.core.issue.IssueDiscrete;
10import genius.core.issue.IssueInteger;
11import genius.core.issue.IssueReal;
12
13public class OpponentUtilitySimilarityBasedEstimator {
14
15 int maximumNumOfLastReceivedBidsUsed = 0;
16 NegotiationSession negotiationSession;
17
18 public OpponentUtilitySimilarityBasedEstimator(NegotiationSession nego,
19 int max) {
20 negotiationSession = nego;
21 maximumNumOfLastReceivedBidsUsed = max;
22 }
23
24 public double GetBidUtility(BidDetails bid1) throws Exception {
25 int repeatingTimes = Math.min(maximumNumOfLastReceivedBidsUsed,
26 negotiationSession.getOpponentBidHistory().getHistory().size());
27 int i = 1;
28 double sum = 0;
29 double avgUtility = 0;
30 double[] CalculatedSimilarities = new double[repeatingTimes + 1];
31
32 for (i = 1; i <= repeatingTimes; i++) {
33 Bid tempBid = negotiationSession
34 .getOpponentBidHistory()
35 .getHistory()
36 .get(negotiationSession.getOpponentBidHistory()
37 .getHistory().size()
38 - i).getBid();
39 double tempUtility = 1 - (0.3 * negotiationSession
40 .getOpponentBidHistory()
41 .getHistory()
42 .get(negotiationSession.getOpponentBidHistory()
43 .getHistory().size()
44 - i).getTime());
45 double tempTime = negotiationSession
46 .getOpponentBidHistory()
47 .getHistory()
48 .get(negotiationSession.getOpponentBidHistory()
49 .getHistory().size()
50 - i).getTime();
51 BidDetails bid2 = new BidDetails(tempBid, tempUtility, tempTime);
52
53 CalculatedSimilarities[i] = GetSimilarity(bid1, bid2);
54 sum += CalculatedSimilarities[i];
55 }
56
57 for (i = 1; i <= repeatingTimes; i++)
58 CalculatedSimilarities[i] = (double) CalculatedSimilarities[i]
59 / sum;
60
61 for (i = 1; i <= repeatingTimes; i++) {
62 Bid tempBid = negotiationSession
63 .getOpponentBidHistory()
64 .getHistory()
65 .get(negotiationSession.getOpponentBidHistory()
66 .getHistory().size()
67 - i).getBid();
68 double tempUtility = 1 - (0.3 * negotiationSession
69 .getOpponentBidHistory()
70 .getHistory()
71 .get(negotiationSession.getOpponentBidHistory()
72 .getHistory().size()
73 - i).getTime());
74 double tempTime = negotiationSession
75 .getOpponentBidHistory()
76 .getHistory()
77 .get(negotiationSession.getOpponentBidHistory()
78 .getHistory().size()
79 - i).getTime();
80 BidDetails bid2 = new BidDetails(tempBid, tempUtility, tempTime);
81 avgUtility += CalculatedSimilarities[i]
82 * bid2.getMyUndiscountedUtil();
83 }
84 return avgUtility;
85 }
86
87 private double GetSimilarity(BidDetails bid1, BidDetails bid2)
88 throws Exception {
89 double TemporalSimilarity = Math.abs(bid1.getTime() - bid2.getTime());
90 double NaturalSimilarity = GetBidDistance(bid1.getBid(), bid2.getBid());
91 return TemporalSimilarity * NaturalSimilarity;
92 }
93
94 private double GetBidDistance(Bid bid1, Bid bid2) throws Exception {
95 double avgDistance = 0;
96 List<Issue> issues = negotiationSession.getDomain().getIssues();
97 for (int i = 1; i <= issues.size(); i++) {
98 Issue lIssue = issues.get(i - 1);
99 switch (lIssue.getType()) {
100 case DISCRETE:
101 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
102 double t1 = (double) (lIssueDiscrete.getValueIndex(bid1
103 .getValue(i).toString()) - lIssueDiscrete
104 .getValueIndex(bid2.getValue(i).toString()))
105 / lIssueDiscrete.getNumberOfValues();
106 avgDistance += Math.pow(t1, 2);
107 break;
108 case REAL:
109 IssueReal lIssueReal = (IssueReal) lIssue;
110 double t2 = (double) (Double.parseDouble(bid1.getValue(i)
111 .toString()) - Double.parseDouble(bid2.getValue(i)
112 .toString()))
113 / (lIssueReal.getUpperBound() - lIssueReal
114 .getLowerBound());
115 avgDistance += Math.pow(t2, 2);
116 break;
117 case INTEGER:
118 IssueInteger lIssueInteger = (IssueInteger) lIssue;
119 double t3 = (double) (Integer.parseInt(bid1.getValue(i)
120 .toString()) - Integer.parseInt(bid2.getValue(i)
121 .toString()))
122 / (lIssueInteger.getUpperBound() - lIssueInteger
123 .getLowerBound());
124 avgDistance += Math.pow(t3, 2);
125 break;
126 default:
127 throw new Exception("issue type " + lIssue.getType()
128 + " not supported!");
129 }
130 }
131 return Math.sqrt(avgDistance);
132 }
133}
Note: See TracBrowser for help on using the repository browser.