source: anac2020/AzarAgent/src/main/java/geniusweb/exampleparties/simpleshaop/USpace.java@ 1

Last change on this file since 1 was 1, checked in by wouter, 4 years ago

#1910 added anac2020 parties

File size: 3.3 KB
Line 
1package geniusweb.exampleparties.simpleshaop;
2
3import java.util.HashMap;
4import java.util.Map.Entry;
5
6import geniusweb.issuevalue.Bid;
7import geniusweb.issuevalue.Domain;
8import geniusweb.issuevalue.Value;
9
10public class USpace {
11
12 // نگه داری وزن های ایشیوها
13 private HashMap<String, Double> weights = new HashMap<String, Double>();
14
15 private HashMap<String, HashMap<Value, Double>> evals = new HashMap<String, HashMap<Value,Double>>();
16
17 private Domain domain;
18
19 public USpace(Domain domain) {
20 this.domain = domain;
21 intitialize();
22 }
23
24 private void intitialize() {
25
26 double w = 1.0/this.domain.getIssues().size();
27 for ( String issue : this.domain.getIssues() ) {
28 weights.put(issue, w);
29 HashMap<Value, Double> hm = new HashMap<Value, Double>();;
30 for ( Value val : this.domain.getValues(issue) ) {
31 hm.put(val, 1.0);
32 }
33 evals.put(issue, hm);
34 }
35
36 }
37
38 public Domain getDomain() {
39 return domain;
40 }
41
42 public void setWeight(String issue, double w) {
43 weights.replace(issue, w);
44 }
45
46 public void setEval(String issue, Value val, double eval) {
47
48 //System.err.println( issue + ", "+ val +", "+eval );
49
50 HashMap<Value, Double> hm = new HashMap<Value, Double>();
51 hm.put(val, eval);
52 for ( Value value : domain.getValues(issue) )
53 if( !value.equals(val) )
54 hm.put(value, evals.get(issue).get(value));
55
56
57 evals.replace( issue, hm );
58
59 }
60
61 public HashMap<String, Double> getWeights() {
62 return weights;
63 }
64
65 public HashMap<String, HashMap<Value, Double>> getEvals() {
66 return evals;
67 }
68
69 public Double getWeight(String iss) {
70
71 return weights.get(iss);
72
73 }
74
75 public HashMap<Value, Double> getValues(String issue) {
76
77 return evals.get(issue);
78
79 }
80
81 public double getValue(String issue, Value val) {
82
83 return evals.get(issue).get(val);
84
85 }
86
87
88 public double getUtility(Bid bid) {
89
90
91
92
93 HashMap<String, Double> maxValOfIssue = new HashMap<String, Double>();
94 for (String issue : domain.getIssues())
95 for ( Value val : domain.getValues(issue) )
96 maxValOfIssue.put(issue, 0.0);
97
98 // پیدا کردن ماکزیمم ولیو برای هر ایشیو
99 for (String issue : domain.getIssues())
100 for ( Value val : domain.getValues(issue) )
101 if ( getValue(issue, val) > maxValOfIssue.get(issue) )
102 maxValOfIssue.replace(issue, getValue(issue, val));
103
104
105 // نرمالایز کردن
106 HashMap<String, HashMap<Value, Double>> evalsTemp = new HashMap<String, HashMap<Value,Double>>();
107 for ( String issue : getEvals().keySet() ) {
108 HashMap<Value, Double> valTemp = new HashMap<Value, Double>();
109 for ( Value val : getValues(issue).keySet() ) {
110 valTemp.put(val, (double)getValue(issue, val)/maxValOfIssue.get(issue) );
111 }
112 evalsTemp.put(issue, valTemp);
113 }
114
115
116
117 double u = 0;
118 for ( Entry<String,Value> e : bid.getIssueValues().entrySet() )
119 u += weights.get(e.getKey())*evalsTemp.get(e.getKey()).get(e.getValue());
120
121
122 return u;
123
124
125
126 }
127
128
129
130 public String toString() {
131
132 String s = "[";
133 for ( String w : weights.keySet() ) {
134 s += w+ "=> W=" + weights.get(w)+"=>[";
135 for ( Value val : evals.get(w).keySet() )
136 s += val.toString() + "=" + evals.get(w).get(val)+", ";
137 }
138 s += "]";
139
140 return s;
141 }
142
143
144
145
146
147
148
149}
Note: See TracBrowser for help on using the repository browser.