1 | package agents.anac.y2011.ValueModelAgent;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.Map;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.issue.ISSUETYPE;
|
---|
8 | import genius.core.issue.Issue;
|
---|
9 | import genius.core.issue.IssueDiscrete;
|
---|
10 | import genius.core.issue.Value;
|
---|
11 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
12 |
|
---|
13 | public class ValueSeperatedBids {
|
---|
14 |
|
---|
15 | private class ValueBidData {
|
---|
16 | BidList approvedSorted = new BidList();
|
---|
17 | int lastTimeBidden = -1;
|
---|
18 | boolean changed = false;
|
---|
19 |
|
---|
20 | void addWrapper(BidWrapper bid) {
|
---|
21 | approvedSorted.addIfNew(bid);
|
---|
22 | changed = true;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | private class IssueSeperatedBids {
|
---|
27 | public Map<String, ValueBidData> values = new HashMap<String, ValueBidData>();
|
---|
28 | }
|
---|
29 |
|
---|
30 | AdditiveUtilitySpace utilitySpace;
|
---|
31 | IssueSeperatedBids[] issues;
|
---|
32 | ValueModeler model;
|
---|
33 |
|
---|
34 | public void addApproved(BidWrapper bid) {
|
---|
35 | for (int i = 0; i < issues.length; i++) {
|
---|
36 | if (issues[i] != null) {
|
---|
37 |
|
---|
38 | try {
|
---|
39 | Value value = bid.bid.getValue(utilitySpace.getIssue(i)
|
---|
40 | .getNumber());
|
---|
41 | ValueBidData data = issues[i].values.get(value.toString());
|
---|
42 | data.addWrapper(bid);
|
---|
43 | } catch (Exception e) {
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void bidden(Bid bid, int roundID) {
|
---|
51 |
|
---|
52 | for (int i = 0; i < issues.length; i++) {
|
---|
53 | if (issues[i] != null) {
|
---|
54 |
|
---|
55 | try {
|
---|
56 | Value value = bid.getValue(utilitySpace.getIssue(i)
|
---|
57 | .getNumber());
|
---|
58 | ValueBidData data = issues[i].values.get(value.toString());
|
---|
59 | data.lastTimeBidden = roundID;
|
---|
60 | } catch (Exception e) {
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public void init(AdditiveUtilitySpace space, ValueModeler model) {
|
---|
67 | this.model = model;
|
---|
68 | utilitySpace = space;
|
---|
69 | int issueCount = utilitySpace.getDomain().getIssues().size();
|
---|
70 | issues = new IssueSeperatedBids[issueCount];
|
---|
71 | for (int i = 0; i < issueCount; i++) {
|
---|
72 | Issue issue = utilitySpace.getDomain().getIssues().get(i);
|
---|
73 | if (issue.getType() == ISSUETYPE.DISCRETE) {
|
---|
74 | issues[i] = new IssueSeperatedBids();
|
---|
75 | IssueDiscrete issueD = (IssueDiscrete) issue;
|
---|
76 | int s = issueD.getNumberOfValues();
|
---|
77 | for (int j = 0; j < s; j++) {
|
---|
78 | String key = issueD.getValue(j).toString();
|
---|
79 | issues[i].values.put(key, new ValueBidData());
|
---|
80 | }
|
---|
81 |
|
---|
82 | } else {
|
---|
83 | issues[i] = null;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | public BidWrapper explore(int round) {
|
---|
89 |
|
---|
90 | ValueBidData minData = null;
|
---|
91 | int minRound = round;
|
---|
92 | int maxBidsAvaliable = 1;
|
---|
93 | int issueCount = utilitySpace.getDomain().getIssues().size();
|
---|
94 | for (int i = 0; i < issueCount; i++) {
|
---|
95 | Issue issue = utilitySpace.getDomain().getIssues().get(i);
|
---|
96 | if (issue.getType() == ISSUETYPE.DISCRETE) {
|
---|
97 | IssueDiscrete issueD = (IssueDiscrete) issue;
|
---|
98 | int s = issueD.getNumberOfValues();
|
---|
99 | for (int j = 0; j < s; j++) {
|
---|
100 | String key = issueD.getValue(j).toString();
|
---|
101 | ValueBidData data = issues[i].values.get(key);
|
---|
102 | int s2 = data.approvedSorted.bids.size();
|
---|
103 | if (s2 > 0
|
---|
104 | && (data.lastTimeBidden < minRound || (data.lastTimeBidden == minRound && maxBidsAvaliable < s2))) {
|
---|
105 | minRound = data.lastTimeBidden;
|
---|
106 | maxBidsAvaliable = s2;
|
---|
107 | minData = data;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | }
|
---|
112 | }
|
---|
113 | if (minData != null) {
|
---|
114 | if (minData.changed == true) {
|
---|
115 | minData.approvedSorted.sortByOpponentUtil(model);
|
---|
116 | minData.changed = false;
|
---|
117 | }
|
---|
118 | if (minRound == round)
|
---|
119 | return null;
|
---|
120 | for (int i = 0; i < minData.approvedSorted.bids.size(); i++) {
|
---|
121 | BidWrapper tempBid = minData.approvedSorted.bids.get(i);
|
---|
122 | if (!tempBid.sentByUs) {
|
---|
123 | return tempBid;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | minData.lastTimeBidden = round;
|
---|
127 | // if all bids in this value were taken, trying to explore a
|
---|
128 | // different
|
---|
129 | // value
|
---|
130 | return explore(round);
|
---|
131 | }
|
---|
132 | return null;
|
---|
133 | }
|
---|
134 |
|
---|
135 | public void clear() {
|
---|
136 | int issueCount = utilitySpace.getDomain().getIssues().size();
|
---|
137 | for (int i = 0; i < issueCount; i++) {
|
---|
138 | Issue issue = utilitySpace.getDomain().getIssues().get(i);
|
---|
139 | if (issue.getType() == ISSUETYPE.DISCRETE) {
|
---|
140 | IssueDiscrete issueD = (IssueDiscrete) issue;
|
---|
141 | int s = issueD.getNumberOfValues();
|
---|
142 | for (int j = 0; j < s; j++) {
|
---|
143 | String key = issueD.getValue(j).toString();
|
---|
144 | ValueBidData data = issues[i].values.get(key);
|
---|
145 | data.approvedSorted.bids.clear();
|
---|
146 | }
|
---|
147 |
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 | } |
---|