source: src/main/java/agents/ai2014/group2/G2Bid.java@ 127

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

Initial import : Genius 9.0.0

File size: 2.3 KB
Line 
1package agents.ai2014.group2;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.Map;
6import java.util.Map.Entry;
7
8import genius.core.Bid;
9import genius.core.Domain;
10import genius.core.issue.Issue;
11import genius.core.issue.IssueDiscrete;
12import genius.core.issue.Objective;
13import genius.core.issue.Value;
14import genius.core.issue.ValueDiscrete;
15import genius.core.utility.Evaluator;
16
17import java.util.Set;
18
19class 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}
Note: See TracBrowser for help on using the repository browser.