source: src/main/java/agents/anac/y2015/AgentW/negotiatingInfo.java@ 127

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

Initial import : Genius 9.0.0

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