source: src/main/java/agents/anac/y2015/group2/G2Issue.java

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

Initial import : Genius 9.0.0

File size: 2.3 KB
Line 
1package agents.anac.y2015.group2;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.HashSet;
6import java.util.Map;
7import java.util.Map.Entry;
8import java.util.Set;
9
10class G2Issue {
11 private Map<String, Double> options;
12 private double weight;
13
14 public G2Issue() {
15 options = new HashMap<String, Double>();
16 weight = 0;
17 }
18
19 public void putValue(String name, double option) {
20 options.put(name, option);
21 }
22
23 public double getValue(String name) {
24 return options.get(name);
25 }
26
27 public double getWeight() {
28 return weight;
29 }
30
31 public void setWeight(double weight) {
32 this.weight = weight;
33 }
34
35 public double getScoreForOption(String name) {
36 /*if(options.get(name) == null){
37 System.out.println(name);
38 System.out.println(toString());
39 }*/
40 return weight * options.get(name);
41 }
42 public String toString() {
43 return options.keySet().toString() + options.values().toString();
44 }
45
46 public String weightString() {
47 Set<Entry<String, Double>> entrySet = options.entrySet();
48 String weightString = "" + weight + ": [";
49 for(Entry<String, Double> entry : entrySet) {
50 weightString += entry.getKey() + ":" + entry.getValue() + ", ";
51 }
52
53 if(options.size() > 0)
54 return weightString.substring(0, weightString.length()-2) + "]";
55 else
56 return weightString + "]";
57 }
58
59 public void SetNeutralPreference() {
60 for(String key : options.keySet()) {
61 options.put(key, 1.0);
62 }
63 }
64 public void SetZeroPreference() {
65 for(String key : options.keySet()) {
66 options.put(key, 0.0);
67 }
68 }
69
70 public void normalizeOptions(){
71 double maxOption = 0.0;
72 for(double option : options.values()){
73 if(option > maxOption){
74 maxOption = option;
75 }
76 }
77 for(Entry<String, Double> entry : options.entrySet()){
78 options.put(entry.getKey(), entry.getValue()/maxOption);
79 }
80 }
81
82 public void increaseOption(String option, int nBids){
83 putValue(option, options.get(option)+1.0/nBids);
84 normalizeOptions();
85 }
86
87 public void updateWeight(int nBids, double newWeight){
88 weight = (weight*nBids + newWeight) / (nBids+1);
89 }
90
91 public Set<String> getOtherOptions(String option){
92 Set<String> otherOptions = new HashSet <String>(options.keySet());
93 otherOptions.remove(option);
94 return otherOptions;
95 }
96
97 public Set<String> getOptionNames() {
98 return options.keySet();
99 }
100}
Note: See TracBrowser for help on using the repository browser.