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

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

Change BilateralProtocol loop to avoid busy wait; note that this fixes only a part of the busy wait problem.

Package structure now in line with latest Acumex discussions.

Pinpointed error avoidance in Agent.

File size: 2.6 KB
RevLine 
[330]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;
[337]10import bargainingchips.actions.FinalAccept;
[330]11import bargainingchips.actions.Offer;
12import bargainingchips.actions.OfferBy;
[337]13import bargainingchips.actions.PreAccept;
[340]14import bargainingchips.messaging.coordination.CoordinationMessage;
15import bargainingchips.messaging.status.StatusMessage;
[330]16import bargainingchips.outcomes.Outcome;
17import bargainingchips.utilityfunctions.UtilityFunction;
18
19/**
20 * Basic agent, by Tim Baarslag
21 */
22public 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).
[337]45 if (lastReceivedOffer.isPreAccept())
46 return new FinalAccept(lastReceivedOffer);
[330]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)
[337]56 return new PreAccept(lastReceivedOffer);
[330]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();
[337]71 return outcomeSpace.getMaxBidPossible(u);
[330]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
[337]92 /*
[330]93 * Messaging with the coordinator can happen below
94 */
95
96 @Override
97 protected StatusMessage sendStatusMessage()
98 {
99 return null;
100 }
[337]101
102 @Override
103 protected void receiveCoordinationMessage(CoordinationMessage cpoll) {
104 // TODO Auto-generated method stub
105
106 }
[330]107}
Note: See TracBrowser for help on using the repository browser.