1 | package agents.ai2014.group2;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.Map;
|
---|
6 | import java.util.Map.Entry;
|
---|
7 |
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.Domain;
|
---|
10 | import genius.core.issue.Issue;
|
---|
11 | import genius.core.issue.IssueDiscrete;
|
---|
12 | import genius.core.issue.Objective;
|
---|
13 | import genius.core.issue.Value;
|
---|
14 | import genius.core.issue.ValueDiscrete;
|
---|
15 | import genius.core.utility.Evaluator;
|
---|
16 |
|
---|
17 | import java.util.Set;
|
---|
18 |
|
---|
19 | class G2Bid {
|
---|
20 | private Map<String, String> choices;
|
---|
21 |
|
---|
22 | private Map<String, String> extractChoicesFromBid(Bid bid) {
|
---|
23 | Map<String, String> bidChoices = new HashMap<String, String>();
|
---|
24 | List<Issue> issues = bid.getIssues();
|
---|
25 |
|
---|
26 | for (genius.core.issue.Issue issue : issues) {
|
---|
27 | try {
|
---|
28 | bidChoices.put(issue.getName(), bid.getValue(issue.getNumber())
|
---|
29 | .toString());
|
---|
30 | } catch (Exception e) {
|
---|
31 | // TODO Auto-generated catch block
|
---|
32 | e.printStackTrace();
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | return bidChoices;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public G2Bid(Bid bid) {
|
---|
40 | choices = extractChoicesFromBid(bid);
|
---|
41 | }
|
---|
42 |
|
---|
43 | public G2Bid(Map<String, String> options) {
|
---|
44 | choices = new HashMap<String, String>(options);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public String getChoice(String issue) {
|
---|
48 | return choices.get(issue);
|
---|
49 | }
|
---|
50 |
|
---|
51 | public String setChoice(String issue, String choice) {
|
---|
52 | return choices.put(issue, choice);
|
---|
53 | }
|
---|
54 |
|
---|
55 | public Map<String, String> getChoices() {
|
---|
56 | return choices;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public Set<Entry<String, String>> getEntrySet() {
|
---|
60 | return choices.entrySet();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public String toString() {
|
---|
64 | String s = "";
|
---|
65 | for (Entry<String, String> entry : getEntrySet()) {
|
---|
66 | s += "[" + entry.getKey() + ":" + entry.getValue() + "]";
|
---|
67 | }
|
---|
68 | return s;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public Bid convertToBid(Domain domain,
|
---|
72 | Set<Entry<Objective, Evaluator>> evaluators) throws Exception {
|
---|
73 | HashMap<Integer, Value> map = new HashMap<Integer, Value>();
|
---|
74 |
|
---|
75 | for (Entry<Objective, Evaluator> entry : evaluators) {
|
---|
76 | IssueDiscrete issue = (IssueDiscrete) entry.getKey();
|
---|
77 | Integer index = issue.getNumber();
|
---|
78 | ValueDiscrete value = issue.getValue(issue
|
---|
79 | .getValueIndex(getChoice(issue.getName())));
|
---|
80 | map.put(index, value);
|
---|
81 | }
|
---|
82 |
|
---|
83 | return new Bid(domain, map);
|
---|
84 | }
|
---|
85 |
|
---|
86 | boolean equals(G2Bid otherBid) {
|
---|
87 | Set<String> keySet = choices.keySet();
|
---|
88 | if (!(keySet.size() == otherBid.choices.keySet().size())) {
|
---|
89 | return false;
|
---|
90 | }
|
---|
91 | for (String issue : keySet) {
|
---|
92 | if (!choices.get(issue).equals(otherBid.getChoice(issue))) {
|
---|
93 | return false;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 | } |
---|