[1] | 1 | package agents.ai2014.group6;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.Collections;
|
---|
| 5 | import java.util.HashMap;
|
---|
| 6 | import java.util.List;
|
---|
| 7 | import java.util.Map.Entry;
|
---|
| 8 |
|
---|
| 9 | import genius.core.Bid;
|
---|
| 10 | import genius.core.issue.Value;
|
---|
| 11 |
|
---|
| 12 | public 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 | }
|
---|