source: src/main/java/agents/anac/y2017/tucagent/IssueManager.java@ 346

Last change on this file since 346 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 7.8 KB
Line 
1package agents.anac.y2017.tucagent;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Map;
6import java.util.Random;
7import java.util.TreeMap;
8
9import genius.core.AgentID;
10import genius.core.Bid;
11import genius.core.issue.Issue;
12import genius.core.timeline.Timeline;
13import genius.core.utility.AdditiveUtilitySpace;
14
15public class IssueManager {
16
17 AdditiveUtilitySpace US;
18 Bid maxBid;
19 Timeline T;
20 TreeMap<Double, Bid> AllPossibleBids;
21 ArrayList<Object> myCurrentBiggerBids;
22 double overallExpectedutil = 0.0;
23 boolean FirstOfferGiven = false;
24 Bid myNextBidIs = null;
25
26 BayesianOpponentModel OMone;
27 BayesianOpponentModel OMtwo;
28
29 // KAINOURIA APO DW KAI PERA
30 ArrayList<Double> GreedyRatioListOne;
31 ArrayList<Double> GreedyRatioListTwo;
32 List<Issue> AllIssues;
33 public int numOfIssues;
34 Bid opponentsOneLastBid = null;
35 Bid opponentsTwoLastBid = null;
36 Bid myBid;
37 Bid firstMaxBid;
38
39 // newwwwwww
40 AgentID agentA = null;
41 AgentID agentB = null;
42 int deltaA = 0;
43 int deltaB = 0;
44 int roundCount = 0;
45 double NSA = 0.0;
46 double NSB = 0.0;
47 double NS = 0.0;
48 int numOfMyCommitedOffers = 1;
49 double selfFactor = 0.0;
50 double Eagerness = 0.5;
51 double enviromFactor = 0.11;
52 double concessionRate = 0.0;
53 double myTotalWeight = 0.0;
54 double maxBidUtil = 0.0;
55
56 // even newer
57 int similarityA = 0;
58 int similarityB = 0;
59 double probOFSimilarityA = 0.0;
60 double probOFSimilarityB = 0.0;
61
62 double BestOpponBid = 0.0;
63
64 // KAINOURIA SUNARTISI
65
66 public void findMySimilarAgent() { // psaxnw na vrw ton agent pou exei
67 // similar weights me emena
68 // prospelavnw ola ta issue
69 for (int i = 0; i < numOfIssues; i++) {
70
71 if (GreedyRatioListOne.get(i) >= 0.8 && GreedyRatioListOne.get(i) <= 1.2) {
72 similarityA++;
73 }
74
75 if (GreedyRatioListTwo.get(i) >= 0.8 && GreedyRatioListOne.get(i) <= 1.2) {
76 similarityB++;
77 }
78 }
79
80 probOFSimilarityA = similarityA / numOfIssues;
81 probOFSimilarityB = similarityB / numOfIssues;
82 }
83
84 // an den exw ousiastika discount factor einai san na to pernw dedomeno =1
85 public double GetDiscountFactor() {
86 if (this.US.getDiscountFactor() <= 0.001 || this.US.getDiscountFactor() > 1.0) {
87 return 1.0;
88 }
89 return this.US.getDiscountFactor();
90 }
91
92 public void ProcessBid(AgentID opponent, Bid IncomingBid) throws Exception { // elengw
93 // an
94 // auto
95 // einai
96 // to
97 // kalutero
98 // bid
99 // p
100 // m
101 // exei
102 // kanei
103 // o
104 // adipalos
105
106 // elenxw an einai to kalutero bid pou m exei er8ei
107 if (this.US.getUtility(IncomingBid) > this.BestOpponBid) {
108 BestOpponBid = this.US.getUtility(IncomingBid);
109 }
110
111 roundCount++;
112
113 if (!AllPossibleBids.isEmpty()) {
114 if (!AllPossibleBids.containsValue(IncomingBid)) { // an ayto to bid
115 // den to eixa
116 // upopsin to
117 // vazw k auto
118 // sti lsita mou
119 AllPossibleBids.put(US.getUtility(IncomingBid), IncomingBid);
120 }
121 }
122
123 findGreedyRatio();
124 findMySimilarAgent();
125
126 findNegotiationStatus(opponent, IncomingBid);
127
128 // SET MY SELF FACTOR
129 double DF = this.GetDiscountFactor();
130 double Time = this.T.getTime();
131
132 if (DF != 1) {
133 Eagerness = 1 - DF;
134 }
135
136 selfFactor = 0.25 * ((1 / numOfMyCommitedOffers) + NS + Time + Eagerness);
137
138 // SET CONCESSION RATE
139
140 if (Time <= 0.2) { // start
141
142 concessionRate = 0.0;
143
144 } else if (Time >= 0.9) { // end
145
146 concessionRate = 0.50;
147
148 } else { // otherwise
149
150 concessionRate = myTotalWeight * selfFactor + enviromFactor;
151 }
152 }
153
154 // kathorismos tou threshold mou me vasi to offer pou tha ekana edw!!!
155 public double CreateThreshold() throws Exception {
156
157 double offer;
158 double reservationValue = 0.6; // set my own reservation value
159
160 double Time = this.T.getTime();
161
162 if (Time >= 0.95) {
163 offer = BestOpponBid;
164 } else {
165 offer = (maxBidUtil + (reservationValue - maxBidUtil) * concessionRate);
166 }
167
168 return offer;
169
170 }
171
172 // kainouria
173 public void findNegotiationStatus(AgentID opponent, Bid IncomingBid) {
174
175 double incomingUtil = US.getUtility(IncomingBid);
176
177 if (opponent == agentA && opponent != null) { // gia ton 1 agent
178
179 if (incomingUtil < US.getUtility(opponentsOneLastBid)) {
180 deltaA = deltaA + 1;
181 } else {
182 deltaA = deltaA + 3;
183 }
184
185 NSA = (deltaA + 2 * roundCount) / 3 * roundCount;
186
187 } else if (opponent == agentB && opponent != null) { // gia ton 2 agent
188
189 if (incomingUtil < US.getUtility(opponentsOneLastBid)) {
190 deltaB = deltaB + 1;
191 } else {
192 deltaB = deltaB + 3;
193 }
194
195 NSB = (deltaB + 2 * roundCount) / 3 * roundCount;
196 }
197
198 if (similarityA == similarityB) {
199
200 NS = (NSA + NSB) / 2;
201
202 } else if (similarityA > similarityB) {
203
204 double weight1 = probOFSimilarityA;
205 double weight2 = 1 - weight1;
206
207 NS = (weight1 * NSA + weight2 * NSB) / 2;
208
209 } else { // o b pio polu similar apo ton a
210
211 double weight1 = probOFSimilarityB;
212 double weight2 = 1 - weight1;
213
214 NS = (weight1 * NSA + weight2 * NSB) / 2;
215 }
216
217 }
218
219 // epistrefei to bid me to amesws mikrotero utillity
220 public Bid GenerateBidWithAtleastUtilityOf(double MinUtility) {
221
222 Map.Entry<Double, Bid> e = this.AllPossibleBids.ceilingEntry(MinUtility);
223
224 if (e == null) {
225 return this.maxBid;
226 }
227
228 return e.getValue();
229 }
230
231 public Bid GetMaxBid() {
232 return maxBid;
233 }
234
235 public void findAllmyBidsPossible() throws Exception {
236
237 Random random = new Random();
238 int numOfPossibleBids = (int) US.getDomain().getNumberOfPossibleBids();
239
240 for (int i = 0; i < numOfPossibleBids; i++) { // prospathw na vrw ola ta
241 // pithana bids--> kanw
242 // mia arxiki lista
243 Bid randomBid = US.getDomain().getRandomBid(random);
244 if ((!AllPossibleBids.containsKey(US.getUtility(randomBid)))
245 || (!AllPossibleBids.containsValue(randomBid))) {
246 AllPossibleBids.put(US.getUtility(randomBid), randomBid);
247 }
248 }
249
250 }
251
252 // KAINOURIA SUNARTISI
253 public void findGreedyRatio() { // se kathe guro enhmerwnetai afou allazei
254 // to expected weight
255
256 for (int i = 0; i < numOfIssues; i++) { // ousiastika kanw update twn
257 // duo greedy factor se kathe
258 // guro
259
260 double myWeight = US.getWeight(i);
261 double oppOneWeight = OMone.getExpectedWeight(i);
262 double oppTwoWeight = OMtwo.getExpectedWeight(i);
263
264 double greedyFactorOne = myWeight / oppOneWeight;
265 double greedyFactorTwo = myWeight / oppTwoWeight;
266
267 GreedyRatioListOne.set(i, greedyFactorOne);// exw duo listes me ta r
268 // k r' pou ananewnodai
269 // sunexeia
270 GreedyRatioListTwo.set(i, greedyFactorTwo);
271
272 }
273 }
274
275 public IssueManager(AdditiveUtilitySpace US, Timeline T) throws Exception {
276 this.T = T;
277 this.US = US;
278
279 try {
280 double maxBidUtil = US.getUtility(this.maxBid); // pernei to utility
281 // tou max bid
282 if (maxBidUtil == 0.0) {
283 this.maxBid = this.US.getMaxUtilityBid();
284 }
285 } catch (Exception e) {
286 try {
287 this.maxBid = this.US.getMaxUtilityBid();
288 } catch (Exception var5_7) {
289 // empty catch block
290 }
291 }
292
293 myNextBidIs = maxBid;
294 AllPossibleBids = new TreeMap<Double, Bid>();
295 myCurrentBiggerBids = new ArrayList<Object>();
296 myCurrentBiggerBids.add(maxBid);
297 AllPossibleBids.put(US.getUtility(maxBid), maxBid);
298 findAllmyBidsPossible();
299
300 // kainouria apo dw k pera
301 myBid = maxBid;
302 GreedyRatioListOne = new ArrayList<Double>();
303 GreedyRatioListTwo = new ArrayList<Double>();
304 AllIssues = new ArrayList<Issue>();
305 AllIssues = US.getDomain().getIssues();
306 numOfIssues = AllIssues.size();
307 opponentsOneLastBid = US.getMinUtilityBid();
308 opponentsTwoLastBid = US.getMinUtilityBid();
309
310 // newwwwwwwwwwwwwww
311 maxBidUtil = US.getUtility(maxBid);
312 findAllmyBidsPossible();
313
314 for (int i = 0; i < numOfIssues; i++) {
315
316 myTotalWeight = (myTotalWeight + US.getWeight(i)) / 2;
317
318 }
319
320 }
321}
Note: See TracBrowser for help on using the repository browser.