1 | package agents.anac.y2015.fairy;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.issue.Issue;
|
---|
9 | import genius.core.issue.IssueDiscrete;
|
---|
10 | import genius.core.issue.IssueInteger;
|
---|
11 | import genius.core.issue.Value;
|
---|
12 | import genius.core.issue.ValueDiscrete;
|
---|
13 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
14 |
|
---|
15 | public class negotiatingInfo {
|
---|
16 | private AdditiveUtilitySpace utilitySpace; // ��p���
|
---|
17 | private List<Issue> issues; // �_�_
|
---|
18 | private ArrayList<Object> opponents; // ���g�ȊO�̌��Q���҂�sender
|
---|
19 | private ArrayList<Bid> MyBidHistory = null; // ��ė���
|
---|
20 | private HashMap<Object, ArrayList<Bid>> opponentsBidHistory = null; // ��ė���
|
---|
21 | private HashMap<Object, Boolean> opponentsBool; // ��Ԃ��^�����ǂ���
|
---|
22 | private HashMap<Object, Double> opponentsAverage; // ����
|
---|
23 | private HashMap<Object, Double> opponentsVariance; // ���U
|
---|
24 | private HashMap<Object, Double> opponentsSum; // �a
|
---|
25 | private HashMap<Object, Double> opponentsPowSum; // ���a
|
---|
26 | private HashMap<Object, Double> opponentsStandardDeviation; // �W����
|
---|
27 | private HashMap<Issue, HashMap<Value, Double>> valueRelativeUtility = null; // ���g�̌�p��Ԃɂ�����e�_�_�l�̑��Ό�p�l�s��i��`��p��ԗp�j
|
---|
28 | private int round = 0; // �����̎�Ԑ�
|
---|
29 | private int negotiatorNum = 3; // ���Ґ�
|
---|
30 | private boolean isLinerUtilitySpace = true; // ��`��p��Ԃł��邩�ǂ���
|
---|
31 |
|
---|
32 | public negotiatingInfo(AdditiveUtilitySpace utilitySpace) {
|
---|
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 | opponentsBool = new HashMap<Object, Boolean>();
|
---|
40 | opponentsAverage = new HashMap<Object, Double>();
|
---|
41 | opponentsVariance = new HashMap<Object, Double>();
|
---|
42 | opponentsSum = new HashMap<Object, Double>();
|
---|
43 | opponentsPowSum = new HashMap<Object, Double>();
|
---|
44 | opponentsStandardDeviation = new HashMap<Object, Double>();
|
---|
45 | valueRelativeUtility = new HashMap<Issue, HashMap<Value, Double>>();
|
---|
46 |
|
---|
47 | try {
|
---|
48 | initValueRelativeUtility();
|
---|
49 | } catch (Exception e) {
|
---|
50 | System.out.println("���Ό�p�s��̏���Ɏ��s���܂���");
|
---|
51 | e.printStackTrace();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void initOpponent(Object sender) {
|
---|
56 | initNegotiatingInfo(sender); // ����������
|
---|
57 | opponents.add(sender); // ���Q���҂�sender��lj�
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void updateInfo(Object sender, Bid offeredBid) {
|
---|
61 | try {
|
---|
62 | updateNegotiatingInfo(sender, offeredBid);
|
---|
63 | } // �����̍X�V
|
---|
64 | catch (Exception e1) {
|
---|
65 | System.out.println("�����̍X�V�Ɏ��s���܂���");
|
---|
66 | e1.printStackTrace();
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void initNegotiatingInfo(Object sender) {
|
---|
71 | opponentsBidHistory.put(sender, new ArrayList<Bid>());
|
---|
72 | opponentsAverage.put(sender, 0.0);
|
---|
73 | opponentsVariance.put(sender, 0.0);
|
---|
74 | opponentsSum.put(sender, 0.0);
|
---|
75 | opponentsPowSum.put(sender, 0.0);
|
---|
76 | opponentsStandardDeviation.put(sender, 0.0);
|
---|
77 | }
|
---|
78 |
|
---|
79 | // ���Ό�p�s��̏���
|
---|
80 | private void initValueRelativeUtility() throws Exception {
|
---|
81 | ArrayList<Value> values = null;
|
---|
82 | for (Issue issue : issues) {
|
---|
83 | valueRelativeUtility.put(issue, new HashMap<Value, Double>()); // �_�_�s�̏���
|
---|
84 | values = getValues(issue);
|
---|
85 | for (Value value : values) {
|
---|
86 | valueRelativeUtility.get(issue).put(value, 0.0);
|
---|
87 | } // �_�_�s�̗v�f�̏���
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | // ���Ό�p�s��̓��o
|
---|
92 | public void setValueRelativeUtility(Bid maxBid) throws Exception {
|
---|
93 | ArrayList<Value> values = null;
|
---|
94 | Bid currentBid = null;
|
---|
95 | for (Issue issue : issues) {
|
---|
96 | currentBid = new Bid(maxBid);
|
---|
97 | values = getValues(issue);
|
---|
98 | for (Value value : values) {
|
---|
99 | currentBid = currentBid.putValue(issue.getNumber(), value);
|
---|
100 | valueRelativeUtility.get(issue).put(
|
---|
101 | value,
|
---|
102 | utilitySpace.getUtility(currentBid)
|
---|
103 | - utilitySpace.getUtility(maxBid));
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void updateNegotiatingInfo(Object sender, Bid offeredBid)
|
---|
109 | throws Exception {
|
---|
110 | opponentsBidHistory.get(sender).add(offeredBid); // ��ė���
|
---|
111 |
|
---|
112 | double util = utilitySpace.getUtility(offeredBid);
|
---|
113 | opponentsSum.put(sender, opponentsSum.get(sender) + util); // �a
|
---|
114 | opponentsPowSum.put(sender,
|
---|
115 | opponentsPowSum.get(sender) + Math.pow(util, 2)); // ���a
|
---|
116 |
|
---|
117 | int round_num = opponentsBidHistory.get(sender).size();
|
---|
118 | opponentsAverage.put(sender, opponentsSum.get(sender) / round_num); // ����
|
---|
119 | opponentsVariance.put(sender, (opponentsPowSum.get(sender) / round_num)
|
---|
120 | - Math.pow(opponentsAverage.get(sender), 2)); // ���U
|
---|
121 |
|
---|
122 | if (opponentsVariance.get(sender) < 0) {
|
---|
123 | opponentsVariance.put(sender, 0.0);
|
---|
124 | }
|
---|
125 | opponentsStandardDeviation.put(sender,
|
---|
126 | Math.sqrt(opponentsVariance.get(sender))); // �W����
|
---|
127 | }
|
---|
128 |
|
---|
129 | // ���Ґ���Ԃ�
|
---|
130 | public void updateOpponentsNum(int num) {
|
---|
131 | negotiatorNum = num;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // ��`��p��ԂłȂ��ꍇ
|
---|
135 | public void utilitySpaceTypeisNonLiner() {
|
---|
136 | isLinerUtilitySpace = false;
|
---|
137 | }
|
---|
138 |
|
---|
139 | // ���g�̒�ď��̍X�V
|
---|
140 | public void updateMyBidHistory(Bid offerBid) {
|
---|
141 | MyBidHistory.add(offerBid);
|
---|
142 | }
|
---|
143 |
|
---|
144 | // �^�����ǂ���(�Q�b�g)
|
---|
145 | public boolean getOpponentsBool(Object sender) {
|
---|
146 | if (opponentsBool.isEmpty())
|
---|
147 | return false;
|
---|
148 | return opponentsBool.get(sender);
|
---|
149 | }
|
---|
150 |
|
---|
151 | // �^�����ǂ���(�N���A)
|
---|
152 | public void clearOpponentsBool() {
|
---|
153 | opponentsBool.clear();
|
---|
154 | return;
|
---|
155 | }
|
---|
156 |
|
---|
157 | // �^�����ǂ���(�Z�b�g)
|
---|
158 | public void setOpponentsBool(Object sender, boolean bool) {
|
---|
159 | opponentsBool.put(sender, bool);
|
---|
160 | return;
|
---|
161 | }
|
---|
162 |
|
---|
163 | // ����
|
---|
164 | public double getAverage(Object sender) {
|
---|
165 | return opponentsAverage.get(sender);
|
---|
166 | }
|
---|
167 |
|
---|
168 | // ���U
|
---|
169 | public double getVariancer(Object sender) {
|
---|
170 | return opponentsVariance.get(sender);
|
---|
171 | }
|
---|
172 |
|
---|
173 | // �W����
|
---|
174 | public double getStandardDeviation(Object sender) {
|
---|
175 | return opponentsStandardDeviation.get(sender);
|
---|
176 | }
|
---|
177 |
|
---|
178 | // ����̒�ė����̗v�f����Ԃ�
|
---|
179 | public int getPartnerBidNum(Object sender) {
|
---|
180 | return opponentsBidHistory.get(sender).size();
|
---|
181 | }
|
---|
182 |
|
---|
183 | // ���g�̃��E���h����Ԃ�
|
---|
184 | public int getRound() {
|
---|
185 | return round;
|
---|
186 | }
|
---|
187 |
|
---|
188 | // ���Ґ���Ԃ�
|
---|
189 | public int getNegotiatorNum() {
|
---|
190 | return negotiatorNum;
|
---|
191 | }
|
---|
192 |
|
---|
193 | // ���Ό�p�s���Ԃ�
|
---|
194 | public HashMap<Issue, HashMap<Value, Double>> getValueRelativeUtility() {
|
---|
195 | return valueRelativeUtility;
|
---|
196 | }
|
---|
197 |
|
---|
198 | // ��`��p��Ԃł��邩�ǂ�����Ԃ�
|
---|
199 | public boolean isLinerUtilitySpace() {
|
---|
200 | return isLinerUtilitySpace;
|
---|
201 | }
|
---|
202 |
|
---|
203 | // �_�_�ꗗ��Ԃ�
|
---|
204 | public List<Issue> getIssues() {
|
---|
205 | return issues;
|
---|
206 | }
|
---|
207 |
|
---|
208 | // �_�_�ɂ������蓾��l�̈ꗗ��Ԃ�
|
---|
209 | public ArrayList<Value> getValues(Issue issue) {
|
---|
210 | ArrayList<Value> values = new ArrayList<Value>();
|
---|
211 | switch (issue.getType()) {
|
---|
212 | case DISCRETE:
|
---|
213 | List<ValueDiscrete> valuesDis = ((IssueDiscrete) issue).getValues();
|
---|
214 | for (Value value : valuesDis) {
|
---|
215 | values.add(value);
|
---|
216 | }
|
---|
217 | break;
|
---|
218 | case INTEGER:
|
---|
219 | int min_value = ((IssueInteger) issue).getUpperBound();
|
---|
220 | int max_value = ((IssueInteger) issue).getUpperBound();
|
---|
221 | for (int j = min_value; j <= max_value; j++) {
|
---|
222 | Object valueObject = new Integer(j);
|
---|
223 | values.add((Value) valueObject);
|
---|
224 | }
|
---|
225 | break;
|
---|
226 | default:
|
---|
227 | try {
|
---|
228 | throw new Exception("issue type " + issue.getType()
|
---|
229 | + " not supported by Atlas3");
|
---|
230 | } catch (Exception e) {
|
---|
231 | System.out.println("�_�_�̎�蓾��l�̎擾�Ɏ��s���܂���");
|
---|
232 | e.printStackTrace();
|
---|
233 | }
|
---|
234 | }
|
---|
235 | return values;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // ������̈ꗗ��Ԃ�
|
---|
239 | public ArrayList<Object> getOpponents() {
|
---|
240 | return opponents;
|
---|
241 | }
|
---|
242 | }
|
---|