source: src/main/java/parties/in4010/q12015/group10/Group10.java@ 126

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

Initial import : Genius 9.0.0

File size: 8.1 KB
Line 
1package parties.in4010.q12015.group10;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.Deadline;
9import genius.core.actions.Accept;
10import genius.core.actions.Action;
11import genius.core.actions.DefaultAction;
12import genius.core.actions.Inform;
13import genius.core.actions.Offer;
14import genius.core.bidding.BidDetails;
15import genius.core.parties.AbstractNegotiationParty;
16import genius.core.parties.NegotiationInfo;
17import genius.core.utility.AdditiveUtilitySpace;
18
19/**
20 * Negotiation party
21 */
22public class Group10 extends AbstractNegotiationParty {
23
24 private int numberOfOpponents; // Number of opponents in this session. The
25 // protocol tells us this
26 private Opponent[] opponents; // Array of opponents. Initially empty (until
27 // we know how many opponents there are)
28 private List<AgentID> opponentAgentIDList = new ArrayList<AgentID>(); // List
29 // of
30 // opponent
31 // AgentIDs.
32 // Not
33 // the
34 // actual
35 // opponents,
36 // just
37 // their
38 // IDs.
39 private BidDetails detailsOfLatestBidOnTable; // Details of latest bid.
40 // Either made by us, or by
41 // the opponent.
42 private Deadline deadLine;
43
44 private OpponentStrategyEstimator myOpponentStrategyEstimator;
45
46 /**
47 * Initialization. This adds to the existing initialization so we can
48 * initialize our own variables, too.
49 */
50 @Override
51 public void init(NegotiationInfo info) {
52 // Original (hidden) initialization
53 super.init(info);
54
55 // Own initialization code
56 deadLine = info.getDeadline();
57 }
58
59 // Here we create and initialize opponents. Note that this is called only
60 // after the protocol
61 // informs us about how many agents take part in this negotiation.
62 private void initOpponents() {
63 // Make array of objects
64 opponents = new Opponent[numberOfOpponents];
65
66 // Initialize each of them by calling their constructors
67 for (int opponentNumber = 0; opponentNumber < numberOfOpponents; opponentNumber++) {
68 opponents[opponentNumber] = new Opponent(opponentNumber, (AdditiveUtilitySpace) utilitySpace, deadLine);
69 }
70 }
71
72 /**
73 * All protocol information and opponent actions will be received as a
74 * message. This function determines if the data comes from the protocol or
75 * an opponent, and starts the appropriate function to process it.
76 */
77 @Override
78 public void receiveMessage(AgentID sender, Action action) {
79 super.receiveMessage(sender, action);
80
81 // Determine who is sending something. Not sure this is the best way to
82 // go.
83 if (sender == null) {
84 // We are receiving a message from the protocol. Go Process it.
85 receiveProtocolMessage(action);
86 } else {
87 // We are receiving a message from an agent. Go Process it.
88 receiveOpponentMessage(action.getAgent(), action);
89 }
90
91 }
92
93 /**
94 * All protocol information is processed here
95 */
96
97 // This runs when the ReceiveMessage function detects that the Protocol
98 // sends something
99 private void receiveProtocolMessage(Action action) {
100 // Check that the action is of the type inform
101 if (action instanceof Inform) {
102 // Explicitly make it of type inform
103 Inform InformMessage = (Inform) action;
104
105 // Get the name of the inform message
106 String messageName = InformMessage.getName();
107
108 // For each message we can expect, define what to do
109 switch (messageName) {
110 case "NumberOfAgents":
111 // If we get information about the number of agents, store it,
112 // and initialize the agents.
113 numberOfOpponents = (int) InformMessage.getValue() - 1; // Don't
114 // count
115 // myself
116 initOpponents(); // Run the opponent initialization.
117 break;
118 default:
119 }
120 }
121 }
122
123 /**
124 * All offers proposed by the other parties will be received as a message.
125 * It is processed here.
126 */
127
128 // This runs when the ReceiveMessage function detects that an opponent sends
129 // something
130 private void receiveOpponentMessage(AgentID agentID, Action action) {
131
132 double timeNow = timeline.getTime();
133
134 int opponentNumber; // Soon to be found numeric value associated with
135 // the agent that sends a message
136
137 // See if we encountered this agent before
138 if (opponentAgentIDList.contains(agentID)) {
139 // Opponent has been seen befor, his number is:
140 opponentNumber = opponentAgentIDList.indexOf(agentID);
141 } else {// We see this agent for the first time.
142
143 // The opponents are numbered in the order we first encounter them.
144 // At first, agentIDList has length 0, so the first opponent will
145 // get
146 // number 0. The next opponent will get number 1, and son on.
147 opponentNumber = opponentAgentIDList.size();
148
149 opponentAgentIDList.add(agentID); // Add it to the list of agents
150 opponents[opponentNumber].setAgentID(agentID);// Store the ID in the
151 // appropriate
152 // object.
153 }
154
155 // Now that we know the opponent number, we can check out what he's
156 // doing, such as offering or bidding
157
158 if (action instanceof Offer) {
159 // The opponent has made a new offer.
160 Bid latestBidOnTable = DefaultAction.getBidFromAction(action); // Get
161 // the
162 // bid that
163 // he
164 // offered.
165 double UndiscountedUtilofLatestBid = getUtility(latestBidOnTable); // Find
166 // the
167 // corresponding
168 // utility
169 // for
170 // group
171 // 10
172 detailsOfLatestBidOnTable = new BidDetails(latestBidOnTable, UndiscountedUtilofLatestBid, timeNow); // Combine
173 // the
174 // offer,
175 // utility
176 // and
177 // time
178 // in
179 // the
180 // BidDetailsObject.
181
182 // Store the details of which offer the opponent is making
183 opponents[opponentNumber].StoreOfferedBid(detailsOfLatestBidOnTable);
184 } else if (action instanceof Accept) {
185 // The opponent is accepting the bid that is currently on the table
186 opponents[opponentNumber].StoreAcceptedBid(detailsOfLatestBidOnTable); // Store
187 // the
188 // details
189 // of
190 // which
191 // offer
192 // he
193 // is
194 // accepting
195 }
196
197 }
198
199 /**
200 * Each round this method gets called and ask you to accept or offer. The
201 * first party in the first round is a bit different, it can only propose an
202 * offer.
203 */
204 @Override
205 public Action chooseAction(java.util.List<Class<? extends Action>> validActions) {
206 OpponentModelEstimator.updateAllModels(opponents, timeline);
207
208 Bid potentialBid = OfferingStrategy.createPotentialBid((AdditiveUtilitySpace) utilitySpace, opponents, timeline,
209 deadLine);
210
211 // Create a BidDetails object of our potential bid
212 double timeNow = timeline.getTime(); // The current time
213 double UndiscountedUtilofPotentialBid = getUtility(potentialBid); // Find
214 // the
215 // corresponding
216 // utility
217 // for
218 // group
219 // 10
220 BidDetails detailsOfPotentialBid = new BidDetails(potentialBid, UndiscountedUtilofPotentialBid, timeNow); // Combine
221 // the
222 // offer,
223 // utility
224 // and
225 // time
226 // in
227 // the
228 // BidDetailsObject.
229
230 // Based on the valid actions, potential and latest bid on the table,
231 // choose what to do.
232 Action chosenAction = AcceptanceStrategy.getAction(validActions, detailsOfPotentialBid,
233 detailsOfLatestBidOnTable, getPartyId());
234
235 // Return our decision to Genius
236 return chosenAction;
237
238 }
239
240 /**
241 * Description of our agent that appears in Genius
242 */
243
244 @Override
245 public String getDescription() {
246 return "Group10";
247 }
248
249}
Note: See TracBrowser for help on using the repository browser.