source: src/main/java/agents/anac/y2012/MetaAgent/MetaAgent.java@ 84

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

Initial import : Genius 9.0.0

File size: 12.3 KB
Line 
1package agents.anac.y2012.MetaAgent;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6import java.util.Map.Entry;
7
8import agents.anac.y2010.AgentSmith.AgentSmith;
9import agents.anac.y2011.AgentK2.Agent_K2;
10import agents.anac.y2011.BramAgent.BRAMAgent;
11import agents.anac.y2011.Gahboninho.Gahboninho;
12import agents.anac.y2011.HardHeaded.KLH;
13import agents.anac.y2011.TheNegotiator.TheNegotiator;
14import agents.anac.y2011.ValueModelAgent.ValueModelAgent;
15import agents.anac.y2012.MetaAgent.agents.Chameleon.Chameleon;
16import agents.anac.y2012.MetaAgent.agents.DNAgent.DNAgent;
17import agents.anac.y2012.MetaAgent.agents.GYRL.GYRL;
18import agents.anac.y2012.MetaAgent.agents.LYY.LYYAgent;
19import agents.anac.y2012.MetaAgent.agents.MrFriendly.MrFriendly;
20import agents.anac.y2012.MetaAgent.agents.ShAgent.ShAgent;
21import agents.anac.y2012.MetaAgent.agents.SimpleAgentNew.SimpleAgentNew;
22import agents.anac.y2012.MetaAgent.agents.WinnerAgent.WinnerAgent2;
23import genius.core.Agent;
24import genius.core.Domain;
25import genius.core.SupportedNegotiationSetting;
26import genius.core.actions.Action;
27import genius.core.actions.EndNegotiation;
28import genius.core.actions.Offer;
29import genius.core.issue.Issue;
30import genius.core.issue.Objective;
31import genius.core.issue.ValueDiscrete;
32import genius.core.utility.AdditiveUtilitySpace;
33import genius.core.utility.EVALUATORTYPE;
34import genius.core.utility.Evaluator;
35import genius.core.utility.EvaluatorDiscrete;
36import genius.core.utility.EvaluatorInteger;
37import genius.core.utility.EvaluatorReal;
38
39public class MetaAgent extends Agent {
40 private Agent myAgent;
41 private String myAgentName;
42 private boolean agentInit;
43 private Action actionOfPartner;
44 private boolean first;
45 double[] params;
46 double opponentFirstBid;
47
48 @Override
49 public void init() {
50 agentInit = false;
51 first = false;
52 opponentFirstBid = 0;
53 Domain d = this.utilitySpace.getDomain();
54 myAgentName = "";
55 }
56
57 private String[][] getRegression() {
58 String[][] reg = new String[18][12];
59 reg[0] = "IAMcrazyhaggler,0.077,0,0.137,0.000000000,0.015,0,0,0,1.311,-0.03,0.556"
60 .split(",");
61 reg[1] = "LYYAgent,-1.22,-0.016,0.23,0.000000000,0.027,0.026,1.042,1.372,1.482,0,0.572"
62 .split(",");
63 reg[2] = "Chameleon,-2.185,-0.024,0.303,0.000000000,0.017,0.055,2.013,2.184,1.692,0,0.502"
64 .split(",");
65 reg[3] = "AgentSmith,-2.075,-0.018,0.333,-0.000000410,0,0.05,1.938,2.027,1.428,0,0.565"
66 .split(",");
67 reg[4] = "GYRL,-1.663,0,0.348,0.000000000,0.029,0.028,1.327,1.668,1.327,0,0.609"
68 .split(",");
69 reg[5] = "Gahboninho,0.309,-0.024,0.337,0.000000248,0,0,0,0,0.495,0,0.451"
70 .split(",");
71 reg[6] = "ValueModelAgent,-1.401,-0.022,0.441,-0.000000206,0,0.044,1.328,1.231,1.629,0,0.49"
72 .split(",");
73 reg[7] = "Nice Tit-for-Tat Agent,-0.018,-0.014,0.422,-0.000000381,0,0,0.198,0,0.549,0,0.529"
74 .split(",");
75 reg[8] = "HardHeaded,-2.012,-0.035,0.319,0.000000172,0,0.053,2.107,2.136,1.547,0,0.392"
76 .split(",");
77 reg[9] = "WinnerAgent,-1.741,0,0.248,0.000000000,0.031,0.03,1.428,1.796,1.742,0,0.599"
78 .split(",");
79 reg[10] = "AgentK2,-1.027,-0.012,0.246,0.000000000,0.019,0.022,1.083,1.127,1.097,0,0.531"
80 .split(",");
81 reg[11] = "TheNegotiator,-0.159,0.017,0.307,0.000000000,0,0.015,0,0,0.92,0.03,0.665"
82 .split(",");
83 reg[12] = "IAMhaggler2011,0.256,0,0.166,0.000000224,0.017,-0.011,0,0,0.347,0,0.543"
84 .split(",");
85 reg[13] = "DNAgent,-0.581,-0.024,0.732,0.000000000,0,0.01,0.61,0,1.141,0,0.237"
86 .split(",");
87 reg[14] = "BRAMAgent,-0.764,0,0.232,0.000000250,0,0.035,0.842,0.708,0.7,0,0.538"
88 .split(",");
89 reg[15] = "MrFriendly,-1.721,-0.025,0.194,-0.000000429,0,0.054,1.814,1.711,1.488,0,0.498"
90 .split(",");
91 reg[16] = "ShAgent,-2.072,-0.021,0,0.000000476,0.069,-0.055,2.336,2.805,1.743,0,0.412"
92 .split(",");
93 reg[17] = "SimpleAgent,-1.359,0,0.287,-0.000000180,0.028,0.016,1.16,1.524,0.86,0,0.588"
94 .split(",");
95 return reg;
96 }
97
98 private void getDomainParams() {
99 params = new double[10];
100 Domain d = this.utilitySpace.getDomain();
101 List<Issue> a = d.getIssues();
102
103 params[0] = a.size(); // 0 = number of issues.
104 params[1] = this.utilitySpace.getDiscountFactor() == 0 ? 1
105 : this.utilitySpace.getDiscountFactor(); // 1
106 // =
107 // discount
108 // factor.
109 int min = Integer.MAX_VALUE, max = -1, size = 1;
110
111 // params 5+6+7 - Expected Utility of role, Standard deviation of
112 // Utility of role, Standard deviation of weights of role
113 double EU = 0, stdevU = 0, stdevW = 0, sW = 0, ssW = 0, countW = 0;
114 Iterator<Entry<Objective, Evaluator>> issue = ((AdditiveUtilitySpace) utilitySpace)
115 .getEvaluators().iterator();
116 List<Double> ssWList = new ArrayList<Double>();
117 while (issue.hasNext()) { // every issue
118 Entry<Objective, Evaluator> entry = issue.next();
119 Evaluator e = entry.getValue();
120 double weight = e.getWeight();
121 countW++;
122 sW += weight;
123 ssWList.add(weight);
124 double tempEU = 0, tempStdevU = 0;
125 if (e.getType() == EVALUATORTYPE.DISCRETE) {
126 Iterator<ValueDiscrete> v = ((EvaluatorDiscrete) e).getValues()
127 .iterator();
128 List<Double> s = new ArrayList<Double>();
129 double sumU = 0;
130 while (v.hasNext()) {
131 ValueDiscrete vd = v.next();
132 try {
133 double val = ((EvaluatorDiscrete) e).getEvaluation(vd);
134 s.add(val);
135 sumU += val;
136 } catch (Exception e1) {
137 e1.printStackTrace();
138 }
139 }
140 int currSize = s.size();
141 min = (min > currSize) ? currSize : min;
142 max = (max < currSize) ? currSize : max;
143 size = size * currSize;
144 tempEU = sumU / currSize;
145 Iterator<Double> valIt = s.iterator();
146 while (valIt.hasNext()) {
147 tempStdevU += Math.pow(valIt.next() - tempEU, 2);
148 }
149 tempStdevU = Math.sqrt(tempStdevU / ((double) currSize - 1));
150 } else if (e.getType() == EVALUATORTYPE.INTEGER) {
151 tempEU = ((double) (((EvaluatorInteger) e).getUpperBound()
152 + ((EvaluatorInteger) e).getLowerBound())) / 2;
153 tempStdevU = Math.sqrt((Math
154 .pow(((EvaluatorInteger) e).getUpperBound() - tempEU, 2)
155 + Math.pow(
156 ((EvaluatorInteger) e).getLowerBound() - tempEU,
157 2))
158 / 2);
159 } else if (e.getType() == EVALUATORTYPE.REAL) {
160 tempEU = (((EvaluatorReal) e).getUpperBound()
161 + ((EvaluatorReal) e).getLowerBound()) / 2;
162 tempStdevU = Math.sqrt((Math
163 .pow(((EvaluatorReal) e).getUpperBound() - tempEU, 2)
164 + Math.pow(((EvaluatorReal) e).getLowerBound() - tempEU,
165 2))
166 / 2);
167 } else {
168 tempEU = 0.5;
169 tempStdevU = 0;
170 }
171
172 EU += tempEU * weight;
173 stdevU += tempStdevU * weight;
174 }
175 Iterator<Double> wIt = ssWList.iterator();
176 double avgW = sW / countW;
177 while (wIt.hasNext()) {
178 ssW += Math.pow(wIt.next() - avgW, 2);
179 }
180
181 stdevW = countW <= 1 ? 0 : Math.sqrt(ssW / (countW - 1));
182 params[2] = size;
183 params[3] = min;
184 params[4] = max;
185 params[5] = EU;
186 params[6] = stdevU;
187 params[7] = stdevW;
188 params[8] = first ? 1 : 0;
189 params[9] = opponentFirstBid;
190 }
191
192 private String getBestAgent() {
193 double lambda = 70;
194 double sumExp = 0;
195
196 String ans = null;
197 getDomainParams();
198 String[][] reg = getRegression();
199 double maxResult = 0;
200 int bestIndex = -1;
201 List<String> agents = new ArrayList<String>();
202 double[] agentsResults = new double[reg.length];
203 for (int k = 0; k < reg.length; k++) {
204 agents.add(k, reg[k][0]);
205 double regressionResult = 0;
206 double[] regression = new double[params.length + 1];
207
208 for (int i = 0; i < regression.length; i++) {
209 regression[i] = Double.parseDouble(reg[k][i + 1]);
210 if (i > 0) {
211 regressionResult += regression[i] * params[i - 1];
212 } else
213 regressionResult += regression[i];
214 }
215 if (!(reg[k][0].equalsIgnoreCase("Nice Tit-for-Tat Agent")
216 || reg[k][0].equalsIgnoreCase("IAMhaggler2011")
217 || reg[k][0].equalsIgnoreCase("IAMcrazyhaggler"))) {
218 // calculate QRE value, part 1
219 agentsResults[k] = Math.exp(regressionResult * lambda);
220 } else // 3 agents that doesn't work - will get a 0 value.
221 {
222 agentsResults[k] = 0;
223 }
224 sumExp += agentsResults[k];
225
226 }
227 double rand = Math.random(), totalValue = 0;
228 for (int i = 0; i < agentsResults.length; i++) {
229 // calculate QRE value, part 2
230 agentsResults[i] = agentsResults[i] / sumExp;
231 totalValue += agentsResults[i];
232 if (rand < totalValue) { // at the end, total value will be 1 (it's
233 // a probability value)
234 bestIndex = i;
235 break;
236 }
237 }
238
239 ans = agents.get(bestIndex);
240 myAgentName = ans;
241 return ans;
242
243 }
244
245 private Agent selectAgent(String name) {
246 Agent a = new KLH(); // default, as winner of 2011 contest.
247 if (name.equalsIgnoreCase("IAMcrazyhaggler"))
248 return a;// /agent doesn't work
249 else if (name.equalsIgnoreCase("LYYAgent"))
250 return new LYYAgent();
251 else if (name.equalsIgnoreCase("Chameleon"))
252 return new Chameleon();
253 else if (name.equalsIgnoreCase("AgentSmith"))
254 return new AgentSmith();
255 else if (name.equalsIgnoreCase("GYRL"))
256 return new GYRL();
257 else if (name.equalsIgnoreCase("Gahboninho"))
258 return new Gahboninho();
259 else if (name.equalsIgnoreCase("ValueModelAgent"))
260 return new ValueModelAgent();
261 else if (name.equalsIgnoreCase("Nice Tit-for-Tat Agent"))
262 return a;// /agent doesn't work
263 else if (name.equalsIgnoreCase("HardHeaded"))
264 return new KLH();
265 else if (name.equalsIgnoreCase("WinnerAgent"))
266 return new WinnerAgent2();
267 else if (name.equalsIgnoreCase("AgentK2"))
268 return new Agent_K2();
269 else if (name.equalsIgnoreCase("TheNegotiator"))
270 return new TheNegotiator();
271 else if (name.equalsIgnoreCase("IAMhaggler2011"))
272 return a;// /agent doesn't work
273 else if (name.equalsIgnoreCase("DNAgent"))
274 return new DNAgent();
275 else if (name.equalsIgnoreCase("BRAMAgent"))
276 return new BRAMAgent();
277 else if (name.equalsIgnoreCase("MrFriendly"))
278 return new MrFriendly();
279 else if (name.equalsIgnoreCase("ShAgent"))
280 return new ShAgent();
281 else if (name.equalsIgnoreCase("simpleAgent"))
282 return new SimpleAgentNew();
283 else
284 return a;
285
286 }
287
288 @Override
289 public Action chooseAction() {
290 try {
291 if (!agentInit) {
292 if (actionOfPartner == null) // first bid, and Meta-Agent is the
293 // first bidder (still not
294 // initialized any agent)
295 {
296 first = true;
297 return new Offer(this.getAgentID(),
298 utilitySpace.getMaxUtilityBid());
299 } else // second bid, or first bid as responder (and not
300 // initiator)
301 {
302 agentInit = true;
303 if (actionOfPartner instanceof Offer) {
304 opponentFirstBid = utilitySpace
305 .getUtility(((Offer) actionOfPartner).getBid());
306 }
307
308 // initialize agent.
309 myAgent = selectAgent(getBestAgent());
310 myAgent.internalInit(0, 1, this.startTime, this.totalTime,
311 this.timeline, this.utilitySpace,
312 this.parametervalues, getAgentID());
313 myAgent.init();
314 // send the message that received to the new agent..
315 myAgent.ReceiveMessage(actionOfPartner);
316 }
317 }
318 Action a = myAgent.chooseAction();
319 if (a == null) {
320 return new Offer(this.getAgentID(),
321 utilitySpace.getMaxUtilityBid());
322 } else { // handle reservation value, because all agent are from
323 // Genius version 3.1 (and don't know what is
324 // reservation value)
325 double time = timeline.getTime();
326 if (a instanceof Offer
327 && this.utilitySpace.getReservationValueWithDiscount(
328 time) >= utilitySpace.getUtilityWithDiscount(
329 ((Offer) a).getBid(), time)) {
330 a = new EndNegotiation(getAgentID());
331 }
332
333 }
334 return a;
335
336 } catch (Exception e) {
337 return null;
338 }
339 }
340
341 @Override
342 public void ReceiveMessage(Action opponentAction) {
343 actionOfPartner = opponentAction;
344 if (agentInit)
345 myAgent.ReceiveMessage(opponentAction);
346 }
347
348 @Override
349 public String getName() {
350 if (myAgentName == null || myAgentName == "")
351 return "Meta-Agent 2012";
352 else
353 return "Meta-Agent 2012: " + myAgentName;
354 }
355
356 @Override
357 public String getVersion() {
358 return "1.42";
359 }
360
361 @Override
362 public SupportedNegotiationSetting getSupportedNegotiationSetting() {
363 return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
364 }
365
366 @Override
367 public String getDescription() {
368 return "ANAC2012";
369 }
370}
Note: See TracBrowser for help on using the repository browser.