source: src/main/java/agents/anac/y2014/KGAgent/History.java@ 68

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

Initial import : Genius 9.0.0

File size: 6.3 KB
Line 
1package agents.anac.y2014.KGAgent;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8import agents.anac.y2014.kGA_gent.library_genetic.GA_Main;
9import agents.anac.y2014.kGA_gent.library_genetic.Gene;
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.ValueInteger;
16
17public class History {
18
19 static int pairsize = 2;
20
21 double add = 0.00001;
22 double derta = 1.1;
23 static int type = 0;
24
25 Map<Bid, Integer> bidhistory = new HashMap<Bid, Integer>(1000);
26 // ArrayList<Bid> bidlisthistory = new ArrayList<Bid>(1000);
27 List<Issue> issues;
28
29 KGAgent agent = null;
30
31 Map<UtilityPair, Double> utility = new HashMap<UtilityPair, Double>(10000);
32 int count = 0;
33
34 History(List<Issue> issuelist, KGAgent agent, int ty) {
35 issues = issuelist;
36 this.agent = agent;
37 type = ty;
38 }
39
40 // 相手��案を入力�る
41 void Input(Bid input) {
42
43 if (bidhistory.containsKey(input)) {
44 bidhistory.put(input, bidhistory.get(input) + 1);
45 } else {
46 count++;
47 // System.out.println("Enemy New Offer sise = " + count);
48 bidhistory.put(input, 1);
49 // bidlisthistory.add(input);
50 AddHistory(input);
51 }
52 }
53
54 /*
55 * 相手ã�®äºˆæƒ³åŠ¹ç�?¨å€¤ã‚’è¿�?ã�™
56 */
57 double GetEnemyUtility(Bid input) {
58
59 if (type == 0) {
60 return GetUtilNonLin(input);
61 } else {
62 return GetUtilLin(input);
63 }
64 }
65
66 double GetUtilNonLin(Bid bid) {
67
68 HashMap<Integer, Value> map = bid.getValues();
69 IssueInteger lIssueInteger;
70 ValueInteger v1, v2;
71
72 double ret = 0.0;
73
74 UtilityPair pair = new UtilityPair();
75
76 int size = issues.size();
77
78 if (count == 0) {
79 return 0;
80 }
81 for (int i = 0; i < size; i++) {
82 lIssueInteger = (IssueInteger) issues.get(i);
83 v1 = (ValueInteger) map.get(lIssueInteger.getNumber());
84 pair.add(new Pair(lIssueInteger.getNumber(), v1.getValue()));
85
86 for (int j = i + 1; j < size; j++) {
87 lIssueInteger = (IssueInteger) issues.get(j);
88 v1 = (ValueInteger) map.get(lIssueInteger.getNumber());
89 pair.add(new Pair(lIssueInteger.getNumber(), v1.getValue()));
90
91 if (utility.containsKey(pair)) {
92 ret += utility.put(pair, utility.get(pair));
93 }
94 pair.remove(pair.size() - 1);
95 }
96 pair.remove(pair.size() - 1);
97
98 }
99 return ret;
100 }
101
102 double GetUtilLin(Bid bid) {
103
104 HashMap<Integer, Value> map = bid.getValues();
105 IssueDiscrete ID;
106
107 double ret = 0.0;
108
109 UtilityPair pair = new UtilityPair();
110
111 int size = issues.size();
112
113 if (count == 0) {
114 return 0;
115 }
116 for (int i = 0; i < size; i++) {
117 ID = (IssueDiscrete) issues.get(i);
118
119 pair.add(new Pair(ID.getNumber(), ID.getNumberOfValues()));
120
121 if (utility.containsKey(pair)) {
122 ret += utility.put(pair, utility.get(pair));
123 }
124 pair.remove(pair.size() - 1);
125
126 }
127 return ret;
128 }
129
130 /*
131 * 相手�入力bid�ら����ペアを作��Map�格��る
132 * 線形�らシングル �線形�らペア
133 */
134 void AddHistory(Bid bid) {
135 if (type == 0) {
136 AddHistoryNonLin(bid);
137
138 } else {
139 AddHistoryLin(bid);
140 }
141 }
142
143 void AddHistoryNonLin(Bid bid) {
144
145 HashMap<Integer, Value> map = bid.getValues();
146 IssueInteger lIssueInteger;
147 ValueInteger v1;
148
149 UtilityPair pair = new UtilityPair();
150
151 add *= derta;
152
153 int size = issues.size();
154
155 for (int i = 0; i < size; i++) {
156 lIssueInteger = (IssueInteger) issues.get(i);
157 v1 = (ValueInteger) map.get(lIssueInteger.getNumber());
158 pair.add(new Pair(lIssueInteger.getNumber(), v1.getValue()));
159
160 for (int j = i + 1; j < size; j++) {
161 lIssueInteger = (IssueInteger) issues.get(j);
162 v1 = (ValueInteger) map.get(lIssueInteger.getNumber());
163 pair.add(new Pair(lIssueInteger.getNumber(), v1.getValue()));
164
165 // System.out.print("add!" + pair.get(0).key
166 // +""+pair.get(1).key);
167
168 UtilityPair p = new UtilityPair();
169 p.addAll(pair);
170 if (utility.containsKey(p)) {
171 // utility.put(p, add);
172 utility.put(p, utility.get(pair) + add);
173
174 } else {
175
176 utility.put(p, add);
177 }
178 pair.remove(pair.size() - 1);
179 }
180 pair.remove(pair.size() - 1);
181
182 }
183 }
184
185 void AddHistoryLin(Bid bid) {
186 HashMap<Integer, Value> map = bid.getValues();
187 UtilityPair pair = new UtilityPair();
188 add *= derta;
189 IssueDiscrete ID;
190 int size = issues.size();
191
192 for (int i = 0; i < size; i++) {
193
194 ID = (IssueDiscrete) issues.get(i);
195
196 pair.add(new Pair(ID.getNumber(), ID.getNumberOfValues()));
197 UtilityPair p = new UtilityPair();
198 p.addAll(pair);
199 if (utility.containsKey(p)) {
200 // utility.put(p, add);
201 utility.put(p, utility.get(pair) + add);
202
203 } else {
204
205 utility.put(p, add);
206 }
207
208 pair.remove(pair.size() - 1);
209 }
210
211 }
212
213 List<Gene> list = null;
214
215 double SearchMaxPoint() {
216
217 double ret = 0.0;
218
219 GA_Main gaMain;
220
221 if (list == null) {
222 gaMain = new GA_Main(new BidGenerationChange(100),
223 new CompMyBidGene(-1));
224
225 } else {
226 List<Gene> in = new ArrayList<Gene>(100);
227 for (int i = 0; i < 10; i++) {
228 in.add(new MyBidGene(((MyBidGene) list.get(i)).bid));
229 }
230 for (int i = 0; i < 100; i++) {
231 in.add(new MyBidGene(agent.GetRandomBid()));
232 }
233 gaMain = new GA_Main(in, new BidGenerationChange(100, 10),
234 new CompMyBidGene(0));
235
236 }
237 gaMain.Start();
238 ret = ((MyBidGene) gaMain.GetList().get(0)).GetValue(-1);
239 list = null;
240 list = gaMain.GetList();
241 return ret;
242
243 }
244}
245
246class UtilityPair extends ArrayList<Pair> {
247
248 public UtilityPair() {
249 super();
250 }
251
252 Boolean Hit(Bid b) {
253 for (Pair p : this) {
254 HashMap<Integer, Value> map = b.getValues();
255 if (((ValueInteger) map.get(p.key)).getValue() == p.value) {
256 return false;
257 }
258 }
259 return true;
260 }
261}
262
263class Pair {
264 int key, value;
265
266 Pair(int k, int v) {
267 key = k;
268 value = v;
269 }
270
271 @Override
272 public int hashCode() {
273 return ((key << 16) | value);
274 }
275
276 @Override
277 public boolean equals(Object obj) {
278 Pair p = (Pair) obj;
279 if (key == p.key && value == p.value) {
280 return true;
281 }
282 return false;
283 }
284}
285
286class CompPair implements java.util.Comparator<Pair> {
287 @Override
288 public int compare(Pair o1, Pair o2) {
289 double x = o1.key - o2.key;
290 if (x > 0) {
291 return 1;
292 }
293 if (x < 0) {
294 return -1;
295 }
296 return 0;
297 }
298
299}
Note: See TracBrowser for help on using the repository browser.