1 | package bargainingchips.players;
|
---|
2 |
|
---|
3 | import java.util.concurrent.BlockingQueue;
|
---|
4 | import java.util.concurrent.LinkedBlockingQueue;
|
---|
5 |
|
---|
6 | import bargainingchips.Bundle;
|
---|
7 | import bargainingchips.NegotiationContext;
|
---|
8 | import bargainingchips.OutcomeSpace;
|
---|
9 | import bargainingchips.actions.Bid;
|
---|
10 | import bargainingchips.actions.FinalAccept;
|
---|
11 | import bargainingchips.actions.Offer;
|
---|
12 | import bargainingchips.actions.OfferBy;
|
---|
13 | import bargainingchips.actions.PreAccept;
|
---|
14 | import bargainingchips.outcomes.Outcome;
|
---|
15 | import bargainingchips.utilityfunctions.UtilityFunction;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Basic agent, by Tim Baarslag
|
---|
19 | */
|
---|
20 | public 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 | }
|
---|