[127] | 1 | package agents.anac.y2010.AgentFSEGA;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.Collections;
|
---|
| 5 |
|
---|
| 6 | import genius.core.Agent;
|
---|
| 7 | import genius.core.Bid;
|
---|
| 8 | import genius.core.BidIterator;
|
---|
| 9 | import genius.core.SupportedNegotiationSetting;
|
---|
| 10 | import genius.core.actions.Accept;
|
---|
| 11 | import genius.core.actions.Action;
|
---|
| 12 | import genius.core.actions.EndNegotiation;
|
---|
| 13 | import genius.core.actions.Offer;
|
---|
| 14 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * ANAC2010 competitor AgentFSEGA.
|
---|
| 18 | */
|
---|
| 19 | public class AgentFSEGA extends Agent {
|
---|
| 20 | enum ACTIONTYPE {
|
---|
| 21 | START, OFFER, ACCEPT, BREAKOFF
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | enum STRATEGY {
|
---|
| 25 | SMART, SERIAL, RESPONSIVE, RANDOM, TIT_FOR_TAT
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | private Action lastOponentAction;
|
---|
| 29 | private Action myLastAction;
|
---|
| 30 | private OpponentModel opponentModel;
|
---|
| 31 | private ArrayList<Bid> leftBids;
|
---|
| 32 | private double elapsedTimeNorm;
|
---|
| 33 | private static final double SIGMA = 0.01;
|
---|
| 34 | private static final double MIN_ALLOWED_UTILITY = 0.5;
|
---|
| 35 | private static final double SIGMA_MAX = 0.5;
|
---|
| 36 |
|
---|
| 37 | /** Returns the version of the agent. */
|
---|
| 38 | @Override
|
---|
| 39 | public String getVersion() {
|
---|
| 40 | return "1.0";
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /** Initializes the agent. */
|
---|
| 44 | @Override
|
---|
| 45 | public void init() {
|
---|
| 46 | lastOponentAction = null;
|
---|
| 47 | myLastAction = null;
|
---|
| 48 |
|
---|
| 49 | // initialize opponent model
|
---|
| 50 | opponentModel = new MyBayesianOpponentModel(
|
---|
| 51 | (AdditiveUtilitySpace) utilitySpace);
|
---|
| 52 |
|
---|
| 53 | // initialize left bids
|
---|
| 54 | BidIterator bIterCount = new BidIterator(utilitySpace.getDomain());
|
---|
| 55 | // proposedBids = new ArrayList<Bid>();
|
---|
| 56 | leftBids = new ArrayList<Bid>();
|
---|
| 57 |
|
---|
| 58 | double[] nrBids = { 0, 0, 0, 0, 0 };
|
---|
| 59 |
|
---|
| 60 | while (bIterCount.hasNext()) {
|
---|
| 61 | Bid tmpBid = bIterCount.next();
|
---|
| 62 | double utility;
|
---|
| 63 | try {
|
---|
| 64 | utility = utilitySpace.getUtility(tmpBid);
|
---|
| 65 | // exclude bids with utility < MIN_ALLOWED_UTILITY
|
---|
| 66 | if ((utility > 1.0) && (utility > 0.9))
|
---|
| 67 | nrBids[0]++;
|
---|
| 68 | else if ((utility <= 0.9) && (utility > 0.8))
|
---|
| 69 | nrBids[1]++;
|
---|
| 70 | else if ((utility <= 0.8) && (utility > 0.7))
|
---|
| 71 | nrBids[2]++;
|
---|
| 72 | else if ((utility <= 0.7) && (utility > 0.6))
|
---|
| 73 | nrBids[3]++;
|
---|
| 74 | else if (utility >= MIN_ALLOWED_UTILITY)
|
---|
| 75 | nrBids[4]++;
|
---|
| 76 | } catch (Exception e) {
|
---|
| 77 | e.printStackTrace();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | try {
|
---|
| 81 | Thread.sleep(1000);
|
---|
| 82 | } catch (Exception e) {
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | double arrayBidCount = 0;
|
---|
| 86 | int iMin = 0;
|
---|
| 87 |
|
---|
| 88 | do {
|
---|
| 89 | arrayBidCount = nrBids[iMin];
|
---|
| 90 | iMin++;
|
---|
| 91 | } while ((arrayBidCount == 0) && (iMin < 5));
|
---|
| 92 |
|
---|
| 93 | // initialize left bids
|
---|
| 94 | BidIterator bIter = new BidIterator(utilitySpace.getDomain());
|
---|
| 95 | leftBids = new ArrayList<Bid>();
|
---|
| 96 |
|
---|
| 97 | while (bIter.hasNext()) {
|
---|
| 98 | Bid tmpBid = bIter.next();
|
---|
| 99 | try {
|
---|
| 100 | // exclude bids with utility < MIN_ALLOWED_UTILITY
|
---|
| 101 | if (utilitySpace.getUtility(tmpBid) >= 0.9 - 0.1 * iMin)
|
---|
| 102 | leftBids.add(tmpBid);
|
---|
| 103 | } catch (Exception e) {
|
---|
| 104 | e.printStackTrace();
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | Collections.sort(leftBids,
|
---|
| 108 | new ReverseBidComparator((AdditiveUtilitySpace) utilitySpace));
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /** Receive the opponent's bid. */
|
---|
| 112 | @Override
|
---|
| 113 | public void ReceiveMessage(Action opponentAction) {
|
---|
| 114 | lastOponentAction = opponentAction;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /** Choose action to present to the opponent. */
|
---|
| 118 | @Override
|
---|
| 119 | public Action chooseAction() {
|
---|
| 120 | Action action = null;
|
---|
| 121 | Bid opponentBid = null;
|
---|
| 122 | try {
|
---|
| 123 | switch (getActionType(lastOponentAction)) {
|
---|
| 124 | case OFFER:
|
---|
| 125 | int timeCase; // the curent time interval id for cameleonic
|
---|
| 126 | // behaviour
|
---|
| 127 | elapsedTimeNorm = timeline.getTime(); // between 0 .. 1
|
---|
| 128 |
|
---|
| 129 | if (elapsedTimeNorm < 0.85)
|
---|
| 130 | timeCase = 0;
|
---|
| 131 | else if (elapsedTimeNorm < 0.95)
|
---|
| 132 | timeCase = 1;
|
---|
| 133 | else
|
---|
| 134 | timeCase = 2;
|
---|
| 135 |
|
---|
| 136 | opponentBid = ((Offer) lastOponentAction).getBid();
|
---|
| 137 |
|
---|
| 138 | // receiveMessage beliefs
|
---|
| 139 | opponentModel.updateBeliefs(opponentBid);
|
---|
| 140 |
|
---|
| 141 | if (myLastAction != null) {
|
---|
| 142 | // check if the opponent offer is acceptable
|
---|
| 143 | if (utilitySpace.getUtility(opponentBid)
|
---|
| 144 | * 1.03 >= utilitySpace.getUtility(
|
---|
| 145 | ((Offer) myLastAction).getBid())) {
|
---|
| 146 | action = new Accept(getAgentID(), opponentBid);
|
---|
| 147 | } else {
|
---|
| 148 | Bid nextBid = getNextBid(timeCase);
|
---|
| 149 | action = new Offer(getAgentID(), nextBid);
|
---|
| 150 |
|
---|
| 151 | // check if the opponent offer utility is greater than
|
---|
| 152 | // next bid
|
---|
| 153 | if (utilitySpace.getUtility(opponentBid) > utilitySpace
|
---|
| 154 | .getUtility(nextBid)) {
|
---|
| 155 | action = new Accept(getAgentID(), opponentBid);
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
| 158 | } else {
|
---|
| 159 | // opponent begins and this is my first action check if
|
---|
| 160 | // opponent's offer is acceptable
|
---|
| 161 | if (utilitySpace.getUtility(opponentBid) == utilitySpace
|
---|
| 162 | .getUtility(utilitySpace.getMaxUtilityBid())) {
|
---|
| 163 | action = new Accept(getAgentID(), opponentBid);
|
---|
| 164 | break;
|
---|
| 165 | }
|
---|
| 166 | // this is the first offer of this node this bid have
|
---|
| 167 | // maximum utility
|
---|
| 168 | action = initialOffer();
|
---|
| 169 | }
|
---|
| 170 | break;
|
---|
| 171 | case ACCEPT:
|
---|
| 172 | case BREAKOFF:
|
---|
| 173 | // Nothing to do in this case
|
---|
| 174 | break;
|
---|
| 175 | default: // normally occurs when action type is START
|
---|
| 176 | // verify if is agent's first offer
|
---|
| 177 | if (myLastAction == null) {
|
---|
| 178 | // is the first offer of this node this bid have maximum
|
---|
| 179 | // utility
|
---|
| 180 | action = initialOffer();
|
---|
| 181 | } else {
|
---|
| 182 | action = myLastAction;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | } catch (Exception e) {
|
---|
| 186 | e.printStackTrace();
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | myLastAction = action;
|
---|
| 190 |
|
---|
| 191 | return action;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | private Action initialOffer() throws Exception {
|
---|
| 195 | // proposes the offer with maximum possible utility
|
---|
| 196 | return new Offer(getAgentID(), utilitySpace.getMaxUtilityBid());
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | private ACTIONTYPE getActionType(Action lAction) {
|
---|
| 200 | ACTIONTYPE lActionType = ACTIONTYPE.START;
|
---|
| 201 | if (lAction instanceof Offer)
|
---|
| 202 | lActionType = ACTIONTYPE.OFFER;
|
---|
| 203 | else if (lAction instanceof Accept)
|
---|
| 204 | lActionType = ACTIONTYPE.ACCEPT;
|
---|
| 205 | else if (lAction instanceof EndNegotiation)
|
---|
| 206 | lActionType = ACTIONTYPE.BREAKOFF;
|
---|
| 207 | return lActionType;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | private Bid getNextBid(int pTimeCase) throws Exception {
|
---|
| 211 | switch (pTimeCase) {
|
---|
| 212 | case 0:
|
---|
| 213 | return getSmartBid(pTimeCase);
|
---|
| 214 | case 1:
|
---|
| 215 | return getSmartBid(1);
|
---|
| 216 | default:
|
---|
| 217 | return getSmartBid(2);
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | @Override
|
---|
| 222 | public String getName() {
|
---|
| 223 | return "AgentFSEGA";
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | private Bid getSmartBid(int pTimeCase) {
|
---|
| 227 | double currentOpponentUtility = 0.0;
|
---|
| 228 | double lastOpponentUtility = 0.0;
|
---|
| 229 |
|
---|
| 230 | double myBestUtil; // utility for remained best bid
|
---|
| 231 | double myNextUtility; // utility for next bid
|
---|
| 232 |
|
---|
| 233 | Bid nextBest = null; // best for me and opponent
|
---|
| 234 | Bid theBest = null; // the best for me, top of the ordered list
|
---|
| 235 |
|
---|
| 236 | // get first entry
|
---|
| 237 | if (leftBids.size() > 0) {
|
---|
| 238 | theBest = leftBids.get(0);
|
---|
| 239 |
|
---|
| 240 | try {
|
---|
| 241 | myBestUtil = utilitySpace.getUtility(theBest);
|
---|
| 242 | } catch (Exception e) {
|
---|
| 243 | myBestUtil = 1;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | nextBest = theBest;
|
---|
| 247 | } else {
|
---|
| 248 | return ((Offer) myLastAction).getBid();
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | Bid lNext = null;
|
---|
| 252 |
|
---|
| 253 | double minUtilAllowed = Math
|
---|
| 254 | .max(0.98 * Math.exp(Math.log(0.52) * elapsedTimeNorm), 0.5);
|
---|
| 255 | double minArrayUtility = 0;
|
---|
| 256 |
|
---|
| 257 | try {
|
---|
| 258 | minArrayUtility = utilitySpace
|
---|
| 259 | .getUtility(leftBids.get(leftBids.size() - 1));
|
---|
| 260 | } catch (Exception e) {
|
---|
| 261 | e.printStackTrace();
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | // !!! left bids receiveMessage
|
---|
| 265 | if (((minArrayUtility > minUtilAllowed + SIGMA)
|
---|
| 266 | || (minArrayUtility > (myBestUtil - SIGMA)))) {
|
---|
| 267 | BidIterator bIter = new BidIterator(utilitySpace.getDomain());
|
---|
| 268 |
|
---|
| 269 | for (Bid tmpBid = bIter.next(); bIter
|
---|
| 270 | .hasNext(); tmpBid = bIter.next()) {
|
---|
| 271 | try {
|
---|
| 272 | double tmpBidUtil = utilitySpace.getUtility(tmpBid);
|
---|
| 273 | if ((tmpBidUtil > MIN_ALLOWED_UTILITY)
|
---|
| 274 | && (tmpBidUtil < minArrayUtility)
|
---|
| 275 | && (tmpBidUtil > Math.min(minUtilAllowed,
|
---|
| 276 | myBestUtil) - 0.1))
|
---|
| 277 | leftBids.add(tmpBid);
|
---|
| 278 | } catch (Exception e) {
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | Collections.sort(leftBids, new ReverseBidComparator(
|
---|
| 282 | (AdditiveUtilitySpace) utilitySpace));
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | // get second entry in last bids
|
---|
| 286 | if (leftBids.size() > 1) {
|
---|
| 287 | lNext = leftBids.get(1);
|
---|
| 288 | } else {
|
---|
| 289 | // proposedBids.add(nextBest);
|
---|
| 290 | leftBids.remove(nextBest);
|
---|
| 291 | return nextBest;
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | try {
|
---|
| 295 | myNextUtility = utilitySpace.getUtility(lNext);
|
---|
| 296 | } catch (Exception e) {
|
---|
| 297 | myNextUtility = 0;
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | double lowerAcceptableUtilLimit;
|
---|
| 301 |
|
---|
| 302 | // if time case is 2 -> make concession
|
---|
| 303 | if (pTimeCase == 2) {
|
---|
| 304 | lowerAcceptableUtilLimit = myBestUtil - (Math
|
---|
| 305 | .exp(Math.log(SIGMA_MAX) / (0.05 * timeline.getTotalTime()))
|
---|
| 306 | * elapsedTimeNorm);
|
---|
| 307 | } else {
|
---|
| 308 | // minimum allowed utility for me at this time
|
---|
| 309 | if (pTimeCase == 0)
|
---|
| 310 | lowerAcceptableUtilLimit = Math.max(myBestUtil - SIGMA,
|
---|
| 311 | minUtilAllowed);
|
---|
| 312 | else
|
---|
| 313 | lowerAcceptableUtilLimit = Math.min(myBestUtil - SIGMA,
|
---|
| 314 | minUtilAllowed);
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | // eliminate first bid + next bid
|
---|
| 318 | java.util.Iterator<Bid> lbi = leftBids.iterator();
|
---|
| 319 | if (leftBids.size() > 1) {
|
---|
| 320 | lbi.next(); // first bid
|
---|
| 321 | lbi.next();
|
---|
| 322 | } else {
|
---|
| 323 | return ((Offer) myLastAction).getBid();
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | // get a bid in interval (max_util - SIGMA, max_util]
|
---|
| 327 | while ((myNextUtility > lowerAcceptableUtilLimit)
|
---|
| 328 | && (myNextUtility <= minUtilAllowed)) {
|
---|
| 329 | // check (my next util) < (last opponent bid's utility for me)
|
---|
| 330 | // in this case, offer previous bid
|
---|
| 331 | // Cristi Litan 19.03.2010
|
---|
| 332 | if (pTimeCase == 0) // use behaviour 0
|
---|
| 333 | {
|
---|
| 334 | try // catch getUtility exceptions
|
---|
| 335 | {
|
---|
| 336 | // do not offer bids with utility smaller than that gived by
|
---|
| 337 | // opponent in time case 0
|
---|
| 338 | if (myNextUtility < utilitySpace
|
---|
| 339 | .getUtility(((Offer) lastOponentAction).getBid())) {
|
---|
| 340 | nextBest = ((Offer) myLastAction).getBid();
|
---|
| 341 | break;
|
---|
| 342 | }
|
---|
| 343 | } catch (Exception e) { /* do nothing - ignore */
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | try {
|
---|
| 348 | currentOpponentUtility = opponentModel
|
---|
| 349 | .getExpectedUtility(lNext);
|
---|
| 350 | } catch (Exception e) {
|
---|
| 351 | currentOpponentUtility = 0;
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | if (currentOpponentUtility > lastOpponentUtility) {
|
---|
| 355 | lastOpponentUtility = currentOpponentUtility;
|
---|
| 356 | nextBest = lNext;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | if (lbi.hasNext()) {
|
---|
| 360 | lNext = lbi.next();
|
---|
| 361 |
|
---|
| 362 | // get my utility for next possible bid
|
---|
| 363 | try {
|
---|
| 364 | myNextUtility = utilitySpace.getUtility(lNext);
|
---|
| 365 | } catch (Exception e) {
|
---|
| 366 | myNextUtility = 0;
|
---|
| 367 | }
|
---|
| 368 | } else
|
---|
| 369 | // log("no other in possible bids");
|
---|
| 370 | break;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | try {
|
---|
| 374 | if (utilitySpace.getUtility(nextBest) <= minUtilAllowed) {
|
---|
| 375 | return ((Offer) myLastAction).getBid();
|
---|
| 376 | }
|
---|
| 377 | } catch (Exception e) {
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | leftBids.remove(nextBest);
|
---|
| 381 |
|
---|
| 382 | return nextBest;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | @Override
|
---|
| 386 | public SupportedNegotiationSetting getSupportedNegotiationSetting() {
|
---|
| 387 | return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | @Override
|
---|
| 391 | public String getDescription() {
|
---|
| 392 | return "ANAC2010";
|
---|
| 393 | }
|
---|
[1] | 394 | } |
---|