package bargainingchips.players; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import bargainingchips.Bundle; import bargainingchips.NegotiationContext; import bargainingchips.OutcomeSpace; import bargainingchips.actions.Bid; import bargainingchips.actions.FinalAccept; import bargainingchips.actions.Offer; import bargainingchips.actions.OfferBy; import bargainingchips.actions.PreAccept; import bargainingchips.outcomes.Outcome; import bargainingchips.utilityfunctions.UtilityFunction; /** * Basic agent, by Tim Baarslag */ public class BasicAgent extends Agent { private Offer lastReceivedOffer = null; /** * For sellers, dummy coordinator queues are created but are never linked up */ public BasicAgent(String name, UtilityFunction u, NegotiationContext nc, BlockingQueue in, BlockingQueue out) { super(name, u, nc, in, out, new LinkedBlockingQueue(), new LinkedBlockingQueue()); } @Override protected Offer sendOffer() { // Nothing received yet if (lastReceivedOffer == null) return new Bid(getNextBid()); // Our last bid got accepted. We are also accepting (and we should notify the coordinator). if (lastReceivedOffer.isPreAccept()) return new FinalAccept(lastReceivedOffer); Bundle lastReceivedBid = lastReceivedOffer.getBundle(); Bundle nextBid = getNextBid(); double lastUtil = lastReceivedBid != null ? u.getUtility(lastReceivedBid) : 0; double nextUtil = nextBid != null ? u.getUtility(nextBid) : 0; // Accept if (nextUtil <= lastUtil) return new PreAccept(lastReceivedOffer); // Counter offer based actions else { return new Bid(nextBid); } } /** * Get the next bid we should do */ protected Bundle getNextBid() { OutcomeSpace outcomeSpace = negotiationContext.getOutcomeSpace(); return outcomeSpace.getMaxBidPossible(u); } @Override protected void receiveOffer(Offer o) { lastReceivedOffer = o; } @Override protected void receiveOutcome(Outcome outcome) { } @Override protected Offer sendOpeningOffer() { return null; } /* * Messaging with the coordinator can happen below */ @Override protected StatusMessage sendStatusMessage() { return null; } @Override protected void receiveCoordinationMessage(CoordinationMessage cpoll) { // TODO Auto-generated method stub } }