1 | package agents.anac.y2018.agentnp1;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.TreeMap;
|
---|
9 |
|
---|
10 | import agents.anac.y2018.agentnp1.etc.bidSearch;
|
---|
11 | import genius.core.AgentID;
|
---|
12 | import genius.core.Bid;
|
---|
13 | import genius.core.actions.Accept;
|
---|
14 | import genius.core.actions.Action;
|
---|
15 | import genius.core.actions.EndNegotiation;
|
---|
16 | import genius.core.actions.Offer;
|
---|
17 | import genius.core.issue.Issue;
|
---|
18 | import genius.core.issue.IssueDiscrete;
|
---|
19 | import genius.core.issue.IssueInteger;
|
---|
20 | import genius.core.issue.IssueReal;
|
---|
21 | import genius.core.issue.Value;
|
---|
22 | import genius.core.issue.ValueInteger;
|
---|
23 | import genius.core.parties.AbstractNegotiationParty;
|
---|
24 | import genius.core.parties.NegotiationInfo;
|
---|
25 | import genius.core.utility.UtilitySpace;
|
---|
26 |
|
---|
27 | public class AgentNP1 extends AbstractNegotiationParty {
|
---|
28 | private NegotiationInfo info;
|
---|
29 | private UtilitySpace utilitySpace;
|
---|
30 | private List<Issue> issues;
|
---|
31 | private Action myAction;
|
---|
32 | private Bid myLastBid;
|
---|
33 | private Bid lastOppBid; // the last bid
|
---|
34 | private Bid offerBid;
|
---|
35 | private double geneUtil; //my agent generates a utility
|
---|
36 | private double recvUtil; // opponent's agenet generates a utility for my agent
|
---|
37 | private double rv; // reservation value
|
---|
38 | private double df; // discount factor
|
---|
39 | private int rounds; //negotiation rounds
|
---|
40 | private boolean upValueIntWeight;
|
---|
41 | private boolean issueContainIntType;
|
---|
42 | private boolean DF_RV;
|
---|
43 | private ArrayList<AgentID> opponents; // Negotiating partners' list
|
---|
44 | private ArrayList<Bid> allBids; // All Bids
|
---|
45 | private ArrayList<Double> oppUtil;
|
---|
46 | private ArrayList<Double> myUtil;
|
---|
47 | private HashMap<AgentID, List<Bid>> oppBidHistory; // opponent bids' history
|
---|
48 | private HashMap<AgentID, Map<Issue, Double>> IssueWeight; // issues & weights
|
---|
49 | private HashMap<AgentID, Map<Issue, List<ValueInteger>>> IssueIntValue;
|
---|
50 | private HashMap<AgentID, Map<Issue, Map<Value, Double>>> ValueFrequency;
|
---|
51 | private HashMap<AgentID, Double> oppSumDiff;
|
---|
52 | private AgentID hardestOpp;
|
---|
53 | private long startTime; // negotiation start time
|
---|
54 | private long currTime; // current time
|
---|
55 | private long diff;
|
---|
56 | private double totalTime;
|
---|
57 | private double normalizedTime;
|
---|
58 | // private long normalizedTime;
|
---|
59 | private bidSearch bidSearch;
|
---|
60 |
|
---|
61 | private Map<String, Integer> map;
|
---|
62 |
|
---|
63 | public AgentNP1() {
|
---|
64 | myAction = null;
|
---|
65 | myLastBid = null;
|
---|
66 | lastOppBid = null;
|
---|
67 | offerBid = null;
|
---|
68 | geneUtil = 0.0D;
|
---|
69 | recvUtil = 0.0D;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public void init(NegotiationInfo info) { //info,utility space, deadline, time, etc...information
|
---|
74 |
|
---|
75 | super.init(info); // call init AbstractNegotiationParty class
|
---|
76 | this.info = info;
|
---|
77 | utilitySpace = info.getUtilitySpace(); //confirm utility space
|
---|
78 | rv = utilitySpace.getReservationValue().doubleValue(); // reservation value
|
---|
79 | df = info.getUtilitySpace().getDiscountFactor(); //discount factor
|
---|
80 | issues = utilitySpace.getDomain().getIssues(); // issues which set within that domain
|
---|
81 | allBids = new ArrayList<Bid>();
|
---|
82 | oppUtil = new ArrayList<Double>();
|
---|
83 | myUtil = new ArrayList<Double>(); //my own bid utility
|
---|
84 | opponents = new ArrayList<AgentID>(); //negotiators list
|
---|
85 | oppBidHistory = new HashMap<AgentID, List<Bid>>(); //the history of the negotiators
|
---|
86 | IssueWeight = new HashMap<AgentID, Map<Issue, Double>>();
|
---|
87 | IssueIntValue = new HashMap<AgentID, Map<Issue, List<ValueInteger>>>();
|
---|
88 | ValueFrequency = new HashMap<AgentID, Map<Issue, Map<Value, Double>>>();
|
---|
89 | oppSumDiff = new HashMap<AgentID, Double>();
|
---|
90 | rounds = 0;
|
---|
91 | upValueIntWeight = false;
|
---|
92 | issueContainIntType = false;
|
---|
93 | DF_RV = false;
|
---|
94 | initTime();
|
---|
95 | issueContainIntType();
|
---|
96 |
|
---|
97 | map = new TreeMap<String, Integer>();
|
---|
98 |
|
---|
99 | try {
|
---|
100 | bidSearch = new bidSearch(utilitySpace, info);
|
---|
101 | } catch (Exception e) {
|
---|
102 | e.printStackTrace();
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | public void receiveMessage(AgentID sender, Action opponentAction) {
|
---|
108 |
|
---|
109 | super.receiveMessage(sender, opponentAction);
|
---|
110 | //System.out.println(sender);
|
---|
111 | if (sender != null && !opponents.contains(sender)) { // In the case of the first negotiating partner
|
---|
112 | opponents.add(sender); // Add sender to negotiating partner list
|
---|
113 | initOpp(sender); // Secure storage area for each sender
|
---|
114 | }
|
---|
115 |
|
---|
116 | // in case of "Offer" negotiation action
|
---|
117 | if (sender != null && opponentAction != null && (opponentAction instanceof Offer)) {
|
---|
118 | lastOppBid = ((Offer) opponentAction).getBid(); // Acquire current negotiation opponent bid (ex: price 3.5$, color red, vebdor docomo etc...)
|
---|
119 | recvUtil = utilitySpace.getUtility(lastOppBid);
|
---|
120 | allBids.add(lastOppBid); // add a bid
|
---|
121 | oppUtil.add(recvUtil);
|
---|
122 | updateOpp(sender);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
127 |
|
---|
128 | updateTime();
|
---|
129 | double timePerRound = timeline.getTime() / (double) rounds;
|
---|
130 | double remainingRounds = (1.0D - timeline.getTime()) / timePerRound;
|
---|
131 | double minimalThreshold = 0.6999999999999999;
|
---|
132 | double upperThreshold = 0.999999999999999;
|
---|
133 | double acceptThreshold = 0.779999999999999;
|
---|
134 | minimalThreshold = minimalThreshold * df;
|
---|
135 | rounds++;
|
---|
136 |
|
---|
137 | if (!possibleActions.contains("negotiator/actions/Accept")) {
|
---|
138 | if (timeline.getTime() > 0.0D && timeline.getTime() <= 0.9D) {
|
---|
139 | acceptThreshold = 0.81D;
|
---|
140 | if (recvUtil > acceptThreshold) {
|
---|
141 | return new Accept(getPartyId(), lastOppBid);
|
---|
142 | }
|
---|
143 | } else if (timeline.getTime() > 0.9D && timeline.getTime() <= 0.99D) {
|
---|
144 | acceptThreshold = 0.78D;
|
---|
145 | if (recvUtil > acceptThreshold) {
|
---|
146 | return new Accept(getPartyId(), lastOppBid);
|
---|
147 | } else if (!DF_RV && judge_DF_RV()) {
|
---|
148 | return new EndNegotiation(getPartyId());
|
---|
149 | }
|
---|
150 | } else if (timeline.getTime() > 0.97D ) {
|
---|
151 | if (recvUtil > rv) {
|
---|
152 | return new Accept(getPartyId(), lastOppBid);
|
---|
153 | } else if (recvUtil <= rv) {
|
---|
154 | return new EndNegotiation(getPartyId());
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | double max = 0.0D;
|
---|
159 | double sum = 0.0D;
|
---|
160 |
|
---|
161 | if (timeline.getTime() < 0.5D) {
|
---|
162 | minimalThreshold = 0.96 - (0.195 *timeline.getTime());
|
---|
163 | Bid myLastBid = bidSearch.getBid(generateRandomBid(), minimalThreshold);
|
---|
164 | geneUtil = utilitySpace.getUtility(myLastBid);
|
---|
165 | allBids.add(myLastBid); //add the created my own bid
|
---|
166 | myUtil.add(geneUtil );
|
---|
167 | System.out.println("[AgentNP Bid (" + rounds + ")]: " + myLastBid );
|
---|
168 | System.out.println("[AgentNP Utility (" + rounds + ")]: " + geneUtil );
|
---|
169 | return myAction = new Offer(getPartyId(), myLastBid);
|
---|
170 | } else if (timeline.getTime() >= 0.5D && timeline.getTime() < 0.7D) {
|
---|
171 | minimalThreshold = 0.85 - (0.105 *timeline.getTime());
|
---|
172 | Bid myLastBid = bidSearch.getBid(generateRandomBid(), minimalThreshold);
|
---|
173 | geneUtil = utilitySpace.getUtility(myLastBid);
|
---|
174 | allBids.add(myLastBid); //add the created my own bid
|
---|
175 | myUtil.add(geneUtil );
|
---|
176 | System.out.println("[AgentNP Bid (" + rounds + ")]: " + myLastBid );
|
---|
177 | System.out.println("[AgentNP Utility (" + rounds + ")]: " + geneUtil );
|
---|
178 | return myAction = new Offer(getPartyId(), myLastBid);
|
---|
179 | } else if (timeline.getTime() >= 0.7D && timeline.getTime() <0.95 ) {
|
---|
180 | for (int i = 0; i < oppUtil.size(); i++) {
|
---|
181 | sum += oppUtil.get(i);
|
---|
182 | max = Math.max(max, oppUtil.get(i));
|
---|
183 | }
|
---|
184 | double ave = sum / oppUtil.size();
|
---|
185 | if (max > 0.7799D && ave > 6.999D) {
|
---|
186 | minimalThreshold = ave ;
|
---|
187 | upperThreshold =max ;
|
---|
188 | } else {
|
---|
189 | minimalThreshold = ave + 0.095D ;
|
---|
190 | upperThreshold =max + 0.095D ;
|
---|
191 | }
|
---|
192 |
|
---|
193 | do {
|
---|
194 | myLastBid = generateRndBid();
|
---|
195 | geneUtil = utilitySpace.getUtility(myLastBid); // get utility value of Bid created randomly
|
---|
196 | for (int i = 0; i <myUtil.size(); i++) {
|
---|
197 | if (myUtil.get(i) == geneUtil) {
|
---|
198 | geneUtil = utilitySpace.getUtility(myLastBid); // get utility value of Bid created randomly
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | } while (geneUtil < minimalThreshold || geneUtil > upperThreshold); //When a random value smaller than mini is generated, generation is terminated
|
---|
203 |
|
---|
204 | allBids.add(myLastBid);
|
---|
205 | myUtil.add(geneUtil );
|
---|
206 | System.out.println("[AgentNP Bid (" + rounds + ")]: " + myLastBid );
|
---|
207 | System.out.println("[AgentNP Utility (" + rounds + ")]: " + geneUtil );
|
---|
208 | return myAction = new Offer(getPartyId(), myLastBid); //contents of bid
|
---|
209 |
|
---|
210 | } else if ( timeline.getTime() >= 0.95) {
|
---|
211 | for (int i = 0; i < oppUtil.size(); i++) {
|
---|
212 | sum += oppUtil.get(i);
|
---|
213 | max = Math.max(max, oppUtil.get(i));
|
---|
214 | }
|
---|
215 | double ave = sum / oppUtil.size();
|
---|
216 | if (max > 0.7799D && ave > 6.999D) {
|
---|
217 | minimalThreshold = ave ;
|
---|
218 | upperThreshold =max ;
|
---|
219 | } else {
|
---|
220 | minimalThreshold = ave + 0.0749 ;
|
---|
221 | upperThreshold =max + 0.0749 ;
|
---|
222 | } do {
|
---|
223 | myLastBid = generateRndBid(); // generate a random bid
|
---|
224 | geneUtil = utilitySpace.getUtility(myLastBid); // get utility value of Bid created randomly
|
---|
225 |
|
---|
226 | for (int i = 0; i <myUtil.size(); i++) {
|
---|
227 | if (myUtil.get(i) == geneUtil) {
|
---|
228 | geneUtil = utilitySpace.getUtility(myLastBid); // get utility value of Bid created randomly
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | } while (geneUtil < minimalThreshold || geneUtil > upperThreshold); //When a random value smaller than mini is generated, generation is terminated
|
---|
233 | allBids.add(myLastBid);
|
---|
234 | myUtil.add(geneUtil );
|
---|
235 | System.out.println("[AgentNP Bid (" + rounds + ")]: " + myLastBid );
|
---|
236 | System.out.println("[AgentNP Utility (" + rounds + ")]: " + geneUtil );
|
---|
237 | return myAction = new Offer(getPartyId(), myLastBid);
|
---|
238 | }
|
---|
239 |
|
---|
240 | }
|
---|
241 | return myAction;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /**
|
---|
245 | *
|
---|
246 | * @return
|
---|
247 | */
|
---|
248 |
|
---|
249 | private boolean judge_DF_RV() {
|
---|
250 |
|
---|
251 | double init = 1.0D;
|
---|
252 | double initRV = 0.75D;
|
---|
253 | boolean endNegotiation = false;
|
---|
254 |
|
---|
255 | for (double i = init; i >= 0.0D; i -= 0.01D) {
|
---|
256 | String df0 = String.format("%.2f", new Object[] { Double.valueOf(i) });
|
---|
257 | double df1 = Double.parseDouble(df0);
|
---|
258 | if (df == df1 && rv >= initRV) {
|
---|
259 | endNegotiation = true;
|
---|
260 | }
|
---|
261 | initRV -= 0.0050000000000000001D;
|
---|
262 | }
|
---|
263 | DF_RV = true;
|
---|
264 | return endNegotiation;
|
---|
265 | }
|
---|
266 |
|
---|
267 | /**
|
---|
268 | *
|
---|
269 | * @param sender
|
---|
270 | */
|
---|
271 | private void updateOpp(AgentID sender) {
|
---|
272 | if (timeline.getTime() < 0.07D) {
|
---|
273 | upValueIntWeight(sender);
|
---|
274 | }
|
---|
275 | upModelIssWeight(sender);
|
---|
276 | updateModelOppValueWeight(sender);
|
---|
277 | oppBidHistory.get(sender).add(lastOppBid);
|
---|
278 | retrieveToughestOpp();
|
---|
279 | }
|
---|
280 |
|
---|
281 | /**
|
---|
282 | *
|
---|
283 | * @param sender
|
---|
284 | */
|
---|
285 | private void upValueIntWeight(AgentID sender) {
|
---|
286 | for (Issue issue : issues) {
|
---|
287 | if (issue.getType().toString().equals("INTEGER")) {
|
---|
288 | ValueInteger currIssueValueInteger = (ValueInteger) lastOppBid.getValue(issue.getNumber());
|
---|
289 | IssueIntValue.get(sender).get(issue).add(currIssueValueInteger); //point
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 | if (timeline.getTime() < 0.07D && !upValueIntWeight) {
|
---|
294 | for (AgentID agent : IssueIntValue.keySet()) {
|
---|
295 | for (Issue issue : issues) {
|
---|
296 | if (issue.getType().toString().equals("INTEGER")) {
|
---|
297 | int sumLower = 0;
|
---|
298 | int sumUpper = 0;
|
---|
299 | int lowerB = ((IssueInteger) issue).getLowerBound();
|
---|
300 | int upperB = ((IssueInteger) issue).getUpperBound();
|
---|
301 | int mid = (lowerB + upperB) / 2;
|
---|
302 | double average = 1.0D / (double) (upperB - lowerB);
|
---|
303 |
|
---|
304 | for (int i = 0; i < IssueIntValue.get(agent).get(issue).size(); i++) {
|
---|
305 | int vv = Integer.parseInt(IssueIntValue.get(agent).get(issue).get(i).toString());
|
---|
306 | if (vv <= mid)
|
---|
307 | sumLower++;
|
---|
308 | else
|
---|
309 | sumUpper++;
|
---|
310 | }
|
---|
311 |
|
---|
312 | ValueInteger vL = new ValueInteger(lowerB);
|
---|
313 | ValueInteger vU = new ValueInteger(upperB);
|
---|
314 | if (sumLower > sumUpper) {
|
---|
315 | ValueFrequency.get(agent).get(issue).put(vL, Double.valueOf(1.0D));
|
---|
316 | ValueFrequency.get(agent).get(issue).put(vU, Double.valueOf(0.0D));
|
---|
317 | double adjustment = 1.0D;
|
---|
318 | for (int i = lowerB + 1; i < upperB; i++) {
|
---|
319 | adjustment -= average;
|
---|
320 | ValueInteger vI = new ValueInteger(i);
|
---|
321 | ValueFrequency.get(agent).get(issue).put(vI, Double.valueOf(adjustment));
|
---|
322 | }
|
---|
323 | } else {
|
---|
324 | ValueFrequency.get(agent).get(issue).put(vU, Double.valueOf(1.0D));
|
---|
325 | ValueFrequency.get(agent).get(issue).put(vL, Double.valueOf(0.0D));
|
---|
326 | double adjustment = 0.0D;
|
---|
327 | for (int i = lowerB + 1; i < upperB; i++) {
|
---|
328 | adjustment += average;
|
---|
329 | ValueInteger vI = new ValueInteger(i);
|
---|
330 | ValueFrequency.get(agent).get(issue).put(vI, Double.valueOf(adjustment));
|
---|
331 | }
|
---|
332 | }
|
---|
333 | }
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | upValueIntWeight = true;
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | private void upModelIssWeight(AgentID sender) { //calculate weight
|
---|
342 | if (oppBidHistory.get(sender).size() != 0 && timeline.getTime() > 0.05D) {
|
---|
343 | Bid formerRoundBid = oppBidHistory.get(sender).get((oppBidHistory.get(sender)).size() - 1);
|
---|
344 | double issueWeightFormula = Math.pow(1D - normalizedTime, 10D) / (double) (issues.size() * 100);
|
---|
345 | double issueWeightInteger = Math.pow(1D - normalizedTime, 10D) / (double) (issues.size() * 10);
|
---|
346 | double issueSum = 0.0D;
|
---|
347 |
|
---|
348 | for (Issue issue : issues) {
|
---|
349 | Value formIssueValue = formerRoundBid.getValue(issue.getNumber()); //selected former value
|
---|
350 | Value currIssueValue = lastOppBid.getValue(issue.getNumber()); //selected current value
|
---|
351 |
|
---|
352 | if (issueContainIntType) {
|
---|
353 | if (issue.getType().toString().equals("INTEGER")) {
|
---|
354 | if (incrIntIssWeight(issue, formIssueValue, currIssueValue)) {
|
---|
355 | IssueWeight.get(sender).put(issue, Double
|
---|
356 | .valueOf(IssueWeight.get(sender).get(issue).doubleValue() + issueWeightInteger));
|
---|
357 | }
|
---|
358 | } else if (formIssueValue == currIssueValue) {
|
---|
359 | IssueWeight.get(sender).put(issue, Double
|
---|
360 | .valueOf(IssueWeight.get(sender).get(issue).doubleValue() + issueWeightInteger));
|
---|
361 | }
|
---|
362 | } else if (formIssueValue == currIssueValue) {
|
---|
363 | IssueWeight.get(sender).put(issue,
|
---|
364 | Double.valueOf(IssueWeight.get(sender).get(issue).doubleValue() + issueWeightFormula));
|
---|
365 | }
|
---|
366 | issueSum += IssueWeight.get(sender).get(issue).doubleValue();
|
---|
367 | }
|
---|
368 |
|
---|
369 | for (Issue issue : issues) {
|
---|
370 | double normalizedIssueW = IssueWeight.get(sender).get(issue).doubleValue() / issueSum;
|
---|
371 | IssueWeight.get(sender).put(issue, Double.valueOf(normalizedIssueW)); //IssueWeight: weight
|
---|
372 | }
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | /**
|
---|
377 | *
|
---|
378 | * @param issue
|
---|
379 | * @param formIssueValue
|
---|
380 | * @param currIssueValue
|
---|
381 | * @return
|
---|
382 | */
|
---|
383 | public boolean incrIntIssWeight(Issue issue, Value formIssueValue, Value currIssueValue) {
|
---|
384 |
|
---|
385 | double arraySlot[] = new double[5];
|
---|
386 | boolean sameSection = false;
|
---|
387 | int pastV = Integer.parseInt(formIssueValue.toString());
|
---|
388 | int currV = Integer.parseInt(currIssueValue.toString());
|
---|
389 | int lowerB = ((IssueInteger) issue).getLowerBound();
|
---|
390 | int upperB = ((IssueInteger) issue).getUpperBound();
|
---|
391 | double formula = ((upperB - lowerB) + 1) / 5;
|
---|
392 | double increment = (double) lowerB + formula;
|
---|
393 | for (int i = 0; i < 4; i++) {
|
---|
394 | arraySlot[i] = increment;
|
---|
395 | increment += formula;
|
---|
396 | }
|
---|
397 |
|
---|
398 | arraySlot[4] = upperB;
|
---|
399 | if ((double) pastV <= arraySlot[0] && (double) currV <= arraySlot[0])
|
---|
400 | sameSection = true;
|
---|
401 | else if ((double) pastV <= arraySlot[1] && (double) currV <= arraySlot[1] && (double) pastV > arraySlot[0]
|
---|
402 | && (double) currV > arraySlot[0])
|
---|
403 | sameSection = true;
|
---|
404 | else if ((double) pastV <= arraySlot[2] && (double) currV <= arraySlot[2] && (double) pastV > arraySlot[1]
|
---|
405 | && (double) currV > arraySlot[1])
|
---|
406 | sameSection = true;
|
---|
407 | else if ((double) pastV <= arraySlot[3] && (double) currV <= arraySlot[3] && (double) pastV > arraySlot[2]
|
---|
408 | && (double) currV > arraySlot[2])
|
---|
409 | sameSection = true;
|
---|
410 | else if ((double) pastV <= arraySlot[4] && (double) currV <= arraySlot[4] && (double) pastV > arraySlot[3]
|
---|
411 | && (double) currV > arraySlot[3])
|
---|
412 | sameSection = true;
|
---|
413 | return sameSection;
|
---|
414 | }
|
---|
415 |
|
---|
416 | private void updateModelOppValueWeight(AgentID sender) {
|
---|
417 |
|
---|
418 | double valueWeightFormula = Math.pow(0.20000000000000001D, normalizedTime) / 30000D;
|
---|
419 | double valueWeightInteger = Math.pow(0.20000000000000001D, normalizedTime) / 955D;
|
---|
420 |
|
---|
421 | for (Issue issue : issues) {
|
---|
422 | if (issueContainIntType) {
|
---|
423 | if (!issue.getType().toString().equals("INTEGER")) {
|
---|
424 | Value value = lastOppBid.getValue(issue.getNumber());
|
---|
425 | ValueFrequency.get(sender).get(issue).put(value, Double.valueOf(
|
---|
426 | ValueFrequency.get(sender).get(issue).get(value).doubleValue() + valueWeightInteger));
|
---|
427 | }
|
---|
428 | } else {
|
---|
429 | Value value = lastOppBid.getValue(issue.getNumber());
|
---|
430 | ValueFrequency.get(sender).get(issue).put(value, Double.valueOf(
|
---|
431 | ValueFrequency.get(sender).get(issue).get(value).doubleValue() + valueWeightFormula));
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | for (Issue issue : issues) {
|
---|
436 | if (!issue.getType().toString().equals("INTEGER")) {
|
---|
437 | double maxValueBase = 0.0D;
|
---|
438 | for (Value value : ValueFrequency.get(sender).get(issue).keySet()) {
|
---|
439 | double currValueBase = ValueFrequency.get(sender).get(issue).get(value).doubleValue();
|
---|
440 | if (currValueBase > maxValueBase)
|
---|
441 | maxValueBase = currValueBase;
|
---|
442 | }
|
---|
443 |
|
---|
444 | for (Value value : ValueFrequency.get(sender).get(issue).keySet()) {
|
---|
445 | double normalizedValue = ValueFrequency.get(sender).get(issue).get(value).doubleValue()
|
---|
446 | / maxValueBase;
|
---|
447 | ValueFrequency.get(sender).get(issue).put(value, Double.valueOf(normalizedValue));
|
---|
448 | }
|
---|
449 | }
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | private void retrieveToughestOpp() {
|
---|
454 |
|
---|
455 | double hardestOppSumDiff = 0.0D;
|
---|
456 | double sumDiff;
|
---|
457 | for (AgentID agent : ValueFrequency.keySet()) {
|
---|
458 | sumDiff = 0.0D;
|
---|
459 | for (Issue issue : issues) {
|
---|
460 | double maxDiff = 0.0D;
|
---|
461 | for (Value value : ValueFrequency.get(agent).get(issue).keySet()) {
|
---|
462 | if (!issue.getType().toString().equals("INTEGER")) {
|
---|
463 | double diff = 1.0D - ValueFrequency.get(agent).get(issue).get(value).doubleValue();
|
---|
464 | if (diff > maxDiff)
|
---|
465 | maxDiff = diff;
|
---|
466 | }
|
---|
467 | }
|
---|
468 | sumDiff += maxDiff;
|
---|
469 | }
|
---|
470 | oppSumDiff.put(agent, Double.valueOf(sumDiff));
|
---|
471 | }
|
---|
472 |
|
---|
473 | for (AgentID agent : oppSumDiff.keySet()) {
|
---|
474 | if (oppSumDiff.get(agent).doubleValue() > hardestOppSumDiff) {
|
---|
475 | hardestOppSumDiff = oppSumDiff.get(agent).doubleValue();
|
---|
476 | hardestOpp = agent;
|
---|
477 | }
|
---|
478 | }
|
---|
479 | }
|
---|
480 |
|
---|
481 | /**
|
---|
482 | *
|
---|
483 | * @param sender
|
---|
484 | */
|
---|
485 | private void initOpp(AgentID sender) {
|
---|
486 |
|
---|
487 | try {
|
---|
488 | issueIntegerHandler(sender);
|
---|
489 | initModelIssueWeight(sender);
|
---|
490 | initModelValueFrequency(sender);
|
---|
491 | oppBidHistory.put(sender, new ArrayList<Bid>());
|
---|
492 | } catch (Exception e) {
|
---|
493 | e.printStackTrace();
|
---|
494 | }
|
---|
495 | }
|
---|
496 |
|
---|
497 | /**
|
---|
498 | *
|
---|
499 | * @param sender
|
---|
500 | */
|
---|
501 | private void issueIntegerHandler(AgentID sender) {
|
---|
502 |
|
---|
503 | IssueIntValue.put(sender, new HashMap<Issue, List<ValueInteger>>());
|
---|
504 | for (Issue issue : issues) {
|
---|
505 | if (issue.getType().toString().equals("INTEGER"))
|
---|
506 | IssueIntValue.get(sender).put(issue, new ArrayList<ValueInteger>());
|
---|
507 | }
|
---|
508 | }
|
---|
509 |
|
---|
510 | /**
|
---|
511 | * Weight
|
---|
512 | *
|
---|
513 | * @param sender
|
---|
514 | */
|
---|
515 | private void initModelIssueWeight(AgentID sender) {
|
---|
516 |
|
---|
517 | IssueWeight.put(sender, new HashMap<Issue, Double>());
|
---|
518 |
|
---|
519 | for (Issue issue : issues) {
|
---|
520 | IssueWeight.get(sender).put(issue, Double.valueOf(0.0D));
|
---|
521 | }
|
---|
522 |
|
---|
523 | int numIssues = IssueWeight.get(sender).keySet().size();
|
---|
524 | double avgW = 1.0D / (double) numIssues;
|
---|
525 | for (Issue issue : IssueWeight.get(sender).keySet()) {
|
---|
526 | IssueWeight.get(sender).put(issue, Double.valueOf(avgW));
|
---|
527 | }
|
---|
528 | }
|
---|
529 |
|
---|
530 | /**
|
---|
531 | *
|
---|
532 | * @param sender
|
---|
533 | */
|
---|
534 | private void initModelValueFrequency(AgentID sender) {
|
---|
535 |
|
---|
536 | ValueFrequency.put(sender, new HashMap<Issue, Map<Value, Double>>());
|
---|
537 |
|
---|
538 | for (Issue issue : issues) {
|
---|
539 | ValueFrequency.get(sender).put(issue, new HashMap<Value, Double>());
|
---|
540 |
|
---|
541 | if (!issue.getType().toString().equals("INTEGER")) {
|
---|
542 | for (Value value : getValues(issue)) {
|
---|
543 | ValueFrequency.get(sender).get(issue).put(value, Double.valueOf(1.0D));
|
---|
544 | }
|
---|
545 | }
|
---|
546 | }
|
---|
547 | }
|
---|
548 |
|
---|
549 | /**
|
---|
550 | *
|
---|
551 | * @param issue
|
---|
552 | * issue
|
---|
553 | * @return
|
---|
554 | */
|
---|
555 | public ArrayList<Value> getValues(Issue issue) {
|
---|
556 |
|
---|
557 | ArrayList<Value> values = new ArrayList<Value>();
|
---|
558 | switch (issue.getType()) {
|
---|
559 | case DISCRETE:
|
---|
560 | for (Value value : ((IssueDiscrete) issue).getValues()) {
|
---|
561 | values.add(value);
|
---|
562 | }
|
---|
563 | break;
|
---|
564 |
|
---|
565 | case REAL:
|
---|
566 | double min_value1 = ((IssueReal) issue).getLowerBound();
|
---|
567 | double max_value1 = ((IssueReal) issue).getUpperBound();
|
---|
568 | for (int i = (int) min_value1; (double) i <= max_value1; i++) {
|
---|
569 | Object valueObject = new Integer(i);
|
---|
570 | values.add((Value) valueObject);
|
---|
571 | }
|
---|
572 | break;
|
---|
573 |
|
---|
574 | case INTEGER:
|
---|
575 | int min_value = ((IssueInteger) issue).getLowerBound();
|
---|
576 | int max_value = ((IssueInteger) issue).getUpperBound();
|
---|
577 | for (int i = min_value; i <= max_value; i++) {
|
---|
578 | Object valueObject = new Integer(i);
|
---|
579 | values.add((Value) valueObject);
|
---|
580 | }
|
---|
581 | break;
|
---|
582 |
|
---|
583 | default:
|
---|
584 |
|
---|
585 | }
|
---|
586 |
|
---|
587 | return values;
|
---|
588 | }
|
---|
589 |
|
---|
590 | private void issueContainIntType() {
|
---|
591 |
|
---|
592 | for (Issue issue : issues) {
|
---|
593 | if (issue.getType().toString().equals("INTEGER")) {
|
---|
594 | issueContainIntType = true;
|
---|
595 | break;
|
---|
596 | }
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | private void updateTime() {
|
---|
601 |
|
---|
602 | currTime = System.currentTimeMillis();
|
---|
603 | diff = currTime - startTime;
|
---|
604 | normalizedTime= diff / totalTime;
|
---|
605 | }
|
---|
606 |
|
---|
607 | private void initTime() {
|
---|
608 |
|
---|
609 | startTime = System.currentTimeMillis();
|
---|
610 | totalTime = 180000D;
|
---|
611 | diff = 0L;
|
---|
612 | }
|
---|
613 |
|
---|
614 | protected Bid generateRndBid() {
|
---|
615 |
|
---|
616 | Bid randomBid = null;
|
---|
617 | HashMap<Integer, Value> values = new HashMap<Integer, Value>();
|
---|
618 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
619 | for (Issue issue : issues) {
|
---|
620 | try {
|
---|
621 | values.put(Integer.valueOf(issue.getNumber()), getRandomValue(issue));
|
---|
622 | } catch (Exception e) {
|
---|
623 | e.printStackTrace();
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | try {
|
---|
628 | randomBid = new Bid(utilitySpace.getDomain(), values);
|
---|
629 | } catch (Exception e) {
|
---|
630 | e.printStackTrace();
|
---|
631 | }
|
---|
632 | return randomBid;
|
---|
633 | }
|
---|
634 |
|
---|
635 | public String getAgentName() {
|
---|
636 | return "AgentNP1-1";
|
---|
637 | }
|
---|
638 |
|
---|
639 | @Override
|
---|
640 | public String getDescription() {
|
---|
641 | return "ANAC2018";
|
---|
642 | }
|
---|
643 |
|
---|
644 | }
|
---|