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

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 2.7 KB
Line 
1package agents.nastyagent;
2
3import java.util.List;
4
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.HashMap;
8import java.util.Iterator;
9
10import genius.core.Agent;
11import genius.core.AgentID;
12import genius.core.Bid;
13import genius.core.BidIterator;
14import genius.core.actions.Action;
15import genius.core.actions.Offer;
16import genius.core.parties.NegotiationInfo;
17import genius.core.parties.NegotiationParty;
18import genius.core.persistent.PersistentDataContainer;
19import genius.core.protocol.DefaultMultilateralProtocol;
20import genius.core.protocol.StackedAlternatingOffersProtocol;
21import 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 */
36public 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}
Note: See TracBrowser for help on using the repository browser.