private Action proposeInitialBid() { Bid lBid = null; // Return (one of the) possible bid(s) with maximal utility. try { lBid = utilitySpace.getMaxUtilityBid(); } catch (Exception e) { e.printStackTrace(); } myLastBid = lBid; return new Offer(getAgentID(), lBid); }
public Action chooseAction() { Action lAction = null; ACTIONTYPE lActionType; Bid lOppntBid = null; lActionType = getActionType(messageOpponent); switch (lActionType) { case OFFER: // Offer received from opponent lOppntBid = ((Offer) messageOpponent).getBid(); if (myLastAction == null) // Other agent started, lets propose my initial bid. lAction = proposeInitialBid(); else { try { if (utilitySpace.getUtility(lOppntBid) >= (utilitySpace.getUtility(myLastBid)) - UTIlITYGAPSIZE) // Opponent bids equally, or outbids my previous bid, so lets accept. lAction = new Accept(getAgentID()); else // Propose counteroffer. Get next bid. try { lAction = proposeNextBid(lOppntBid); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } break; case ACCEPT: // Presumably, opponent accepted last bid, but let's check... case BREAKOFF: // nothing left to do. Negotiation ended, which should be checked by // Negotiator... break; default: // I am starting, but not sure whether Negotiator checks this, so // lets check also myLastAction... if (myLastAction == null) lAction = proposeInitialBid(); else // simply repeat last action lAction = myLastAction; break; } myLastAction = lAction; return lAction; }