1 | package parties.feedbackmediator.partialopponentmodel;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Iterator;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.Map.Entry;
|
---|
9 |
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.Feedback;
|
---|
12 | import genius.core.issue.Issue;
|
---|
13 | import genius.core.issue.Value;
|
---|
14 |
|
---|
15 | import java.util.Set;
|
---|
16 |
|
---|
17 | public class ValuePreferenceGraphMap {
|
---|
18 | /*
|
---|
19 | * for each issue, value-score pairs are kept.
|
---|
20 | */
|
---|
21 | private HashMap<Integer, ValuePreferenceGraph> issuePreferenceList;
|
---|
22 | private List<Issue> issueList;
|
---|
23 |
|
---|
24 | public ValuePreferenceGraphMap() {
|
---|
25 | issuePreferenceList = new HashMap<Integer, ValuePreferenceGraph>();
|
---|
26 | issueList = new ArrayList<Issue>();
|
---|
27 | }
|
---|
28 |
|
---|
29 | public ValuePreferenceGraphMap(Bid firstBid) {
|
---|
30 |
|
---|
31 | issuePreferenceList = new HashMap<Integer, ValuePreferenceGraph>();
|
---|
32 | issueList = firstBid.getIssues();
|
---|
33 |
|
---|
34 | Set<Entry<Integer, Value>> valueSet = firstBid.getValues().entrySet();
|
---|
35 | Iterator<Entry<Integer, Value>> valueIterator = valueSet.iterator();
|
---|
36 |
|
---|
37 | while (valueIterator.hasNext()) {
|
---|
38 | Map.Entry<Integer, Value> indexValuePair = (Entry<Integer, Value>) valueIterator.next();
|
---|
39 | issuePreferenceList.put((Integer) indexValuePair.getKey(),
|
---|
40 | new ValuePreferenceGraph((Value) indexValuePair.getValue()));
|
---|
41 | }
|
---|
42 |
|
---|
43 | for (Issue issue : issueList)
|
---|
44 | issuePreferenceList.get(issue.getNumber()).setIssue(issue);
|
---|
45 |
|
---|
46 | }
|
---|
47 |
|
---|
48 | public double getEstimatedUtility(int issueIndex, Value issueValue) {
|
---|
49 | return issuePreferenceList.get(issueIndex).getEstimatedUtility(issueValue);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public double estimateUtility(Bid currentBid) throws Exception {
|
---|
53 |
|
---|
54 | double utility = 0.0;
|
---|
55 |
|
---|
56 | for (Issue issue : issueList) {
|
---|
57 | utility += getEstimatedUtility(issue.getNumber(), currentBid.getValue(issue.getNumber()));
|
---|
58 | }
|
---|
59 |
|
---|
60 | return utility;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public void updateValuePreferenceGraph(int issueIndex, Value previousValue, Value currentValue, Feedback feedback) {
|
---|
64 |
|
---|
65 | issuePreferenceList.get(issueIndex).addPreferenceOrdering(previousValue, currentValue, feedback);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public ArrayList<Value> getAllValues(int issueIndex) {
|
---|
69 | return issuePreferenceList.get(issueIndex).getAllValues();
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * @return true iff the new value is less preferred than current value,
|
---|
74 | * otherwise false (even we cannot compare them)
|
---|
75 | */
|
---|
76 | public boolean isLessPreferredThan(int issueIndex, Value newValue, Value currentValue) {
|
---|
77 |
|
---|
78 | return issuePreferenceList.get(issueIndex).getAllLessPreferredValues(currentValue).contains(newValue);
|
---|
79 | }
|
---|
80 |
|
---|
81 | public boolean isEquallyPreferred(int issueIndex, Value newValue, Value currentValue) {
|
---|
82 | return issuePreferenceList.get(issueIndex).getEqualPreferredValues(currentValue).contains(newValue);
|
---|
83 | }
|
---|
84 |
|
---|
85 | public boolean isMorePreferredThan(int issueIndex, Value newValue, Value currentValue) {
|
---|
86 |
|
---|
87 | return (issuePreferenceList.get(issueIndex).getAllMorePreferredValues(currentValue).contains(newValue));
|
---|
88 | }
|
---|
89 |
|
---|
90 | public Value getMissingValue(int issueIndex) {
|
---|
91 | return issuePreferenceList.get(issueIndex).getMissingValue();
|
---|
92 | }
|
---|
93 |
|
---|
94 | public ArrayList<Value> getIncomparableValues(int issueIndex, Value currentValue) {
|
---|
95 | return issuePreferenceList.get(issueIndex).getAllIncomparableValues(currentValue);
|
---|
96 | }
|
---|
97 |
|
---|
98 | public Value getIncomparableValue(int issueIndex, Value currentValue) {
|
---|
99 | return issuePreferenceList.get(issueIndex).getIncomparableValue(currentValue);
|
---|
100 | }
|
---|
101 |
|
---|
102 | @Override
|
---|
103 | public String toString() {
|
---|
104 |
|
---|
105 | Set<Integer> keySet = this.issuePreferenceList.keySet();
|
---|
106 |
|
---|
107 | Iterator<Integer> keyIterator = keySet.iterator();
|
---|
108 |
|
---|
109 | StringBuffer buffy = new StringBuffer("Issue Preference Map:\n");
|
---|
110 | while (keyIterator.hasNext()) {
|
---|
111 | buffy.append("\n\n" + issuePreferenceList.get(keyIterator.next()).toString());
|
---|
112 | }
|
---|
113 |
|
---|
114 | return (buffy.toString());
|
---|
115 | }
|
---|
116 | } |
---|