1 | package negotiator.boaframework.opponentmodel;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.boaframework.NegotiationSession;
|
---|
10 | import genius.core.boaframework.OpponentModel;
|
---|
11 | import genius.core.issue.Issue;
|
---|
12 | import genius.core.issue.IssueDiscrete;
|
---|
13 | import genius.core.issue.Value;
|
---|
14 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
15 | import negotiator.boaframework.opponentmodel.tools.UtilitySpaceAdapter;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Optimized version of the ANAC2012 CUKHAgent opponent model. Adapted by Mark
|
---|
19 | * Hendrikx to be compatible with the BOA framework.
|
---|
20 | *
|
---|
21 | * This model keeps track of how many times each value has been offered. In the
|
---|
22 | * author's implementation the sum of the value scores is used to quantify the
|
---|
23 | * quality of the bid. In my BOA-compatible implementation I divide the sum of
|
---|
24 | * the value scores by the maximum possible score to normalize the score to a
|
---|
25 | * utility.
|
---|
26 | *
|
---|
27 | * Note that after 100 bids the model is no longer updated.
|
---|
28 | *
|
---|
29 | * Tim Baarslag, Koen Hindriks, Mark Hendrikx, Alex Dirkzwager and Catholijn M.
|
---|
30 | * Jonker. Decoupling Negotiating Agents to Explore the Space of Negotiation
|
---|
31 | * Strategies
|
---|
32 | *
|
---|
33 | * @author Mark Hendrikx
|
---|
34 | */
|
---|
35 | public class CUHKFrequencyModelV2 extends OpponentModel {
|
---|
36 |
|
---|
37 | /** History of unique bids, contains at most 100 bids */
|
---|
38 | private ArrayList<Bid> bidHistory;
|
---|
39 | /**
|
---|
40 | * List of Hashmaps storing how much each value has been offered for each
|
---|
41 | * issue
|
---|
42 | */
|
---|
43 | private ArrayList<HashMap<Value, Integer>> opponentBidsStatisticsDiscrete;
|
---|
44 | /**
|
---|
45 | * Optimization which stores the score of the most prefered value for each
|
---|
46 | * issue
|
---|
47 | */
|
---|
48 | private HashMap<Integer, Integer> maxPreferencePerIssue;
|
---|
49 | /**
|
---|
50 | * Maximum amount unique bids which may be stored by the agent. After this
|
---|
51 | * limit the OM is not updated
|
---|
52 | */
|
---|
53 | private int maximumBidsStored = 100;
|
---|
54 | /** Cache the issues of the domain to improve performance */
|
---|
55 | private List<Issue> issues;
|
---|
56 | /** Highest possible sum of values */
|
---|
57 | private int maxPossibleTotal = 0;
|
---|
58 | /**
|
---|
59 | * After 100 bids the utilityspace does not chance, and can therefore be
|
---|
60 | * cached
|
---|
61 | */
|
---|
62 | private AdditiveUtilitySpace cache = null;
|
---|
63 | /** Boolean which indicates if the utilityspaced is arleady cached */
|
---|
64 | private boolean cached = false;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * initialization of the model in which the issues are cached and the score
|
---|
68 | * keeper for each issue is created.
|
---|
69 | */
|
---|
70 | @Override
|
---|
71 | public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
|
---|
72 | this.bidHistory = new ArrayList<Bid>();
|
---|
73 | opponentBidsStatisticsDiscrete = new ArrayList<HashMap<Value, Integer>>();
|
---|
74 | maxPreferencePerIssue = new HashMap<Integer, Integer>();
|
---|
75 | this.negotiationSession = negotiationSession;
|
---|
76 | try {
|
---|
77 | issues = negotiationSession.getUtilitySpace().getDomain().getIssues();
|
---|
78 |
|
---|
79 | for (int i = 0; i < issues.size(); i++) {
|
---|
80 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) issues.get(i);
|
---|
81 | HashMap<Value, Integer> discreteIssueValuesMap = new HashMap<Value, Integer>();
|
---|
82 | for (int j = 0; j < lIssueDiscrete.getNumberOfValues(); j++) {
|
---|
83 | Value v = lIssueDiscrete.getValue(j);
|
---|
84 | discreteIssueValuesMap.put(v, 0);
|
---|
85 | }
|
---|
86 | maxPreferencePerIssue.put(i, 0);
|
---|
87 | opponentBidsStatisticsDiscrete.add(discreteIssueValuesMap);
|
---|
88 | }
|
---|
89 | } catch (Exception e) {
|
---|
90 | e.printStackTrace();
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * This function updates the opponent's Model by calling the
|
---|
96 | * updateStatistics method
|
---|
97 | */
|
---|
98 | public void updateModel(Bid bid, double time) {
|
---|
99 | if (this.bidHistory.size() > this.maximumBidsStored) {
|
---|
100 | return;
|
---|
101 | }
|
---|
102 | if (bidHistory.indexOf(bid) == -1) {
|
---|
103 | this.bidHistory.add(bid);
|
---|
104 | }
|
---|
105 | if (this.bidHistory.size() <= this.maximumBidsStored) {
|
---|
106 | this.updateStatistics(bid);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * This function updates the statistics of the bids that were received from
|
---|
112 | * the opponent.
|
---|
113 | */
|
---|
114 | private void updateStatistics(Bid bidToUpdate) {
|
---|
115 | try {
|
---|
116 | // counters for each type of the issues
|
---|
117 | int discreteIndex = 0;
|
---|
118 | for (Issue lIssue : issues) {
|
---|
119 | int issueNum = lIssue.getNumber();
|
---|
120 | Value v = bidToUpdate.getValue(issueNum);
|
---|
121 | if (opponentBidsStatisticsDiscrete == null) {
|
---|
122 | System.out.println("opponentBidsStatisticsDiscrete is NULL");
|
---|
123 | } else if (opponentBidsStatisticsDiscrete.get(discreteIndex) != null) {
|
---|
124 | int counterPerValue = opponentBidsStatisticsDiscrete.get(discreteIndex).get(v);
|
---|
125 | counterPerValue++;
|
---|
126 | if (counterPerValue > maxPreferencePerIssue.get(discreteIndex)) {
|
---|
127 | maxPreferencePerIssue.put(discreteIndex, counterPerValue);
|
---|
128 | maxPossibleTotal++; // must be an increase by 1 one the
|
---|
129 | // total
|
---|
130 | }
|
---|
131 | opponentBidsStatisticsDiscrete.get(discreteIndex).put(v, counterPerValue);
|
---|
132 | }
|
---|
133 | discreteIndex++;
|
---|
134 | }
|
---|
135 | } catch (Exception e) {
|
---|
136 | System.out.println("Exception in updateStatistics: " + e.getMessage());
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | public double getBidEvaluation(Bid bid) {
|
---|
141 | int discreteIndex = 0;
|
---|
142 | int totalBidValue = 0;
|
---|
143 | try {
|
---|
144 | for (int j = 0; j < issues.size(); j++) {
|
---|
145 | Value v = bid.getValue(issues.get(j).getNumber());
|
---|
146 | if (opponentBidsStatisticsDiscrete == null) {
|
---|
147 | System.err.println("opponentBidsStatisticsDiscrete is NULL");
|
---|
148 | } else if (opponentBidsStatisticsDiscrete.get(discreteIndex) != null) {
|
---|
149 | int counterPerValue = opponentBidsStatisticsDiscrete.get(discreteIndex).get(v);
|
---|
150 | totalBidValue += counterPerValue;
|
---|
151 | }
|
---|
152 | discreteIndex++;
|
---|
153 | }
|
---|
154 | } catch (Exception e) {
|
---|
155 | e.printStackTrace();
|
---|
156 | }
|
---|
157 | if (totalBidValue == 0) {
|
---|
158 | return 0.0;
|
---|
159 | }
|
---|
160 | return (double) totalBidValue / (double) maxPossibleTotal;
|
---|
161 | }
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Returns the estimated utilityspace. After 100 unique bids the opponent
|
---|
165 | * model is not longer updated, and therefore a cached version can be used.
|
---|
166 | */
|
---|
167 | public AdditiveUtilitySpace getOpponentUtilitySpace() {
|
---|
168 | if (!cached && this.bidHistory.size() >= this.maximumBidsStored) {
|
---|
169 | cached = true;
|
---|
170 | cache = new UtilitySpaceAdapter(this, negotiationSession.getUtilitySpace().getDomain());
|
---|
171 | } else if (this.bidHistory.size() < this.maximumBidsStored) {
|
---|
172 | return new UtilitySpaceAdapter(this, negotiationSession.getUtilitySpace().getDomain());
|
---|
173 | }
|
---|
174 | return cache;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * This model does not rely on issue weights. Therefore, the issue weight is
|
---|
179 | * uniform.
|
---|
180 | */
|
---|
181 | public double getWeight(Issue issue) {
|
---|
182 | return (1.0 / (double) issues.size());
|
---|
183 | }
|
---|
184 |
|
---|
185 | public String getName() {
|
---|
186 | return "CUHK Frequency Model V2";
|
---|
187 | }
|
---|
188 | } |
---|