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