source: src/main/java/agents/anac/y2017/agentkn/etc/negotiationInfo.java@ 345

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

Initial import : Genius 9.0.0

File size: 8.5 KB
Line 
1package agents.anac.y2017.agentkn.etc;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.Iterator;
6import java.util.List;
7import java.util.Map;
8
9import agents.anac.y2016.farma.etc.CntBySender;
10import genius.core.Bid;
11import genius.core.issue.Issue;
12import genius.core.issue.IssueDiscrete;
13import genius.core.issue.IssueInteger;
14import genius.core.issue.Value;
15import genius.core.issue.ValueDiscrete;
16import genius.core.utility.AbstractUtilitySpace;
17
18public class negotiationInfo {
19 private AbstractUtilitySpace utilitySpace; // 効用空間
20 private List<Issue> issues; // 論点
21 private ArrayList<Object> opponents; // 自身以外の交渉参加者のsender
22 private ArrayList<Bid> MyBidHistory = null; // 提案履歴
23 private HashMap<Object, ArrayList<Bid>> opponentsBidHistory = null; // 提案履歴
24 private HashMap<Object, Double> opponentsAverage; // 平均
25 private HashMap<Object, Double> opponentsVariance; // 分散
26 private HashMap<Object, Double> opponentsSum; // 和
27 private HashMap<Object, Double> opponentsPowSum; // 二乗和
28 private HashMap<Object, Double> opponentsStandardDeviation; // 標準偏差
29 private HashMap<Issue, HashMap<Value, Double>> valueRelativeUtility = null; // 自身の効用空間における各論点値の相対効用値行列(線形効用空間用)
30 private HashMap<Value, CntBySender> offeredValueNum;
31
32 private int round = 0; // 自分の手番数
33 private int negotiatorNum = 0; // 交渉者数
34 private boolean isLinerUtilitySpace = true; // 線形効用空間であるかどうか
35
36 private boolean isPrinting = false; // デバッグ用
37
38 public negotiationInfo(AbstractUtilitySpace utilitySpace, boolean isPrinting) {
39 // 初期化
40 this.utilitySpace = utilitySpace;
41 this.isPrinting = isPrinting;
42
43 issues = utilitySpace.getDomain().getIssues();
44 opponents = new ArrayList<Object>();
45 MyBidHistory = new ArrayList<>();
46 opponentsBidHistory = new HashMap<Object, ArrayList<Bid>>();
47 opponentsAverage = new HashMap<Object, Double>();
48 opponentsVariance = new HashMap<Object, Double>();
49 opponentsSum = new HashMap<Object, Double>();
50 opponentsPowSum = new HashMap<Object, Double>();
51 opponentsStandardDeviation = new HashMap<Object, Double>();
52 valueRelativeUtility = new HashMap<Issue, HashMap<Value, Double>>();
53 offeredValueNum = new HashMap<Value, CntBySender>();
54 System.out.println(offeredValueNum);
55 try {
56 initValueRelativeUtility();
57 } catch (Exception e) {
58 System.out.println("相対効用行列の初期化に失敗しました");
59 e.printStackTrace();
60 }
61 }
62
63 public void initOpponent(Object sender) {
64 initNegotiatingInfo(sender); // 交渉情報を初期化
65 opponents.add(sender); // 交渉参加者にsenderを追加
66 }
67
68 public void updateInfo(Object sender, Bid offeredBid) {
69 try {
70 updateNegotiatingInfo(sender, offeredBid);
71 } // 交渉情報の更新
72 catch (Exception e1) {
73 System.out.println("交渉情報の更新に失敗しました");
74 e1.printStackTrace();
75 }
76 }
77
78 private void initNegotiatingInfo(Object sender) {
79 opponentsBidHistory.put(sender, new ArrayList<Bid>());
80 opponentsAverage.put(sender, 0.0);
81 opponentsVariance.put(sender, 0.0);
82 opponentsSum.put(sender, 0.0);
83 opponentsPowSum.put(sender, 0.0);
84 opponentsStandardDeviation.put(sender, 0.0);
85 }
86
87 // 相対効用行列の初期化
88 private void initValueRelativeUtility() throws Exception {
89 ArrayList<Value> values = null;
90 for (Issue issue : issues) {
91 valueRelativeUtility.put(issue, new HashMap<Value, Double>()); // 論点行の初期化
92 values = getValues(issue);
93 for (Value value : values) {
94 valueRelativeUtility.get(issue).put(value, 0.0);
95 } // 論点行の要素の初期化
96 }
97 }
98
99 // 相対効用行列の導出
100 public void setValueRelativeUtility(Bid maxBid) throws Exception {
101 ArrayList<Value> values = null;
102 Bid currentBid = null;
103 for (Issue issue : issues) {
104 currentBid = new Bid(maxBid);
105 values = getValues(issue);
106 for (Value value : values) {
107 currentBid = currentBid.putValue(issue.getNumber(), value);
108 valueRelativeUtility.get(issue).put(value,
109 utilitySpace.getUtility(currentBid) - utilitySpace.getUtility(maxBid));
110 }
111 }
112 }
113
114 public void updateNegotiatingInfo(Object sender, Bid offeredBid) throws Exception {
115 opponentsBidHistory.get(sender).add(offeredBid); // 提案履歴
116
117 double util = utilitySpace.getUtility(offeredBid);
118 opponentsSum.put(sender, opponentsSum.get(sender) + util); // 和
119 opponentsPowSum.put(sender, opponentsPowSum.get(sender) + Math.pow(util, 2)); // 二乗和
120
121 int round_num = opponentsBidHistory.get(sender).size();
122 opponentsAverage.put(sender, opponentsSum.get(sender) / round_num); // 平均
123 opponentsVariance.put(sender,
124 (opponentsPowSum.get(sender) / round_num) - Math.pow(opponentsAverage.get(sender), 2)); // 分散
125
126 if (opponentsVariance.get(sender) < 0) {
127 opponentsVariance.put(sender, 0.0);
128 }
129 opponentsStandardDeviation.put(sender, Math.sqrt(opponentsVariance.get(sender))); // 標準偏差
130 }
131
132 // 交渉者数を返す
133 public void updateOpponentsNum(int num) {
134 negotiatorNum = num;
135 }
136
137 // 線形効用空間でない場合
138 public void utilitySpaceTypeisNonLiner() {
139 isLinerUtilitySpace = false;
140 }
141
142 // 自身の提案情報の更新
143 public void updateMyBidHistory(Bid offerBid) {
144 MyBidHistory.add(offerBid);
145 }
146
147 // 平均
148 public double getAverage(Object sender) {
149 return opponentsAverage.get(sender);
150 }
151
152 // 分散
153 public double getVariancer(Object sender) {
154 return opponentsVariance.get(sender);
155 }
156
157 // 標準偏差
158 public double getStandardDeviation(Object sender) {
159 return opponentsStandardDeviation.get(sender);
160 }
161
162 // 相手の提案履歴の要素数を返す
163 public int getPartnerBidNum(Object sender) {
164 return opponentsBidHistory.get(sender).size();
165 }
166
167 // 自身のラウンド数を返す
168 public int getRound() {
169 return round;
170 }
171
172 // 交渉者数を返す
173 public int getNegotiatorNum() {
174 return negotiatorNum;
175 }
176
177 // 相対効用行列を返す
178 public HashMap<Issue, HashMap<Value, Double>> getValueRelativeUtility() {
179 return valueRelativeUtility;
180 }
181
182 // 線形効用空間であるかどうかを返す
183 public boolean isLinerUtilitySpace() {
184 return isLinerUtilitySpace;
185 }
186
187 // 論点一覧を返す
188 public List<Issue> getIssues() {
189 return issues;
190 }
191
192 // 論点における取り得る値の一覧を返す
193 public ArrayList<Value> getValues(Issue issue) {
194 ArrayList<Value> values = new ArrayList<Value>();
195 switch (issue.getType()) {
196 case DISCRETE:
197 List<ValueDiscrete> valuesDis = ((IssueDiscrete) issue).getValues();
198 for (Value value : valuesDis) {
199 values.add(value);
200 }
201 break;
202 case INTEGER:
203 int min_value = ((IssueInteger) issue).getUpperBound();
204 int max_value = ((IssueInteger) issue).getUpperBound();
205 for (int j = min_value; j <= max_value; j++) {
206 Object valueObject = new Integer(j);
207 values.add((Value) valueObject);
208 }
209 break;
210 default:
211 try {
212 throw new Exception("issue type " + issue.getType() + " not supported by Atlas3");
213 } catch (Exception e) {
214 System.out.println("論点の取り得る値の取得に失敗しました");
215 e.printStackTrace();
216 }
217 }
218 return values;
219 }
220
221 // 交渉相手の一覧を返す
222 public ArrayList<Object> getOpponents() {
223 return opponents;
224 }
225
226 public Value getHighFrequencyValue(Object sender, Issue issue) {
227 ArrayList values = this.getValues(issue);
228 double tempMax = 0.0D;
229 Value tempValue = (Value) values.get(0);
230 Iterator var8 = values.iterator();
231
232 while (var8.hasNext()) {
233 Value value = (Value) var8.next();
234 if (this.offeredValueNum.containsKey(value)) {
235 double nowCnt = (double) ((CntBySender) this.offeredValueNum.get(value)).getSimpleCnt(sender);
236 if (tempMax < nowCnt) {
237 tempMax = nowCnt;
238 tempValue = value;
239 }
240 }
241 }
242
243 return tempValue;
244 }
245
246 public void updateOfferedValueNum(Object sender, Bid bid, double time) {
247 Value value;
248 for (Iterator var6 = this.issues.iterator(); var6.hasNext(); ((CntBySender) this.offeredValueNum.get(value))
249 .incrementCnt(sender, time)) {
250 Issue issue = (Issue) var6.next();
251 value = bid.getValue(issue.getNumber());
252 if (!this.offeredValueNum.containsKey(value)) {
253 this.offeredValueNum.put(value, new CntBySender(0));
254 }
255 }
256
257 }
258
259 // 入力されたbidがそれぞれのsender でどれほど頻度的に多いのかチェック
260 public int getBidFrequcncy(Bid aBid) {
261 int tPoint = 0;
262 for (Map.Entry<Integer, Value> e : aBid.getValues().entrySet()) {
263 if (this.offeredValueNum.containsKey(e.getValue())) {
264 tPoint += offeredValueNum.get(e.getValue()).getSimpleSum();
265 }
266 }
267 return tPoint;
268 }
269}
Note: See TracBrowser for help on using the repository browser.