source: src/main/java/bargainingchips/players/BasicAgent.java@ 337

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

Added support for PreAccept and FinalAccept

File size: 2.5 KB
Line 
1package bargainingchips.players;
2
3import java.util.concurrent.BlockingQueue;
4import java.util.concurrent.LinkedBlockingQueue;
5
6import bargainingchips.Bundle;
7import bargainingchips.NegotiationContext;
8import bargainingchips.OutcomeSpace;
9import bargainingchips.actions.Bid;
10import bargainingchips.actions.FinalAccept;
11import bargainingchips.actions.Offer;
12import bargainingchips.actions.OfferBy;
13import bargainingchips.actions.PreAccept;
14import bargainingchips.outcomes.Outcome;
15import bargainingchips.utilityfunctions.UtilityFunction;
16
17/**
18 * Basic agent, by Tim Baarslag
19 */
20public class BasicAgent extends Agent
21{
22 private Offer lastReceivedOffer = null;
23
24 /**
25 * For sellers, dummy coordinator queues are created but are never linked up
26 */
27 public BasicAgent(String name, UtilityFunction u, NegotiationContext nc,
28 BlockingQueue<Offer> in, BlockingQueue<OfferBy> out)
29 {
30 super(name, u, nc, in, out,
31 new LinkedBlockingQueue<CoordinationMessage>(),
32 new LinkedBlockingQueue<StatusMessage>());
33 }
34
35 @Override
36 protected Offer sendOffer()
37 {
38 // Nothing received yet
39 if (lastReceivedOffer == null)
40 return new Bid(getNextBid());
41
42 // Our last bid got accepted. We are also accepting (and we should notify the coordinator).
43 if (lastReceivedOffer.isPreAccept())
44 return new FinalAccept(lastReceivedOffer);
45
46 Bundle lastReceivedBid = lastReceivedOffer.getBundle();
47 Bundle nextBid = getNextBid();
48
49 double lastUtil = lastReceivedBid != null ? u.getUtility(lastReceivedBid) : 0;
50 double nextUtil = nextBid != null ? u.getUtility(nextBid) : 0;
51
52 // Accept
53 if (nextUtil <= lastUtil)
54 return new PreAccept(lastReceivedOffer);
55 // Counter offer based actions
56 else
57 {
58 return new Bid(nextBid);
59 }
60
61 }
62
63 /**
64 * Get the next bid we should do
65 */
66 protected Bundle getNextBid()
67 {
68 OutcomeSpace outcomeSpace = negotiationContext.getOutcomeSpace();
69 return outcomeSpace.getMaxBidPossible(u);
70 }
71
72 @Override
73 protected void receiveOffer(Offer o)
74 {
75 lastReceivedOffer = o;
76 }
77
78 @Override
79 protected void receiveOutcome(Outcome outcome)
80 {
81 }
82
83
84 @Override
85 protected Offer sendOpeningOffer()
86 {
87 return null;
88 }
89
90 /*
91 * Messaging with the coordinator can happen below
92 */
93
94 @Override
95 protected StatusMessage sendStatusMessage()
96 {
97 return null;
98 }
99
100 @Override
101 protected void receiveCoordinationMessage(CoordinationMessage cpoll) {
102 // TODO Auto-generated method stub
103
104 }
105}
Note: See TracBrowser for help on using the repository browser.