1 | package negotiator.boaframework.offeringstrategy.anac2010;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.Comparator;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.Map;
|
---|
9 |
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.bidding.BidDetails;
|
---|
12 | import genius.core.boaframework.NegotiationSession;
|
---|
13 | import genius.core.boaframework.NoModel;
|
---|
14 | import genius.core.boaframework.OMStrategy;
|
---|
15 | import genius.core.boaframework.OfferingStrategy;
|
---|
16 | import genius.core.boaframework.OpponentModel;
|
---|
17 | import genius.core.issue.Issue;
|
---|
18 | import genius.core.issue.Value;
|
---|
19 | import genius.core.utility.AbstractUtilitySpace;
|
---|
20 | import negotiator.boaframework.opponentmodel.DefaultModel;
|
---|
21 | import negotiator.boaframework.opponentmodel.SmithFrequencyModel;
|
---|
22 | import negotiator.boaframework.opponentmodel.agentsmith.Bounds;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * This is the decoupled Offering Strategy for AgentSmith (ANAC2010). The code
|
---|
26 | * was taken from the ANAC2010 AgentSmith and adapted to work within the BOA
|
---|
27 | * framework.
|
---|
28 | *
|
---|
29 | * Using another opponent model strategy makes no sense for this agent.
|
---|
30 | *
|
---|
31 | * DEFAULT OM: SmithFrequencyModel
|
---|
32 | *
|
---|
33 | * Decoupling Negotiating Agents to Explore the Space of Negotiation Strategies
|
---|
34 | * T. Baarslag, K. Hindriks, M. Hendrikx, A. Dirkzwager, C.M. Jonker
|
---|
35 | *
|
---|
36 | * @author Alex Dirkzwager, Mark Hendrikx
|
---|
37 | */
|
---|
38 | public class AgentSmith_Offering extends OfferingStrategy {
|
---|
39 |
|
---|
40 | private final static double sTimeMargin = 170.0 / 180.0;
|
---|
41 | private final static double sUtilyMargin = 0.7;
|
---|
42 | static private double UTILITY_THRESHOLD = 0.7;
|
---|
43 |
|
---|
44 | private int fIndex;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Empty constructor called by BOA framework.
|
---|
48 | */
|
---|
49 | public AgentSmith_Offering() {
|
---|
50 | }
|
---|
51 |
|
---|
52 | public AgentSmith_Offering(NegotiationSession negoSession, OpponentModel om, OMStrategy oms) {
|
---|
53 | initializeAgent(negoSession, om, oms);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public void init(NegotiationSession negotiationSession, OpponentModel model, OMStrategy oms,
|
---|
58 | Map<String, Double> parameters) throws Exception {
|
---|
59 | if (model instanceof DefaultModel) {
|
---|
60 | model = new SmithFrequencyModel();
|
---|
61 | model.init(negotiationSession, null);
|
---|
62 | oms.setOpponentModel(model);
|
---|
63 | }
|
---|
64 | initializeAgent(negotiationSession, model, oms);
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void initializeAgent(NegotiationSession negoSession, OpponentModel om, OMStrategy oms) {
|
---|
68 | this.negotiationSession = negoSession;
|
---|
69 | opponentModel = om;
|
---|
70 | omStrategy = oms;
|
---|
71 | fIndex = 0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public BidDetails determineNextBid() {
|
---|
76 | // Time in seconds.
|
---|
77 | double time = negotiationSession.getTime();
|
---|
78 | Bid bid2Offer = null;
|
---|
79 | try {
|
---|
80 | // Check if the session (2 min) is almost finished
|
---|
81 | if (time >= sTimeMargin) {
|
---|
82 | // If the session is almost finished check if the utility is
|
---|
83 | // "high enough"
|
---|
84 | BidDetails lastBid = negotiationSession.getOpponentBidHistory().getLastBidDetails();
|
---|
85 | if (lastBid.getMyUndiscountedUtil() < sUtilyMargin) {
|
---|
86 | nextBid = negotiationSession.getOpponentBidHistory().getBestBidDetails();
|
---|
87 | }
|
---|
88 | } else {
|
---|
89 | bid2Offer = getMostOptimalBid();
|
---|
90 | nextBid = new BidDetails(bid2Offer, negotiationSession.getUtilitySpace().getUtility(bid2Offer),
|
---|
91 | negotiationSession.getTime());
|
---|
92 | }
|
---|
93 | } catch (Exception e) {
|
---|
94 |
|
---|
95 | }
|
---|
96 | return nextBid;
|
---|
97 | }
|
---|
98 |
|
---|
99 | @Override
|
---|
100 | public BidDetails determineOpeningBid() {
|
---|
101 | return negotiationSession.getMaxBidinDomain();
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Calculate the most optimal bid
|
---|
106 | *
|
---|
107 | * @return the most optimal bid
|
---|
108 | * @throws Exception
|
---|
109 | */
|
---|
110 | public Bid getMostOptimalBid() {
|
---|
111 | ArrayList<Bid> allBids = getSampledBidList();
|
---|
112 |
|
---|
113 | ArrayList<Bid> removeMe = new ArrayList<Bid>();
|
---|
114 | for (int i = 0; i < allBids.size(); i++) {
|
---|
115 | try {
|
---|
116 | if (negotiationSession.getUtilitySpace().getUtility(allBids.get(i)) < UTILITY_THRESHOLD) {
|
---|
117 | removeMe.add(allBids.get(i));
|
---|
118 | }
|
---|
119 | } catch (Exception e) {
|
---|
120 | e.printStackTrace();
|
---|
121 | }
|
---|
122 | }
|
---|
123 | allBids.removeAll(removeMe);
|
---|
124 |
|
---|
125 | if (opponentModel instanceof NoModel) {
|
---|
126 | Bid bid = allBids.get(fIndex);
|
---|
127 | fIndex++;
|
---|
128 | return bid;
|
---|
129 | } else {
|
---|
130 | // Log.logger.info("Size of bid space: " + lBids.size());
|
---|
131 | Comparator<Bid> lComparator = new BidComparator(negotiationSession.getUtilitySpace());
|
---|
132 |
|
---|
133 | // sort the bids in order of highest utility
|
---|
134 | ArrayList<Bid> sortedAllBids = allBids;
|
---|
135 | Collections.sort(sortedAllBids, lComparator);
|
---|
136 |
|
---|
137 | Bid lBid = sortedAllBids.get(fIndex);
|
---|
138 | if (fIndex < sortedAllBids.size() - 1)
|
---|
139 | fIndex++;
|
---|
140 | return lBid;
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | private ArrayList<Bid> getSampledBidList() {
|
---|
145 | ArrayList<Bid> lBids = new ArrayList<Bid>();
|
---|
146 | List<Issue> lIssues = negotiationSession.getIssues();
|
---|
147 | HashMap<Integer, Bounds> lBounds = Bounds.getIssueBounds(lIssues);
|
---|
148 |
|
---|
149 | // first createFrom a new list
|
---|
150 | HashMap<Integer, Value> lBidValues = new HashMap<Integer, Value>();
|
---|
151 | for (Issue lIssue : lIssues) {
|
---|
152 | Bounds b = lBounds.get(lIssue.getNumber());
|
---|
153 | Value v = Bounds.getIssueValue(lIssue, b.getLower());
|
---|
154 | lBidValues.put(lIssue.getNumber(), v);
|
---|
155 | }
|
---|
156 | try {
|
---|
157 | lBids.add(new Bid(negotiationSession.getUtilitySpace().getDomain(), lBidValues));
|
---|
158 | } catch (Exception e) {
|
---|
159 | }
|
---|
160 |
|
---|
161 | // for each item permutate with issue values, like binary
|
---|
162 | // 0 0 0
|
---|
163 | // 0 0 1
|
---|
164 | // 0 1 0
|
---|
165 | // 0 1 1
|
---|
166 | // etc.
|
---|
167 | for (Issue lIssue : lIssues) {
|
---|
168 | ArrayList<Bid> lTempBids = new ArrayList<Bid>();
|
---|
169 | Bounds b = lBounds.get(lIssue.getNumber());
|
---|
170 |
|
---|
171 | for (Bid lTBid : lBids) {
|
---|
172 | for (double i = b.getLower(); i < b.getUpper(); i += b.getStepSize()) {
|
---|
173 | HashMap<Integer, Value> lNewBidValues = getBidValues(lTBid);
|
---|
174 | lNewBidValues.put(lIssue.getNumber(), Bounds.getIssueValue(lIssue, i));
|
---|
175 |
|
---|
176 | try {
|
---|
177 | Bid iBid = new Bid(negotiationSession.getUtilitySpace().getDomain(), lNewBidValues);
|
---|
178 | lTempBids.add(iBid);
|
---|
179 |
|
---|
180 | } catch (Exception e) {
|
---|
181 |
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 | lBids = lTempBids;
|
---|
186 | }
|
---|
187 |
|
---|
188 | ArrayList<Bid> lToDestroy = new ArrayList<Bid>();
|
---|
189 | for (Bid lBid : lBids) {
|
---|
190 | try {
|
---|
191 | if (negotiationSession.getUtilitySpace().getUtility(lBid) < UTILITY_THRESHOLD) {
|
---|
192 | lToDestroy.add(lBid);
|
---|
193 | }
|
---|
194 | } catch (Exception e) {
|
---|
195 | e.printStackTrace();
|
---|
196 | }
|
---|
197 | }
|
---|
198 | for (Bid lBid : lToDestroy) {
|
---|
199 | lBids.remove(lBid);
|
---|
200 | }
|
---|
201 |
|
---|
202 | return lBids;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Get the values of a bid
|
---|
207 | *
|
---|
208 | * @param pBid
|
---|
209 | * @return
|
---|
210 | */
|
---|
211 | private HashMap<Integer, Value> getBidValues(Bid pBid) {
|
---|
212 | HashMap<Integer, Value> lNewBidValues = new HashMap<Integer, Value>();
|
---|
213 | for (Issue lIssue : negotiationSession.getUtilitySpace().getDomain().getIssues()) {
|
---|
214 | try {
|
---|
215 | lNewBidValues.put(lIssue.getNumber(), pBid.getValue(lIssue.getNumber()));
|
---|
216 | } catch (Exception e) {
|
---|
217 |
|
---|
218 | }
|
---|
219 | }
|
---|
220 | return lNewBidValues;
|
---|
221 | }
|
---|
222 |
|
---|
223 | public class BidComparator implements Comparator<Bid> {
|
---|
224 |
|
---|
225 | private AbstractUtilitySpace space;
|
---|
226 |
|
---|
227 | public BidComparator(AbstractUtilitySpace mySpace) {
|
---|
228 | this.space = mySpace;
|
---|
229 | }
|
---|
230 |
|
---|
231 | /*
|
---|
232 | * returns 1 if his own bid is better than the opponents, -1 otherwise
|
---|
233 | */
|
---|
234 | public int compare(Bid b1, Bid b2) {
|
---|
235 | return getMeasure(b2) > getMeasure(b1) ? -1 : 1;
|
---|
236 | }
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * returns a double that represents the value of a value of a bid,
|
---|
240 | * taking into account both the agents own and opponents' utility.
|
---|
241 | */
|
---|
242 | public double getMeasure(Bid b1) {
|
---|
243 | double a = 0;
|
---|
244 | try {
|
---|
245 | a = (1 - space.getUtility(b1));
|
---|
246 | } catch (Exception e) {
|
---|
247 | e.printStackTrace();
|
---|
248 | }
|
---|
249 | double b = (1 - opponentModel.getBidEvaluation(b1));
|
---|
250 |
|
---|
251 | double alpha = Math.atan(b / a);
|
---|
252 |
|
---|
253 | return a + b + (0.5 * Math.PI / alpha) * 0.5 * Math.PI;
|
---|
254 | }
|
---|
255 |
|
---|
256 | }
|
---|
257 |
|
---|
258 | @Override
|
---|
259 | public String getName() {
|
---|
260 | return "2010 - AgentSmith";
|
---|
261 | }
|
---|
262 | } |
---|