source: src/test/java/bilateralexamples/RandomBidderExample.java@ 346

Last change on this file since 346 was 234, checked in by Tim Baarslag, 5 years ago

Screen size adjustment for higher resolution monitors

File size: 2.4 KB
Line 
1package bilateralexamples;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.EndNegotiation;
10import genius.core.actions.Offer;
11import genius.core.parties.AbstractNegotiationParty;
12import genius.core.parties.NegotiationInfo;
13import 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 */
20public class RandomBidderExample extends AbstractNegotiationParty
21{
22 private static double MINIMUM_TARGET = 0.8;
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
36 * Accepts everything above the reservation value at the end of the negotiation; or breaks off otherwise.
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)
43 if (timeline.getTime() >= 0.9)
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}
Note: See TracBrowser for help on using the repository browser.