1 | package agents.nastyagent;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.HashMap;
|
---|
8 | import java.util.Iterator;
|
---|
9 |
|
---|
10 | import genius.core.Agent;
|
---|
11 | import genius.core.AgentID;
|
---|
12 | import genius.core.Bid;
|
---|
13 | import genius.core.BidIterator;
|
---|
14 | import genius.core.actions.Action;
|
---|
15 | import genius.core.actions.Offer;
|
---|
16 | import genius.core.parties.NegotiationInfo;
|
---|
17 | import genius.core.parties.NegotiationParty;
|
---|
18 | import genius.core.persistent.PersistentDataContainer;
|
---|
19 | import genius.core.protocol.DefaultMultilateralProtocol;
|
---|
20 | import genius.core.protocol.StackedAlternatingOffersProtocol;
|
---|
21 | import genius.core.utility.AbstractUtilitySpace;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * NastyAgent is an agent with nasty behaviour: throws, returns silly actions,
|
---|
25 | * goes to sleep for long times. This is for testing if Genius is robust for
|
---|
26 | * such cases. If not nasty, this agent just places bids ordered by decreasing
|
---|
27 | * utility.
|
---|
28 | * <p>
|
---|
29 | * This is an abstract class without any actual nastyness. This is because
|
---|
30 | * {@link NegotiationParty} does not support parameterization anymore (unlike
|
---|
31 | * {@link Agent}. The actual (non-abstract) implementations do the nastyness.
|
---|
32 | *
|
---|
33 | * @author W.Pasman.
|
---|
34 | *
|
---|
35 | */
|
---|
36 | public abstract class NastyAgent implements NegotiationParty {
|
---|
37 |
|
---|
38 | ArrayList<Bid> bids = new ArrayList<Bid>(); // the bids that we MAY place.
|
---|
39 | Iterator<Bid> bidIterator; // next bid that we can place. Iterator over
|
---|
40 | // bids.
|
---|
41 | protected AgentID id;
|
---|
42 | protected Action lastReceivedAction;
|
---|
43 | protected boolean ended = false; // used to check if the nego was ended
|
---|
44 | // properly
|
---|
45 | protected PersistentDataContainer data;
|
---|
46 | protected AbstractUtilitySpace utilitySpace;
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void init(NegotiationInfo info)
|
---|
50 | {
|
---|
51 | this.id = info.getAgentID();
|
---|
52 | this.data = info.getPersistentData();
|
---|
53 | this.utilitySpace = info.getUtilitySpace();
|
---|
54 |
|
---|
55 | BidIterator biter = new BidIterator(utilitySpace.getDomain());
|
---|
56 | while (biter.hasNext())
|
---|
57 | bids.add(biter.next());
|
---|
58 | Collections.sort(bids, new BidComparator(utilitySpace));
|
---|
59 | bidIterator = bids.iterator();
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
65 | if (bidIterator.hasNext()) {
|
---|
66 | return new Offer(id, bidIterator.next());
|
---|
67 | }
|
---|
68 | return null;
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public void receiveMessage(AgentID sender, Action action) {
|
---|
73 | this.lastReceivedAction = action;
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public String getDescription() {
|
---|
78 | return this.getClass().getSimpleName();
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public Class<? extends DefaultMultilateralProtocol> getProtocol() {
|
---|
83 | return StackedAlternatingOffersProtocol.class;
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public HashMap<String, String> negotiationEnded(Bid acceptedBid) {
|
---|
88 | ended = true;
|
---|
89 | return null;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public boolean isEnded() {
|
---|
93 | return ended;
|
---|
94 | }
|
---|
95 |
|
---|
96 | }
|
---|