[188] | 1 | package bilateralexamples;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.AgentID;
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.actions.Accept;
|
---|
| 8 | import genius.core.actions.Action;
|
---|
| 9 | import genius.core.actions.EndNegotiation;
|
---|
| 10 | import genius.core.actions.Offer;
|
---|
| 11 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 12 | import genius.core.parties.NegotiationInfo;
|
---|
| 13 | import genius.core.utility.AbstractUtilitySpace;
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | * A simple example agent that makes random bids above a minimum target utility.
|
---|
| 17 | *
|
---|
| 18 | * @author Tim Baarslag
|
---|
| 19 | */
|
---|
| 20 | public class RandomBidderExample extends AbstractNegotiationParty
|
---|
| 21 | {
|
---|
[198] | 22 | private static double MINIMUM_TARGET = 0.8;
|
---|
[188] | 23 | private Bid lastOffer;
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * Initializes a new instance of the agent.
|
---|
| 27 | */
|
---|
| 28 | @Override
|
---|
| 29 | public void init(NegotiationInfo info)
|
---|
| 30 | {
|
---|
| 31 | super.init(info);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * Makes a random offer above the minimum utility target
|
---|
[234] | 36 | * Accepts everything above the reservation value at the end of the negotiation; or breaks off otherwise.
|
---|
[188] | 37 | */
|
---|
| 38 | @Override
|
---|
| 39 | public Action chooseAction(List<Class<? extends Action>> possibleActions)
|
---|
| 40 | {
|
---|
| 41 | // Check for acceptance if we have received an offer
|
---|
| 42 | if (lastOffer != null)
|
---|
[234] | 43 | if (timeline.getTime() >= 0.9)
|
---|
[188] | 44 | if (getUtility(lastOffer) >= utilitySpace.getReservationValue())
|
---|
| 45 | return new Accept(getPartyId(), lastOffer);
|
---|
| 46 | else
|
---|
| 47 | return new EndNegotiation(getPartyId());
|
---|
| 48 |
|
---|
| 49 | // Otherwise, send out a random offer above the target utility
|
---|
| 50 | return new Offer(getPartyId(), generateRandomBidAboveTarget());
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | private Bid generateRandomBidAboveTarget()
|
---|
| 54 | {
|
---|
| 55 | Bid randomBid;
|
---|
| 56 | double util;
|
---|
| 57 | int i = 0;
|
---|
| 58 | // try 100 times to find a bid under the target utility
|
---|
| 59 | do
|
---|
| 60 | {
|
---|
| 61 | randomBid = generateRandomBid();
|
---|
| 62 | util = utilitySpace.getUtility(randomBid);
|
---|
| 63 | }
|
---|
| 64 | while (util < MINIMUM_TARGET && i++ < 100);
|
---|
| 65 | return randomBid;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * Remembers the offers received by the opponent.
|
---|
| 70 | */
|
---|
| 71 | @Override
|
---|
| 72 | public void receiveMessage(AgentID sender, Action action)
|
---|
| 73 | {
|
---|
| 74 | if (action instanceof Offer)
|
---|
| 75 | {
|
---|
| 76 | lastOffer = ((Offer) action).getBid();
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | @Override
|
---|
| 81 | public String getDescription()
|
---|
| 82 | {
|
---|
| 83 | return "Places random bids >= " + MINIMUM_TARGET;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * This stub can be expanded to deal with preference uncertainty in a more sophisticated way than the default behavior.
|
---|
| 88 | */
|
---|
| 89 | @Override
|
---|
| 90 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
| 91 | {
|
---|
| 92 | return super.estimateUtilitySpace();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | }
|
---|