source: src/test/java/agents/nastyagent/NastyAgent.java@ 15

Last change on this file since 15 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.7 KB
Line 
1package agents.nastyagent;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.HashMap;
6import java.util.Iterator;
7import java.util.List;
8
9import genius.core.Agent;
10import genius.core.AgentID;
11import genius.core.Bid;
12import genius.core.BidIterator;
13import genius.core.actions.Action;
14import genius.core.actions.Offer;
15import genius.core.parties.NegotiationInfo;
16import genius.core.parties.NegotiationParty;
17import genius.core.persistent.PersistentDataContainer;
18import genius.core.protocol.DefaultMultilateralProtocol;
19import genius.core.protocol.StackedAlternatingOffersProtocol;
20import 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 */
35public 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}
Note: See TracBrowser for help on using the repository browser.