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