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