source: src/main/java/agents/anac/y2018/shiboy/etc/NegoStrategy.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: 4.5 KB
Line 
1package agents.anac.y2018.shiboy.etc;
2
3import java.util.ArrayList;
4
5import genius.core.Bid;
6import genius.core.parties.NegotiationInfo;
7
8
9/**
10 * Created by shota_suzuki on 2018/05/16.
11 */
12public class NegoStrategy {
13 private NegotiationInfo info;
14 private boolean isPrinting = false; // デバッグ用
15 private boolean isPrinting_Strategy = true;
16
17 private NegoStats negoStats; // 交渉情報
18 private NegoHistory negoHistory;
19 private double rv = 0.0; // 留保価格
20 private double df = 0.0; // 割引効用
21
22
23 public NegoStrategy(NegotiationInfo info, boolean isPrinting, NegoStats negoStats, NegoHistory negoHistory) {
24 this.info = info;
25 this.isPrinting = isPrinting;
26
27 this.negoStats = negoStats;
28 this.negoHistory = negoHistory;
29 rv = info.getUtilitySpace().getReservationValueUndiscounted();
30 df = info.getUtilitySpace().getDiscountFactor();
31
32 if (this.isPrinting) {
33 System.out.println("[isPrinting] NegoStrategy: success");
34 }
35 if (isPrinting_Strategy) {
36 System.out.println("[isPrint_Strategy] rv = " + rv);
37 System.out.println("[isPrint_Strategy] df = " + df);
38 }
39 }
40
41 // 受容判定
42 public boolean selectAccept(Bid offeredBid, double time) {
43 try {
44 if (info.getUtilitySpace().getUtility(offeredBid) >= getThreshold(time)) {
45 return true;
46 } else {
47 return false;
48 }
49 } catch (Exception e) {
50 System.out.println("[Exception_Strategy] 受容判定に失敗しました");
51 e.printStackTrace();
52 return false;
53 }
54 }
55
56 // 交渉終了判定
57 public boolean selectEndNegotiation(double time) {
58 if (1.0 - df < 1e-7) { // 割引効用が設定されていない
59 return false;
60 } else {
61 if (rv > getThreshold(time)) {
62 return true;
63 } else {
64 return false;
65 }
66 }
67
68 }
69
70 /**
71 * 統計情報を元に相手の変位幅を推定 (二分割一様分布を利用)
72 *
73 * @param m 平均効用値
74 * @param sd 標準偏差
75 * @return
76 */
77 public double calWidth(double m, double sd) {
78 if (m > 0.1 && m < 0.9) {
79 return Math.sqrt(3.0 / (m - m * m)) * sd;
80 } else {
81 return Math.sqrt(12) * sd;
82 }
83 }
84
85 // 閾値を返す
86 public double getThreshold(double time) {
87 double threshold = 1.0;
88 double alpha = 4.0;
89
90 // 交渉相手全員に対してemaxを計算し,最小となるものを探す
91 ArrayList<Object> rivals = negoStats.getRivals();
92 double emax = 1.0;
93 for (Object sender : rivals) {
94 double m = negoStats.getRivalMean(sender);
95 double sd = negoStats.getRivalSD(sender);
96
97 // emax = Math.min(emax, m + (1 - m)*calWidth(m, sd));
98 // negoStats.getRivalMax(sender) より今sessionにおける最大効用値を採用
99 emax = Math.min(emax, Math.max(negoStats.getRivalMax(sender), m + (1 - m) * calWidth(m, sd)));
100 emax = Math.max(emax, rv); // 留保価格より小さい場合は,rvを採用する.
101 }
102
103 if (1.0 - df < 1e-7) { // 割引効用が設定されていない
104 threshold = Math.min(threshold, 1 - (1 - emax) * Math.pow(time, alpha));
105 } else {
106 threshold = Math.max(threshold - time, emax);
107 }
108
109 /*
110 // 一旦、過去の提案で最大のものまで譲歩する
111 if (0.80 < time && time < 0.82) {
112 for (Object sender : rivals) {
113 threshold = Math.min(threshold, negoStats.getRivalMax(sender));
114 }
115 threshold = Math.max(threshold, rv);
116 }
117
118 if (isPrinting_Strategy) {
119 System.out.println("[isPrint_Strategy] threshold = " + threshold
120 + " | time: " + time
121 + ", emax: " + emax);
122 }
123 */
124
125 // 交渉決裂寸前では、過去の提案で最大のものまで譲歩する
126 if (time > 0.99) {
127 for (Object sender : rivals) {
128 threshold = Math.min(threshold, negoStats.getRivalMax(sender));
129 }
130 threshold = Math.max(threshold, rv);
131 }
132
133 if (isPrinting_Strategy) {
134 System.out.println("[isPrint_Strategy] threshold = " + threshold
135 + " | time: " + time
136 + ", emax: " + emax);
137 }
138
139 return threshold;
140 }
141}
Note: See TracBrowser for help on using the repository browser.