source: src/main/java/agents/ai2014/group6/FrequencyAnalysisOpponentModel.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: 1.4 KB
Line 
1package agents.ai2014.group6;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.HashMap;
6import java.util.List;
7import java.util.Map.Entry;
8
9import genius.core.Bid;
10import genius.core.issue.Value;
11
12public class FrequencyAnalysisOpponentModel implements IOpponentModel {
13
14 HashMap<Integer,List<Value>> preferences;
15
16 public FrequencyAnalysisOpponentModel() {
17 preferences = new HashMap<Integer,List<Value>>();
18 }
19
20 @Override
21 // Returns the value of an issue that is most often observed.
22 // If all values are observed an equal amount of times, then select the most recent value
23 // If the issueId has not yet been observed, return null
24 public Value getValue(Integer issueId) {
25 List<Value> values = preferences.get(issueId);
26
27 if(values == null) {
28 // If no values have been learned for the issue, return null
29 return null;
30 } else {
31 // Otherwise, search value with the highest frequency or most recent
32 int maxFreq = 0;
33 Value maxVal = null;
34
35 for(Value v: values) {
36 int freq = Collections.frequency(values, v);
37 if(freq > maxFreq) {
38 maxFreq = freq;
39 maxVal = v;
40 }
41 }
42
43 return maxVal;
44 }
45 }
46
47 @Override
48 public void learnWeights(Bid bid) {
49 for(Entry<Integer, Value> issue : bid.getValues().entrySet()) {
50 if(!preferences.containsKey(issue.getKey()))
51 preferences.put(issue.getKey(), new ArrayList<Value>());
52
53 preferences.get(issue.getKey()).add(issue.getValue());
54 }
55 }
56
57}
Note: See TracBrowser for help on using the repository browser.