source: src/main/java/agents/anac/y2016/terra/etc/negotiationInfo.java

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

Initial import : Genius 9.0.0

File size: 11.4 KB
Line 
1package agents.anac.y2016.terra.etc;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6
7import genius.core.Bid;
8import genius.core.issue.Issue;
9import genius.core.issue.IssueDiscrete;
10import genius.core.issue.IssueInteger;
11import genius.core.issue.Value;
12import genius.core.issue.ValueDiscrete;
13import genius.core.utility.AbstractUtilitySpace;
14
15/**
16 * 交渉者の情報を蓄えて整理
17 */
18public class negotiationInfo {
19
20 /* 交渉に関する情報 */
21 private AbstractUtilitySpace utilitySpace; // 効用空間
22 private List<Issue> issues; // 論点
23 private int round = 0; // 自分の手番数
24 private boolean isLinerUtilitySpace = true; // 線形効用空間であるかどうか
25
26 /* 自分の情報 */
27 private ArrayList<Bid> myBidHistory;
28 private HashMap<Issue, ArrayList<Value>> myOfferValue;
29 private HashMap<Issue, HashMap<Value, Double>> valueRelativeUtility = null; // 自身の効用空間における各論点値の相対効用値行列(線形効用空間用)
30
31 /* 相手の情報 */
32 private ArrayList<Object> opponentList; // 交渉者リスト
33 private int negotiatonNum = 0; // 交渉者数
34
35 private HashMap<Object, ArrayList<Bid>> disagreedList; // 却下された提案リスト
36 private HashMap<Object, ArrayList<Bid>> agreedList; // 賛成された提案リスト
37 private HashMap<Object, ArrayList<Bid>> offeredList; // 提案された提案リスト
38
39 private HashMap<Object, ArrayList<Bid>> recentDisagreedList; // 最近却下された提案リスト
40 private HashMap<Object, ArrayList<Bid>> recentAgreedList; // 最近賛成された提案リスト
41 private HashMap<Object, ArrayList<Bid>> recentOfferedList; // 最近提案された提案リスト
42
43 private HashMap<Object, HashMap<Issue, ArrayList<Value>>> offeredValue;// 相手の提案内容の組み合わせ
44
45 /* init */
46 public negotiationInfo(AbstractUtilitySpace utilitySpace) {
47
48 /* 交渉に関する情報 */
49 this.utilitySpace = utilitySpace;
50 issues = utilitySpace.getDomain().getIssues();
51
52 /* 自分の情報 */
53 myBidHistory = new ArrayList<>();
54 myOfferValue = new HashMap<>();
55
56 valueRelativeUtility = new HashMap<Issue, HashMap<Value, Double>>();//
57 try {
58 initValueRelativeUtility();
59 } catch (Exception e) {
60 System.out.println("相対効用行列の初期化に失敗しました");
61 e.printStackTrace();
62 }
63
64 /* 相手の情報 */
65 opponentList = new ArrayList<>();
66
67 disagreedList = new HashMap<>();
68 agreedList = new HashMap<>();
69 offeredList = new HashMap<>();
70
71 recentDisagreedList = new HashMap<>();
72 recentAgreedList = new HashMap<>();
73 recentOfferedList = new HashMap<>();
74
75 offeredValue = new HashMap<>();
76 }
77
78 private void initValueRelativeUtility() throws Exception {
79 ArrayList<Value> values = null;
80 for (Issue issue : issues) {
81 valueRelativeUtility.put(issue, new HashMap<Value, Double>()); // 論点行の初期化
82 values = getValues(issue);
83 for (Value value : values) {
84 valueRelativeUtility.get(issue).put(value, 0.0);
85 } // 論点行の要素の初期化
86 }
87 }
88
89 /* Set */
90 public void updateOpponents(Object agent, int negotiationNum) {
91 // if(agent.equals(null))return;
92 if (!opponentList.contains(agent))
93 opponentList.add(agent);
94 this.negotiatonNum = negotiationNum;
95
96 if (!offeredList.containsKey(agent))
97 offeredList.put(agent, new ArrayList<Bid>());
98
99 if (!disagreedList.containsKey(agent))
100 disagreedList.put(agent, new ArrayList<Bid>());
101
102 if (!agreedList.containsKey(agent))
103 agreedList.put(agent, new ArrayList<Bid>());
104
105 if (!offeredList.containsKey(agent))
106 offeredList.put(agent, new ArrayList<Bid>());
107
108 if (!offeredValue.containsKey(agent))
109 offeredValue.put(agent, new HashMap<Issue, ArrayList<Value>>());
110 }
111
112 public void utilitySpaceTypeisNonLiner() {
113 isLinerUtilitySpace = false;
114 }
115
116 public void setValueRelativeUtility(Bid maxBid) throws Exception {
117 ArrayList<Value> values = null;
118 Bid currentBid = null;
119 for (Issue issue : issues) {
120 currentBid = new Bid(maxBid);
121 values = getValues(issue);
122 for (Value value : values) {
123 currentBid = currentBid.putValue(issue.getNumber(), value);
124 valueRelativeUtility.get(issue).put(
125 value,
126 utilitySpace.getUtility(currentBid)
127 - utilitySpace.getUtility(maxBid));
128 }
129 }
130 }
131
132 /* Add */
133 public void addMyBidHistory(Bid bid) {
134 round++;
135 myBidHistory.add(bid);
136
137 HashMap<Issue, ArrayList<Value>> tHashMap = new HashMap<>();
138 tHashMap = myOfferValue;
139 for (Issue issues : getIssues()) {
140 ArrayList<Value> tValues = new ArrayList<>();
141 if (tHashMap.containsKey(issues)) {
142 tValues = myOfferValue.get(issues);
143 }
144
145 tValues.add(bid.getValue(issues.getNumber()));
146
147 tHashMap.put(issues, tValues);
148 }
149 myOfferValue = tHashMap;
150 }
151
152 public void addDisagreedList(Object agent, Bid bid) {
153 ArrayList<Bid> tList = new ArrayList<>();
154 tList = disagreedList.get(agent);
155 tList.add(bid);
156 disagreedList.put(agent, tList);
157
158 ArrayList<Bid> tList2 = new ArrayList<>();
159 for (int i = 1; i <= 12; i++) {
160 if (tList.size() - i < 0)
161 break;
162 tList2.add(tList.get(tList.size() - i));
163 }
164 recentDisagreedList.put(agent, tList2);
165 return;
166 }
167
168 public void addAgreedList(Object agent, Bid bid) {
169 ArrayList<Bid> tList = new ArrayList<>();
170 tList = agreedList.get(agent);
171 tList.add(bid);
172 agreedList.put(agent, tList);
173
174 ArrayList<Bid> tList2 = new ArrayList<>();
175 for (int i = 1; i <= 12; i++) {
176 if (tList.size() - i < 0)
177 break;
178 tList2.add(tList.get(tList.size() - i));
179 }
180 recentAgreedList.put(agent, tList2);
181 return;
182 }
183
184 public void addOfferedList(Object agent, Bid bid) {
185 ArrayList<Bid> tList = new ArrayList<>();
186 tList = offeredList.get(agent);
187 tList.add(bid);
188 offeredList.put(agent, tList);
189
190 ArrayList<Bid> tList2 = new ArrayList<>();
191 for (int i = 1; i <= 6; i++) {
192 if (tList.size() - i < 0)
193 break;
194 tList2.add(tList.get(tList.size() - i));
195 }
196 recentOfferedList.put(agent, tList2);
197
198 addOfferedValue(agent, bid);
199 return;
200 }
201
202 private void addOfferedValue(Object agent, Bid bid) {
203 HashMap<Issue, ArrayList<Value>> tHashMap = new HashMap<>();
204 tHashMap = offeredValue.get(agent);
205
206 for (Issue issues : getIssues()) {
207 ArrayList<Value> tValues = new ArrayList<>();
208 if (tHashMap.containsKey(issues)) {
209 tValues = offeredValue.get(agent).get(issues);
210 }
211
212 tValues.add(bid.getValue(issues.getNumber()));
213
214 tHashMap.put(issues, tValues);
215 }
216 offeredValue.put(agent, tHashMap);
217 }
218
219 /* Get */
220 public ArrayList<Bid> getMyHistory() {
221 return myBidHistory;
222 }
223
224 public HashMap<Issue, ArrayList<Value>> getMyOfferValue() {
225 return myOfferValue;
226 }
227
228 public List<Issue> getIssues() {
229 return issues;
230 }
231
232 public HashMap<Issue, HashMap<Value, Double>> getValueRelativeUtility() {
233 return valueRelativeUtility;
234 }
235
236 public HashMap<Object, ArrayList<Bid>> getDisagreedList() {
237 return disagreedList;
238 }; // 却下された提案リスト
239
240 public HashMap<Object, ArrayList<Bid>> getAgreedList() {
241 return agreedList;
242 } // 賛成された提案リスト
243
244 public HashMap<Object, ArrayList<Bid>> getOfferedList() {
245 return offeredList;
246 } // 提案された提案リスト
247
248 public ArrayList<Object> getOpponet() {
249 return opponentList;
250 } // 相手リスト
251
252 public HashMap<Object, HashMap<Issue, ArrayList<Value>>> getOfferedValue() {
253 return offeredValue;
254 }// 提案されたValue
255
256 public HashMap<Object, ArrayList<Bid>> getRecentDisagreedList() {
257 return recentDisagreedList;
258 }; // 最近の却下された提案リスト
259
260 public HashMap<Object, ArrayList<Bid>> getRecentAgreedList() {
261 return recentAgreedList;
262 } // 最近の賛成された提案リスト
263
264 public HashMap<Object, ArrayList<Bid>> getRecentOfferedList() {
265 return recentOfferedList;
266 } // 最近の提案された提案リスト
267
268 // Issue毎に何回Valueが提案されたかを数える
269 public HashMap<Issue, HashMap<Value, Integer>> getOfferedValueNum(
270 Object agent) {
271 HashMap<Issue, ArrayList<Value>> tHashMap = offeredValue.get(agent);
272 return getOfferedValueNum(tHashMap);
273 }
274
275 public HashMap<Issue, HashMap<Value, Integer>> getOfferedValueNum() {
276 HashMap<Issue, HashMap<Value, Integer>> answer = new HashMap<>();
277 for (Object agent : getOpponet()) {
278 HashMap<Issue, ArrayList<Value>> hashMap = offeredValue.get(agent);
279 for (Issue issue : getIssues()) {
280 if (hashMap.containsKey(issue)) {
281 HashMap<Value, Integer> tHashMap = new HashMap<>();
282 if (answer.containsKey(issue))
283 tHashMap = answer.get(issue);// 前のエージェントの論点の値を考慮
284
285 for (Value tValue : hashMap.get(issue)) {
286 if (tHashMap.containsKey(tValue)) {// 値がすでに出ていれば数に1足す
287 tHashMap.put(tValue, tHashMap.get(tValue) + 1);
288 } else {// 未出であれば1を加える
289 tHashMap.put(tValue, 1);
290 }
291 }
292 answer.put(issue, tHashMap);
293 }
294 }
295 }
296 return answer;
297 }
298
299 public HashMap<Issue, HashMap<Value, Integer>> getOfferedValueNum(
300 HashMap<Issue, ArrayList<Value>> hashMap) {
301 HashMap<Issue, HashMap<Value, Integer>> answer = new HashMap<>();
302
303 for (Issue issue : getIssues()) {
304 if (hashMap.containsKey(issue)) {
305 HashMap<Value, Integer> tHashMap = new HashMap<>();
306 for (Value tValue : hashMap.get(issue)) {
307 if (tHashMap.containsKey(tValue)) {// 値がすでに出ていれば数に1足す
308 tHashMap.put(tValue, tHashMap.get(tValue) + 1);
309 } else {// 未出であれば1を加える
310 tHashMap.put(tValue, 1);
311 }
312 }
313 answer.put(issue, tHashMap);
314 }
315 }
316 return answer;
317 }
318
319 // 与えられたBidリストの効用値の平均値を返す
320 public HashMap<Object, Double> getUtilityAverage(
321 HashMap<Object, ArrayList<Bid>> bidList) {
322 HashMap<Object, Double> ans = new HashMap<>();
323 for (Object agent : bidList.keySet()) {
324 if (bidList.containsKey(agent)) {
325 ArrayList<Bid> tList = bidList.get(agent);
326 double ave = 0;
327 for (Bid tBid : tList) {
328 ave += utilitySpace.getUtility(tBid);
329 }
330 ave /= tList.size();
331 ans.put(agent, ave);
332 }
333 }
334 return ans;
335 };
336
337 // 与えられたBidリストの効用値の最大値を返す
338 public HashMap<Object, Double> getUtilityMax(
339 HashMap<Object, ArrayList<Bid>> bidList) {
340 HashMap<Object, Double> ans = new HashMap<>();
341 for (Object agent : opponentList) {
342 ArrayList<Bid> tList = bidList.get(agent);
343 ans.put(agent, 0.0);
344 for (Bid tBid : tList) {
345 double tvalue = utilitySpace.getUtility(tBid);
346 if (tvalue > ans.get(agent)) {
347 ans.put(agent, tvalue);
348 }
349 }
350 }
351 return ans;
352 };
353
354 // ターン数を取得
355 // public int getRound(){return round;}
356
357 // Issue毎のValueを取得
358 public ArrayList<Value> getValues(Issue issue) {
359 ArrayList<Value> values = new ArrayList<Value>();
360 switch (issue.getType()) {
361 case DISCRETE:
362 List<ValueDiscrete> valuesDis = ((IssueDiscrete) issue).getValues();
363 for (Value value : valuesDis) {
364 values.add(value);
365 }
366 break;
367 case INTEGER:
368 int min_value = ((IssueInteger) issue).getUpperBound();
369 int max_value = ((IssueInteger) issue).getUpperBound();
370 for (int j = min_value; j <= max_value; j++) {
371 Object valueObject = new Integer(j);
372 values.add((Value) valueObject);
373 }
374 break;
375 default:
376 try {
377 throw new Exception("issue type " + issue.getType()
378 + " not supported by Atlas3");
379 } catch (Exception e) {
380 System.out.println("論点の取り得る値の取得に失敗しました");
381 e.printStackTrace();
382 }
383 }
384 return values;
385 }
386
387 /* Bool */
388 public boolean isLinerUtilitySpace() {
389 return isLinerUtilitySpace;
390 }
391}
Note: See TracBrowser for help on using the repository browser.