source: src/main/java/agents/anac/y2018/agent33/etc/NegoStats.java

Last change on this file was 343, checked in by Tim Baarslag, 4 years ago

Fixed all errors in all 2018 agents

File size: 38.9 KB
Line 
1 package agents.anac.y2018.agent33.etc;
2
3import java.util.List;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.Iterator;
8
9import genius.core.Bid;
10import genius.core.issue.Issue;
11import genius.core.issue.IssueDiscrete;
12import genius.core.issue.IssueInteger;
13import genius.core.issue.Value;
14import genius.core.issue.ValueDiscrete;
15import genius.core.parties.NegotiationInfo;
16
17
18public class NegoStats {
19 private NegotiationInfo info;
20 private boolean isPrinting = false; // デバッグ用
21 private boolean isPrinting_Stats = false;
22
23 // 交渉における基本情報
24 private List<Issue> issues;
25 private ArrayList<Object> rivals;
26 private int negotiatorNum = 0; // 交渉者数
27 private boolean isLinerUtilitySpace = true; // 線形効用空間であるかどうか
28 private HashMap<Issue, HashMap<Value, Double>> valueRelativeUtility = null; // 自身の効用空間における各論点値の相対効用値行列(線形効用空間用)
29 /**
30 * 2015/5/22 頻度を小数にする
31 * 重みをつけるための係数
32 */
33 private HashMap<Object, HashMap<Issue, HashMap<Value, Double>>> agreedValueFrequency1 = null;
34 private double weightFrequencyRate = 0.01;
35 private double weightF = 1.0;
36 /**
37 * 2015/5/22-----2
38 * agree valueのカウント個数を時間の長さで決める
39 */
40 private double countTime = 0.25;
41
42
43 // current session の提案履歴
44 private ArrayList<Bid> myBidHist = null;
45 private HashMap<Object, ArrayList<Bid>> rivalsBidHist = null;
46 private HashMap<Object, HashMap<Issue, HashMap<Value, Integer>>> agreedValueFrequency = null;
47
48
49 private HashMap<Object, HashMap<Issue, HashMap<Value, Integer>>> rejectedValueFrequency = null;
50
51
52 // 交渉相手の統計情報
53 private HashMap<Object, Double> rivalsMean = null;
54 private HashMap<Object, Double> rivalsVar = null;
55 private HashMap<Object, Double> rivalsSum = null;
56 private HashMap<Object, Double> rivalsPowSum = null;
57 private HashMap<Object, Double> rivalsSD = null;
58
59 private HashMap<Object, Double> rivalsMax = null; // 今sessionにおける相手の提案に対する自身の最大効用値
60 private HashMap<Object, Double> rivalsMin = null; // 今sessionにおける相手の提案に対する自身の最低効用値
61
62 /**
63 * 2018/5/23
64 * 相手の重視情報
65 */
66 private HashMap<Object, ArrayList<HashMap<Issue,Value>>> rivalsValuePrior = null;//今sessionにおける相手の提案に対する相手の重視value
67 private HashMap<Object,ArrayList<HashMap<Issue,Value>>> valuePrior = null; //今session相手の重視issueとそのissueの最重視valueのlist
68 private HashMap<Object,HashMap<Issue,Double>> valueAgreeRateSD = null;//今session相手の各issueのvalueAgreeRateの標準偏差
69 //private HashMap<Issue,Value> issueValuePrior_tmp = null;
70
71 /**
72 * 2018/5/24
73 */
74 private HashMap<Issue,ArrayList<Value>> valuePriorAll = null;//今sessionにおける全相手が重視するissueとその重視value
75
76 public NegoStats(NegotiationInfo info, boolean isPrinting){
77 this.info = info;
78 this.isPrinting = isPrinting;
79
80 // 交渉における基本情報
81 issues = info.getUtilitySpace().getDomain().getIssues();
82 rivals = new ArrayList<Object>();
83 valueRelativeUtility = new HashMap<Issue, HashMap<Value, Double>> ();
84
85 // current session の提案履歴
86 myBidHist = new ArrayList<Bid>();
87 rivalsBidHist = new HashMap<Object, ArrayList<Bid>>();
88 agreedValueFrequency = new HashMap<Object, HashMap<Issue, HashMap<Value, Integer>>> (); // Value毎のAccept数
89 rejectedValueFrequency = new HashMap<Object, HashMap<Issue, HashMap<Value, Integer>>> (); // Value毎のReject数
90
91 /**
92 * 2018/5/29
93 * 相手の重視情報
94 */
95 rivalsValuePrior = new HashMap<Object, ArrayList<HashMap<Issue,Value>>>();
96 valuePrior = new HashMap<Object,ArrayList<HashMap<Issue,Value>>>();
97 valueAgreeRateSD = new HashMap<Object,HashMap<Issue,Double>>();
98
99 try {
100 initValueRelativeUtility();
101 } catch (Exception e) {
102 System.out.println("[Exception_Stats] 相対効用行列の初期化に失敗しました");
103 e.printStackTrace();
104 }
105
106 // 交渉相手の統計情報
107 rivalsMean = new HashMap<Object, Double>();
108 rivalsVar = new HashMap<Object, Double>();
109 rivalsSum = new HashMap<Object, Double>();
110 rivalsPowSum = new HashMap<Object, Double>();
111 rivalsSD = new HashMap<Object, Double>();
112
113 rivalsMax = new HashMap<Object, Double>();
114 rivalsMin = new HashMap<Object, Double>();
115
116 if(this.isPrinting){
117 System.out.println("[isPrinting] NegoStats: success");
118 }
119
120 }
121
122 public void initRivals(Object sender) {
123 System.out.println("initRivalsが始まる");
124 initNegotiatingInfo(sender); // 交渉情報を初期化
125 rivals.add(sender); // 交渉参加者にsenderを追加
126 }
127
128 public void updateInfo(Object sender, Bid offeredBid) {
129 try {
130 //System.out.println("??????????????????????");
131 updateNegoStats(sender, offeredBid); // 交渉情報の更新
132
133 } catch (Exception e1) {
134 System.out.println("[Exception_Stats] 交渉情報の更新に失敗しました");
135 e1.printStackTrace();
136 }
137 }
138
139 private void initNegotiatingInfo(Object sender) {
140 rivalsBidHist.put(sender, new ArrayList<Bid>());
141 //rivalsBidHist.put(sender, null);
142 //System.out.println("rivalsBidHist:" + rivalsBidHist);
143 rivalsMean.put(sender, 0.0);
144 rivalsVar.put(sender, 0.0);
145 rivalsSum.put(sender, 0.0);
146 rivalsPowSum.put(sender, 0.0);
147 rivalsSD.put(sender, 0.0);
148
149 rivalsMax.put(sender, 0.0);
150 rivalsMin.put(sender, 1.0);
151
152 /**
153 * 2018/5/23
154 * 重要valueの初期化
155 */
156 //System.out.println("initNegotiatingInfo");
157 rivalsValuePrior.put(sender, new ArrayList<HashMap<Issue,Value>>());
158 //System.out.println("rivalsValuePrior:" + rivalsValuePrior);
159 valuePrior.put(sender, new ArrayList<HashMap<Issue,Value>>());
160 //System.out.println("valuePrior:" + valuePrior);
161 }
162
163 /**
164 * 交渉者数を更新する
165 * @param num
166 */
167 public void updateNegotiatorsNum(int num) {
168 negotiatorNum = num;
169 }
170
171
172 /**
173 * 線形効用空間でない場合
174 */
175 public void utilSpaceTypeisNonLiner() {
176 isLinerUtilitySpace = false;
177 }
178
179 /**
180 * 相対効用行列の初期化
181 * @throws Exception
182 */
183 private void initValueRelativeUtility() throws Exception{
184 //ArrayList<Value> values = null;
185 ArrayList<Object> rivals = getRivals();
186
187 for(Issue issue:issues){
188 valueRelativeUtility.put(issue, new HashMap<Value, Double>()); // 論点行の初期化
189
190 // 論点行の要素の初期化
191 ArrayList<Value> values = getValues(issue);
192 for(Value value:values){
193 valueRelativeUtility.get(issue).put(value, 0.0);
194 }
195 }
196 }
197
198 // 相対効用行列の導出
199 public void setValueRelativeUtility(Bid maxBid) throws Exception {
200 ArrayList<Value> values = null;
201 Bid currentBid = null;
202 for(Issue issue:issues){
203 currentBid = new Bid(maxBid);
204 values = getValues(issue);
205 for(Value value:values){
206 currentBid = currentBid.putValue(issue.getNumber(), value);
207 valueRelativeUtility.get(issue).put(value,
208 info.getUtilitySpace().getUtility(currentBid) - info.getUtilitySpace().getUtility(maxBid));
209 }
210 }
211 System.out.println("SetValueRelatility OK!");
212 }
213
214 /**
215 * Agent senderが受け入れたValueの頻度を更新
216 * @param sender
217 * @param bid
218 */
219 public void updateAgreedValues(Object sender, Bid bid){
220 // senderが過去に登場していない場合は初期化
221 if(!agreedValueFrequency.containsKey(sender)){
222 agreedValueFrequency.put(sender, new HashMap<Issue, HashMap<Value, Integer>> ());
223
224 for(Issue issue : issues){
225 agreedValueFrequency.get(sender).put(issue, new HashMap<Value, Integer>());
226
227 ArrayList<Value> values = getValues(issue);
228 for(Value value : values){
229 agreedValueFrequency.get(sender).get(issue).put(value, 0);
230 }
231 }
232 }
233 /**
234 * 2018/5/22----2
235 * 最初の30sの個数だけカウント
236 */
237 System.out.println("+++++++++time:" + info.getTimeline().getTime());
238 //if(info.getTimeline().getTime() <= countTime) {
239 // 各issue毎に個数をカウント
240 for(Issue issue : issues) {
241 Value value = bid.getValue(issue.getNumber());
242 agreedValueFrequency.get(sender).get(issue).put(value, agreedValueFrequency.get(sender).get(issue).get(value) + 1);
243 }
244 // }
245
246 if(isPrinting_Stats){
247 System.out.println("[isPrint_Stats] (ACCEPT) " + sender.toString() + ":");
248 for(Issue issue : issues){
249 ArrayList<Value> values = getValues(issue);
250 for(Value value : values){
251 System.out.print(agreedValueFrequency.get(sender).get(issue).get(value) + " ");
252 }
253 System.out.println();
254 }
255
256
257 getMostAgreedValues(sender);
258 }
259 }
260
261 /**
262 * 2018/5/23
263 * 各agentに重視issueとその最重視valueを探す
264 */
265 public void valuePriorSearch(Object sender) {
266
267 double issuePriorSD1; //重要度1のissueの標準偏差
268 double issuePriorSD2; //重要度2のissueの標準偏差
269
270 // HashMap<Issue,Value> issuePrior = new HashMap<Issue,Value>();//重視issue
271 //System.out.println("issuePrior:" + issuePrior);
272 ArrayList<HashMap<Issue,Value>> issueValuePrior = new ArrayList<HashMap<Issue,Value>>();//各issueとその最重視valueのlist
273 // System.out.println("issueValuePrior:" + issueValuePrior);
274 valuePrior.put(sender, new ArrayList<HashMap<Issue,Value>>()); //今session相手の重視issueとそのissueの最重視valueのlistの初期化
275
276 // System.out.println("issues:" + issues);
277 //各issueとその最重視valueを探す
278 for(Issue issue: issues) {
279 ArrayList<Value> values = getValues(issue);
280
281 //issueごとに最重視valueを返す
282 double valueAgreeRate_tmp = 0.0;
283 HashMap<Issue, Value> issueValuePrior_tmp = new HashMap<Issue,Value>();
284
285 for(Value value: values) {
286 //issueの最大valueを調べる
287 if(agreedValueFrequency.get(sender).get(issue).get(value) > valueAgreeRate_tmp) {
288 valueAgreeRate_tmp = agreedValueFrequency.get(sender).get(issue).get(value);
289 issueValuePrior_tmp.put(issue, value);
290 }
291 }
292 //issueとその最大valueのセットをlistに追加
293 issueValuePrior.add(issueValuePrior_tmp);
294 }
295
296 // System.out.println("issueValuePrior:" + issueValuePrior);
297 issuePriorSD1 = selectPriorIssueValue(sender, issueValuePrior, 0.0);
298 if(issues.size() > 2) {//issueが2個以上の場合
299 issuePriorSD2 = selectPriorIssueValue(sender, issueValuePrior, issuePriorSD1);
300 }
301 }
302
303 /**
304 * 2018/5/23
305 * 重視issueとその最重視valueをlistに追加
306 */
307 //public double selectPriorIssueValue(Object sender, HashMap<Issue,Value> issuePrior,
308 // ArrayList<HashMap<Issue,Value>> issueValuePrior, double issuePriorSD1){
309 public double selectPriorIssueValue(Object sender,
310 ArrayList<HashMap<Issue,Value>> issueValuePrior, double issuePriorSD1){
311
312 double compareSD = 0.0;
313 /**2018/5/30
314 *
315 */
316 HashMap<Issue,Value> issuePrior = new HashMap<Issue,Value>();//重視issue
317 // issuePrior = null;
318 System.out.println("issuePrior:" + issuePrior);
319
320
321 for(Issue issue: issues) {
322 ArrayList<Value> values = getValues(issue);
323
324 double sumValueAgreeRate = 0.0; //issueごとに全てのvalueAgreeRateの和
325 double valueAgreeRateMean = 0.0; //issueごとに全てのvalueAgreeRateの平均
326 double valueAgreeRateSD_tmp = 0.0; //issueごとに全てのvalueAgreeRateの標準偏差
327 double issueSize = agreedValueFrequency.get(sender).get(issue).size();//issueの中のvalue個数
328 HashMap<Object,HashMap<Issue,Double>> valueAgreeRateSD = new HashMap<Object,HashMap<Issue,Double>>();
329
330 //issueごとに全てのvalueAgreeRateの和を求める
331 for(Value value: values) {
332 sumValueAgreeRate += agreedValueFrequency.get(sender).get(issue).get(value);
333 }
334
335 //issueごとにvalueAgreeRateの平均を求める
336 for(Value value: values) {
337 valueAgreeRateMean += agreedValueFrequency.get(sender).get(issue).get(value) / sumValueAgreeRate;
338 }
339 valueAgreeRateMean /= issueSize;
340
341 //issueごとにvalueAgreeRateの標準偏差を求める
342 for(Value value: values) {
343 valueAgreeRateSD_tmp += Math.pow((agreedValueFrequency.get(sender).get(issue).get(value) - valueAgreeRateMean),2);
344 }
345 valueAgreeRateSD_tmp /= issueSize;
346 valueAgreeRateSD_tmp = Math.sqrt(valueAgreeRateSD_tmp);
347
348 //issueとその標準偏差をセット
349 System.out.println("valueAgreeRateSD.get(sender):" + valueAgreeRateSD.get(sender));
350 HashMap<Issue, Double> issueSD = new HashMap<Issue, Double>();
351 //System.out.println("issueSD:" + issueSD);
352 issueSD.put(issue,valueAgreeRateSD_tmp);
353 valueAgreeRateSD.put(sender, issueSD);
354 //System.out.println("valueAgreeRateSD.get(" + sender + "):" + valueAgreeRateSD.get(sender));
355 //System.out.println("valueAgreeRateSD_tmp:" + valueAgreeRateSD_tmp);
356 //System.out.println("compareSD:" + compareSD);
357 //System.out.println("issuePriorSD1:" + issuePriorSD1);
358
359 //標準偏差が最大のissueとその最重視valueをpick out
360 //System.out.println("issuePrior:" + issuePrior);
361 //System.out.println("issue:" + issue);
362 //System.out.println("valuePrior.get(sender):" + valuePrior.get(sender));
363 if(valueAgreeRateSD_tmp > compareSD && issuePriorSD1 != valueAgreeRateSD_tmp) //1回目探索するとき
364 { //2番目のissueを探索するとき、1回目を回避
365 //if(valueAgreeRateSD_tmp > compareSD && issuePriorSD1 != valueAgreeRateSD_tmp) {
366 compareSD = valueAgreeRateSD_tmp;
367
368 //issuePrior = issueValuePrior.get(issue.getNumber());
369 /**
370 * 2018/5/30
371 * issueの順番が違うため
372 * issue.getNumber()使えない
373 */
374 for (HashMap<Issue, Value> issueValuePriorOne: issueValuePrior) {
375 if(issueValuePriorOne.containsKey(issue)) {
376 issuePrior.clear();
377 issuePrior.put(issue, issueValuePriorOne.get(issue));
378 System.out.println("issuePrior:" + issuePrior);
379 break;
380 }
381 }
382 }
383 }
384
385 //重視issueとその最重視valueを保存
386 //System.out.println("valuePrior.get(sender):" + valuePrior.get(sender));
387 ArrayList<HashMap<Issue,Value>> valuePriorGet = new ArrayList<HashMap<Issue,Value>>();
388 valuePriorGet = valuePrior.get(sender);
389 //System.out.println("valuePriorGet:" + valuePriorGet);
390 //System.out.println("issuePrior:" + issuePrior);
391 if(!issuePrior.isEmpty()) {
392 //System.out.println("&&&&&&&&&&&&&&&");
393 valuePriorGet.add(issuePrior);
394 }
395 // System.out.println("valuePriorGet:" + valuePriorGet);
396
397
398 valuePrior.put(sender, valuePriorGet);
399 //System.out.println("valuePrior:" + valuePrior);
400
401
402 return compareSD;
403 }
404
405
406 /**
407 * 2018/5/22
408 * Agent senderが受け入れたValueの頻度を更新
409 * 頻度も時間とともに重み付きで減少、小数となる
410 */
411 public void updateAgreedValues1(Object sender, Bid bid){
412 // senderが過去に登場していない場合は初期化
413 if(!agreedValueFrequency1.containsKey(sender)){
414 agreedValueFrequency1.put(sender, new HashMap<Issue, HashMap<Value, Double>> ());
415
416 for(Issue issue : issues){
417 agreedValueFrequency1.get(sender).put(issue, new HashMap<Value, Double>());
418
419 ArrayList<Value> values = getValues(issue);
420 for(Value value : values){
421 agreedValueFrequency1.get(sender).get(issue).put(value, 0.0);
422 }
423 }
424 }
425
426 // 各issue毎に個数をカウント
427 for(Issue issue : issues) {
428 Value value = bid.getValue(issue.getNumber());
429 agreedValueFrequency1.get(sender).get(issue).put(value, agreedValueFrequency1.get(sender).get(issue).get(value) + weightF);
430 }
431
432 if(weightF > 0 ) {
433 weightF = weightF - weightFrequencyRate; //頻度の重みを更新
434 }
435
436 if(isPrinting_Stats){
437 System.out.println("[isPrint_Stats] (ACCEPT) " + sender.toString() + ":");
438 for(Issue issue : issues){
439 ArrayList<Value> values = getValues(issue);
440 for(Value value : values){
441 System.out.print(agreedValueFrequency1.get(sender).get(issue).get(value) + " ");
442 }
443 System.out.println();
444 }
445
446 getMostAgreedValues(sender);
447 }
448 }
449
450
451
452 /**
453 * senderが拒絶したValueの頻度を更新
454 * @param sender
455 * @param bid
456 */
457 public void updateRejectedValues(Object sender, Bid bid){
458 // senderが過去に登場していない場合は初期化
459 if(!rejectedValueFrequency.containsKey(sender)){
460 rejectedValueFrequency.put(sender, new HashMap<Issue, HashMap<Value, Integer>> ());
461
462 for(Issue issue : issues){
463 rejectedValueFrequency.get(sender).put(issue, new HashMap<Value, Integer>());
464
465 ArrayList<Value> values = getValues(issue);
466 for(Value value : values){
467 rejectedValueFrequency.get(sender).get(issue).put(value, 0);
468 }
469 }
470 }
471
472 /**
473 * 2018/5/22
474 * 最初の30sの個数だけカウント
475 */
476 // 各issue毎に個数をカウント
477 for(Issue issue : issues) {
478 Value value = bid.getValue(issue.getNumber());
479 rejectedValueFrequency.get(sender).get(issue).put(value, rejectedValueFrequency.get(sender).get(issue).get(value) + 1);
480 }
481
482 if(isPrinting_Stats){
483 System.out.println("[isPrint_Stats] (REJECT) " + sender.toString() + ":");
484 for(Issue issue : issues){
485 ArrayList<Value> values = getValues(issue);
486 for(Value value : values){
487 System.out.print(rejectedValueFrequency.get(sender).get(issue).get(value) + " ");
488 }
489 System.out.println();
490 }
491
492 getMostRejectedValues(sender);
493 }
494 }
495
496
497 public void updateNegoStats(Object sender, Bid offeredBid) throws Exception {
498 // current session の提案履歴 への追加
499
500 rivalsBidHist.get(sender).add(offeredBid);
501 //System.out.println("rivalsBidHist.get(" + sender + "):" + rivalsBidHist.get(sender));
502 //System.out.println("???????????????");
503 updateAgreedValues(sender, offeredBid);
504
505 /**
506 * 2018/5/23
507 * 交渉相手の重要value情報を更新
508 * ナッシュ解に近いbidを探す
509 */
510 valuePriorSearch(sender);//valuePriorを更新
511
512 //valuePriorAllを初期化する
513 //valuePriorAllInit(valuePriorAll);
514
515 /**
516 * 2018/5/25
517 * valuePriorAllを更新する
518 * valuePriorAllとは全ての重視issueとそのvaluelistのセット
519 */
520 valueIssueSetGet();
521
522
523
524 // 交渉相手の統計情報 の更新
525 double util = info.getUtilitySpace().getUtility(offeredBid);
526 rivalsSum.put(sender, rivalsSum.get(sender) + util); // 和
527 rivalsPowSum.put(sender, rivalsPowSum.get(sender) + Math.pow(util, 2)); // 二乗和
528
529 int round_num = rivalsBidHist.get(sender).size();
530 rivalsMean.put(sender, rivalsSum.get(sender) / round_num); // 平均
531 rivalsVar.put(sender, (rivalsPowSum.get(sender) / round_num) - Math.pow(rivalsMean.get(sender), 2)); // 分散
532
533 if(rivalsVar.get(sender) < 0){rivalsVar.put(sender, 0.0);}
534 rivalsSD.put(sender, Math.sqrt(rivalsVar.get(sender))); // 標準偏差
535
536
537 // 最大最小の更新
538 if(util > rivalsMax.get(sender)){
539 rivalsMax.put(sender, util);
540 } else if (util < rivalsMin.get(sender)){
541 rivalsMin.put(sender, util);
542 }
543
544 if(isPrinting_Stats){
545 System.out.println("[isPrint_Stats] Mean: " + getRivalMean(sender) + " (Agent: " + sender.toString() + ")");
546 }
547 }
548
549 /**
550 * 自身の提案情報の更新
551 * @param offerBid
552 */
553 public void updateMyBidHist(Bid offerBid) {
554 myBidHist.add(offerBid);
555 }
556
557
558 // 交渉における基本情報 の取得
559 /**
560 * 論点一覧を返す
561 * @return
562 */
563 public List<Issue> getIssues() {
564 return issues;
565 }
566
567 /**
568 * 交渉相手の一覧を返す
569 * @return
570 */
571 public ArrayList<Object> getRivals() {
572 return rivals;
573 }
574
575 /**
576 * 交渉者数(自身を含む)を返す
577 * @return
578 */
579 public int getNegotiatorNum(){
580 // + 1: 自分
581 return rivals.size() + 1;
582 }
583
584 /**
585 * 論点における取り得る値の一覧を返す
586 * @param issue
587 * @return
588 */
589 public ArrayList<Value> getValues(Issue issue) {
590 ArrayList<Value> values = new ArrayList<Value>();
591
592 // 効用情報のtype毎に処理が異なる
593 switch(issue.getType()) {
594 case DISCRETE:
595 List<ValueDiscrete> valuesDis = ((IssueDiscrete)issue).getValues();
596 for(Value value:valuesDis){
597 values.add(value);
598 }
599 break;
600 case INTEGER:
601 int min_value = ((IssueInteger)issue).getUpperBound();
602 int max_value = ((IssueInteger)issue).getUpperBound();
603 for(int j=min_value; j<=max_value; j++){
604 Object valueObject = new Integer(j);
605 values.add((Value)valueObject);
606 }
607 break;
608 default:
609 try {
610 throw new Exception("issue type \""+ issue.getType() + "\" not supported by" + info.getAgentID().getName());
611 } catch (Exception e) {
612 System.out.println("[Exception] 論点の取り得る値の取得に失敗しました");
613 e.printStackTrace();
614 }
615 }
616
617 return values;
618 }
619
620 /**
621 * 線形効用空間であるかどうかを返す
622 * @return
623 */
624 public boolean isLinerUtilitySpace () {
625 return isLinerUtilitySpace;
626 }
627
628 /**
629 * 相対効用行列を返す
630 * @return
631 */
632 public HashMap<Issue, HashMap<Value, Double>> getValueRelativeUtility(){
633 return valueRelativeUtility;
634 }
635
636 /**
637 * 2018/5/25
638 * valuePriorAll:issueとそのvaluelistのセットを返す
639 */
640 public HashMap<Issue,ArrayList<Value>> getValuePriorAll(){
641 return valuePriorAll;
642 }
643
644 // current session の提案履歴 の取得
645
646 /**
647 * エージェントsenderの論点issueにおける最大Agree数となる選択肢valueを取得
648 * @param sender
649 * @param issue
650 * @return
651 */
652 public Value getMostAgreedValue (Object sender, Issue issue){
653 ArrayList<Value> values = getValues(issue);
654
655 int maxN = 0;
656 Value mostAgreedValue = values.get(0);
657 for (Value value : values){
658 int tempN = agreedValueFrequency.get(sender).get(issue).get(value);
659 // もし最大数が更新されたら
660 if(maxN < tempN){
661 maxN = tempN;
662 mostAgreedValue = value;
663 }
664 }
665
666 return mostAgreedValue;
667 }
668
669 /**2018/5/18
670 * エージェントsenderの論点issueにおける選択肢valueとそのAgree率を返す
671 * @param sender
672 * @param issue
673 * @param value
674 * @return
675 */
676 public HashMap<Value,Double> getProbAgreedValue1 (Object sender, Issue issue, Value value){
677 ArrayList<Value> values = getValues(issue);
678 HashMap<Value,Double> prob = new HashMap<Value, Double>();
679
680 int sum = 0;
681 for(Value v : values){
682 sum += agreedValueFrequency.get(sender).get(issue).get(v);
683 }
684
685 prob.put(value,agreedValueFrequency.get(sender).get(issue).get(value) * 1.0 / sum);
686
687 return prob;
688 }
689
690 /**
691 * 2018/5/22
692 * エージェントsenderの論点issueにおける選択肢valueとそのAgree率を返す
693 * Agree率を返すとき、時間とともに重み付きで減少
694 */
695 public HashMap<Value,Double> getProbAgreedValue2 (Object sender, Issue issue, Value value){
696 ArrayList<Value> values = getValues(issue);
697 HashMap<Value,Double> prob = new HashMap<Value, Double>();
698
699 double sum = 0;
700 for(Value v : values){
701 sum += agreedValueFrequency.get(sender).get(issue).get(v);
702 }
703
704 prob.put(value,agreedValueFrequency.get(sender).get(issue).get(value) / sum);
705
706 return prob;
707 }
708
709
710 /**
711 * エージェントsenderの論点issueにおける選択肢valueのAgree率を返す
712 * @param sender
713 * @param issue
714 * @param value
715 * @return
716 */
717 public double getProbAgreedValue (Object sender, Issue issue, Value value){
718 ArrayList<Value> values = getValues(issue);
719
720 int sum = 0;
721 for(Value v : values){
722 sum += agreedValueFrequency.get(sender).get(issue).get(v);
723 }
724
725 double prob = agreedValueFrequency.get(sender).get(issue).get(value) * 1.0 / sum;
726 return prob;
727 }
728
729
730
731
732 /**
733 * 2018/5/18
734 * エージェントSenderにおける各論点における累積確率(CP)を取得
735 * 同意を受けたvalueの特徴を拡大する
736 * @param sender
737 * @param issue
738 * @return
739 */
740 public HashMap<Value, ArrayList<Double>> getCPAgreedValue1 (Object sender, Issue issue, double pow){
741 HashMap<Value, ArrayList<Double>> CPMap = new HashMap<Value, ArrayList<Double>>();
742
743 ArrayList<Value> values = getValues(issue);
744
745 double sumOfProb = 0.0;
746 for(Value value : values){
747 double prob = getProbAgreedValue1(sender,issue,value).get(value);
748 sumOfProb += Math.pow(prob, pow);
749 }
750
751 double tempCP1 = 0.0;
752 for(Value value : values) {
753 ArrayList<Double> tempArray = new ArrayList<Double> ();
754
755 HashMap<Value,Double> probUpdate = new HashMap<Value, Double>();
756 double prob = getProbAgreedValue1(sender,issue,value).get(value);
757 probUpdate.put(value, Math.pow(prob,pow) / sumOfProb);
758
759 // 範囲のStartを格納
760 tempArray.add(tempCP1);
761
762 // 範囲のEndを格納
763 tempCP1 += probUpdate.get(value);
764 tempArray.add(tempCP1);
765
766 CPMap.put(value, tempArray);
767 }
768
769 return CPMap;
770 }
771
772
773 /**
774 * エージェントSenderにおける各論点における累積確率(CP)を取得
775 * @param sender
776 * @param issue
777 * @return
778 */
779 public HashMap<Value, ArrayList<Double>> getCPAgreedValue (Object sender, Issue issue){
780 HashMap<Value, ArrayList<Double>> CPMap = new HashMap<Value, ArrayList<Double>>();
781
782 ArrayList<Value> values = getValues(issue);
783 int sum = 0;
784 for(Value value : values){
785 sum += agreedValueFrequency.get(sender).get(issue).get(value);
786 }
787
788 double tempCP = 0.0;
789 for(Value value : values){
790 ArrayList<Double> tempArray = new ArrayList<Double> ();
791 // 範囲のStartを格納
792 tempArray.add(tempCP);
793
794 // 範囲のEndを格納
795 tempCP += agreedValueFrequency.get(sender).get(issue).get(value) * 1.0 / sum;
796 tempArray.add(tempCP);
797
798 CPMap.put(value, tempArray);
799 }
800
801 return CPMap;
802 }
803
804
805
806 /**
807 * エージェントSenderにおける各論点における最大Agree数となる選択肢valueをArrayListで取得
808 * @param sender
809 * @return
810 */
811 public ArrayList<Value> getMostAgreedValues (Object sender){
812 ArrayList<Value> values = new ArrayList<Value>();
813
814 // issueの内部的な順番はa-b-c-d-...じゃないので注意
815 for (Issue issue : issues){
816 values.add(getMostAgreedValue(sender, issue));
817 }
818
819
820 if(isPrinting_Stats){
821 System.out.print("[isPrint_Stats] ");
822 for(int i = 0; i < issues.size(); i++){
823 //System.out.print(issues.get(i).toString() + ":" + values.get(issues.get(i).getNumber()-1) + " ");
824 //System.out.print(issues.get(i).toString() + ":" + values.get(i) + "(" + getProbAgreedValue(sender,issues.get(i),values.get(i)) + ") ");
825
826 HashMap<Value, ArrayList<Double>> cp = getCPAgreedValue(sender, issues.get(i));
827
828 System.out.print(issues.get(i).toString() + ":"
829 + values.get(i) + "(" + cp.get(values.get(i)).get(0) + " - " + cp.get(values.get(i)).get(1) + ") ");
830 }
831 System.out.println();
832 }
833
834 return values;
835 }
836
837
838 /**
839 * エージェントsenderの論点issueにおける最大Reject数となる選択肢valueを取得
840 * @param sender
841 * @param issue
842 * @return
843 */
844 public Value getMostRejectedValue (Object sender, Issue issue){
845 ArrayList<Value> values = getValues(issue);
846
847 int maxN = 0;
848 Value mostRejectedValue = values.get(0);
849 for (Value value : values){
850 int tempN = rejectedValueFrequency.get(sender).get(issue).get(value);
851 // もし最大数が更新されたら
852 if(maxN < tempN){
853 maxN = tempN;
854 mostRejectedValue = value;
855 }
856 }
857
858 return mostRejectedValue;
859 }
860
861
862 /**
863 * 2018/5/18
864 * エージェントsenderの論点issueにおける選択肢valueとそのRejected率を返す
865 * @param sender
866 * @param issue
867 * @param value
868 * @return
869 */
870 public HashMap<Value,Double> getProbRejectedValue1 (Object sender, Issue issue, Value value){
871 ArrayList<Value> values = getValues(issue);
872 HashMap<Value,Double> probHash = new HashMap<Value, Double>();
873
874 int sum = 0;
875 for(Value v : values){
876 sum += rejectedValueFrequency.get(sender).get(issue).get(v);
877 }
878
879 probHash.put(value,rejectedValueFrequency.get(sender).get(issue).get(value) * 1.0 / sum);
880
881 return probHash;
882 }
883
884
885 /**
886 * 2018/5/18
887 * エージェントSenderにおける各論点における累積確率(CP)を取得
888 * 同意を受けたvalueの特徴を拡大する
889 * @param sender
890 * @param issue
891 * @return
892 */
893 public HashMap<Value, ArrayList<Double>> getCPRejectedValue1 (Object sender, Issue issue, double pow){
894 HashMap<Value, ArrayList<Double>> CPMap = new HashMap<Value, ArrayList<Double>>();
895
896 ArrayList<Value> values = getValues(issue);
897
898 double sumOfProb = 0.0;
899 for(Value value : values){
900 double prob = getProbRejectedValue1(sender,issue,value).get(value);
901 sumOfProb += Math.pow(prob, pow);
902 //System.out.println("+++++++++++" + sumOfProb);
903 }
904
905 double tempCP1 = 0.0;
906 for(Value value : values) {
907 ArrayList<Double> tempArray = new ArrayList<Double> ();
908
909 HashMap<Value,Double> probUpdate = new HashMap<Value, Double>();
910 double prob = getProbRejectedValue1(sender,issue,value).get(value);
911 probUpdate.put(value, Math.pow(prob,pow) / sumOfProb);
912
913 // 範囲のStartを格納
914 tempArray.add(tempCP1);
915
916 // 範囲のEndを格納
917 //System.out.println(value + ":" + tempCP1);
918 tempCP1 += probUpdate.get(value);
919
920 tempArray.add(tempCP1);
921
922 CPMap.put(value, tempArray);
923 }
924 //System.out.println("区切り");
925
926 return CPMap;
927 }
928
929
930 /**
931 * エージェントsenderの論点issueにおける選択肢valueのReject率を返す
932 * @param sender
933 * @param issue
934 * @param value
935 * @return
936 */
937 public double getProbRejectedValue (Object sender, Issue issue, Value value){
938 ArrayList<Value> values = getValues(issue);
939
940 int sum = 0;
941 for(Value v : values){
942 sum += rejectedValueFrequency.get(sender).get(issue).get(v);
943 }
944
945 double prob = rejectedValueFrequency.get(sender).get(issue).get(value) * 1.0 / sum;
946 return prob;
947 }
948
949 /**
950 * エージェントSenderにおける各論点における累積確率(CP)を取得
951 * @param sender
952 * @param issue
953 * @return
954 */
955 public HashMap<Value, ArrayList<Double>> getCPRejectedValue (Object sender, Issue issue){
956 HashMap<Value, ArrayList<Double>> CPMap = new HashMap<Value, ArrayList<Double>>();
957
958 ArrayList<Value> values = getValues(issue);
959 int sum = 0;
960 for(Value value : values){
961 sum += rejectedValueFrequency.get(sender).get(issue).get(value);
962 //System.out.println("+++++++++++" + sum);
963 }
964 //System.out.println("区切り");
965
966
967 double tempCP = 0.0;
968 for(Value value : values){
969 ArrayList<Double> tempArray = new ArrayList<Double> ();
970 // 範囲のStartを格納
971 tempArray.add(tempCP);
972
973 //System.out.println(value + ":" + tempCP);
974 // 範囲のEndを格納
975 tempCP += rejectedValueFrequency.get(sender).get(issue).get(value) * 1.0 / sum;
976
977 tempArray.add(tempCP);
978
979 CPMap.put(value, tempArray);
980 }
981 //System.out.println("区切り");
982
983 return CPMap;
984 }
985
986 /**
987 * エージェントSenderにおける各論点における最大Reject数となる選択肢valueをArrayListで取得
988 * @param sender
989 * @return
990 */
991 public ArrayList<Value> getMostRejectedValues (Object sender){
992 ArrayList<Value> values = new ArrayList<Value>();
993
994 // issueの内部的な順番はa-b-c-d-...じゃないので注意
995 for (Issue issue : issues){
996 values.add(getMostRejectedValue(sender, issue));
997 }
998
999
1000 if(isPrinting_Stats){
1001 System.out.print("[isPrint_Stats] ");
1002 for(int i = 0; i < issues.size(); i++){
1003 //System.out.print(issues.get(i).toString() + ":" + values.get(issues.get(i).getNumber()-1) + " ");
1004 //System.out.print(issues.get(i).toString() + ":" + values.get(i) + "(" + getProbRejectedValue(sender,issues.get(i),values.get(i)) + ") ");
1005
1006 HashMap<Value, ArrayList<Double>> cp = getCPRejectedValue(sender, issues.get(i));
1007
1008 System.out.print(issues.get(i).toString() + ":"
1009 + values.get(i) + "(" + cp.get(values.get(i)).get(0) + " - " + cp.get(values.get(i)).get(1) + ") ");
1010 }
1011 System.out.println();
1012 }
1013
1014 return values;
1015 }
1016
1017
1018 // 交渉相手の統計情報 の取得
1019 /**
1020 * 平均
1021 * @param sender
1022 * @return
1023 */
1024 public double getRivalMean(Object sender) {
1025 return rivalsMean.get(sender);
1026 }
1027
1028 /**
1029 * 分散
1030 * @param sender
1031 * @return
1032 */
1033 public double getRivalVar(Object sender) {
1034 return rivalsVar.get(sender);
1035 }
1036
1037 /**
1038 * 標準偏差
1039 * @param sender
1040 * @return
1041 */
1042 public double getRivalSD(Object sender) {
1043 return rivalsSD.get(sender);
1044 }
1045
1046
1047 /**
1048 * エージェントSenderにおける今sessionにおける提案の自身の最大効用値
1049 * @param sender
1050 * @return
1051 */
1052 public double getRivalMax(Object sender){
1053 return rivalsMax.get(sender);
1054 }
1055
1056 /**
1057 * エージェントSenderにおける今sessionにおける提案の自身の最小効用値
1058 * @param sender
1059 * @return
1060 */
1061 public double getRivalMin(Object sender){
1062 return rivalsMin.get(sender);
1063 }
1064
1065 /**
1066 * 2018/5/24
1067 * valuePriorAllを初期化する
1068 */
1069 public void valuePriorAllInit(HashMap<Issue,ArrayList<Value>> valuePriorAll) {
1070 valuePriorAll = new HashMap<Issue,ArrayList<Value>>();
1071 }
1072
1073 /**
1074 * 2018/5/25
1075 * 重視するissueとそのissueの重視するvalueのlistをセットで返す
1076 */
1077 public void valueIssueSetGet() {
1078 ArrayList<HashMap<Issue,Value>> valueIssueSets = new ArrayList<HashMap<Issue,Value>>();
1079 valuePriorAll = new HashMap<Issue,ArrayList<Value>>();
1080
1081 //全相手の重視issueとそのissueの重視のセットを1つのlistにまとめる
1082 for(Object rival:rivals) {
1083 if(!valuePrior.get(rival).isEmpty()) {//重視issueがある場合
1084 if(!valuePrior.get(rival).get(0).isEmpty()) {
1085 System.out.println("valuePrior.get(rival).get(0):" + valuePrior.get(rival).get(0));
1086 valueIssueSets.add(valuePrior.get(rival).get(0));
1087 }
1088
1089 System.out.println("issues.size:" + issues.size());
1090 if(valuePrior.get(rival).size() == 2) {//issueのsizeが2以上の場合
1091 if(!valuePrior.get(rival).get(1).isEmpty()) {
1092 valueIssueSets.add(valuePrior.get(rival).get(1));
1093 }
1094 }
1095 }
1096 }
1097 System.out.println("valueIssueSets:" + valueIssueSets);
1098 //重視issueとvalueのセットを合併
1099 for(HashMap<Issue,Value> valueIssueSet: valueIssueSets) {
1100 //System.out.println("valueIssueSet.keySet():" + valueIssueSet.keySet());
1101 Iterator<Issue> key_itr = valueIssueSet.keySet().iterator();
1102 Issue issue_tmp = (Issue) key_itr.next();
1103
1104 //System.out.println("issue_tmp:" + issue_tmp);
1105 //System.out.println("valuePriorAll:" + valuePriorAll);
1106
1107 //issueはすでに追加された場合
1108
1109 if(valuePriorAll.containsKey(issue_tmp)) {
1110 //valueはissueのvaluelistに存在するかどうか判断
1111 boolean valueExist = false;
1112 for(Value value: valuePriorAll.get(issue_tmp)) {
1113 if(valueIssueSet.get(issue_tmp) == value) {
1114 valueExist = true;
1115 }
1116 }
1117 //valueはissueのvaluelistに存在しない場合、追加
1118 if(!valueExist) {
1119 ArrayList<Value> valueList = valuePriorAll.get(issue_tmp);
1120 valueList.add((Value) valueIssueSet.get(issue_tmp));
1121 valuePriorAll.put(issue_tmp, valueList);
1122 }
1123 }
1124
1125 //issueはまだ追加されていない場合
1126 if(!valuePriorAll.containsKey(issue_tmp)) {
1127 ArrayList<Value> valueList = new ArrayList<Value>();
1128 valueList.add((Value) valueIssueSet.get(issue_tmp));
1129 //issueとそのvaluelistを追加
1130 valuePriorAll.put(issue_tmp, valueList);
1131 }
1132 }
1133 System.out.println("valuePriorAll:" + valuePriorAll);
1134 }
1135}
Note: See TracBrowser for help on using the repository browser.