source: src/main/java/agents/ai2014/group8/Group8.java@ 127

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

Initial import : Genius 9.0.0

File size: 6.3 KB
Line 
1package agents.ai2014.group8;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.actions.Accept;
9import genius.core.actions.Action;
10import genius.core.actions.Inform;
11import genius.core.actions.Offer;
12import genius.core.issue.Issue;
13import genius.core.parties.AbstractNegotiationParty;
14import genius.core.parties.NegotiationInfo;
15
16/**
17 * This is your negotiation party.
18 */
19public class Group8 extends AbstractNegotiationParty {
20
21 // utility value above which bids will be accepted
22 private double acceptanceValue;
23
24 // number of rounds available for negotiation
25 private double totalRounds;
26
27 // number of rounds of negotiation completed
28 private int roundCounter;
29
30 private static final double INITIALACCEPTVALUE = 0.5;
31
32 // most recent bid
33 private Bid mostRecentBid;
34
35 // most recent bidder
36 private AgentID mostRecentBidder;
37
38 // list of opponents modeled by opponentModel class
39 private List<OpponentModel> opponents;
40
41 @Override
42 public void init(NegotiationInfo info) {
43 super.init(info);
44
45 // get total number of rounds available from the environment
46 this.totalRounds = timeline.getTotalTime() - 1;
47
48 this.roundCounter = 0;
49
50 }
51
52 /**
53 * Each round this method gets called and ask you to accept or offer. The
54 * first party in the first round is a bit different, it can only propose an
55 * offer.
56 *
57 * @param validActions
58 * Either a list containing both accept and offer or only offer.
59 * @return The chosen action.
60 */
61 @Override
62 public Action chooseAction(List<Class<? extends Action>> validActions) {
63 this.roundCounter++;
64
65 this.acceptanceValue = 0.99 + 1 - Math.pow(Math.pow(1.9, 1 / this.totalRounds),
66 Math.pow(INITIALACCEPTVALUE, (this.totalRounds) / this.roundCounter) * (this.roundCounter - 1));
67
68 // first bid - offer a bid with high utility value for self
69 if (!validActions.contains(Accept.class)) {
70 Bid firstBid = this.generateHigherUtilityBid(this.acceptanceValue).get(0);
71
72 return new Offer(getPartyId(), firstBid);
73 }
74 // choosing action after a bid has been made
75 else {
76 // evaluate the utility of most recent bid
77 double utilityOfMostRecentBid;
78
79 try {
80 utilityOfMostRecentBid = this.utilitySpace.getUtility(this.mostRecentBid);
81 } catch (Exception e) {
82 utilityOfMostRecentBid = 0;
83 e.printStackTrace();
84 }
85
86 // accept offer if utility is higher than our acceptance value
87 if (utilityOfMostRecentBid >= this.acceptanceValue) {
88 return new Accept(getPartyId(), mostRecentBid);
89 }
90 // make counter offer
91 else {
92 // generate some high utility bids
93 List<Bid> possibleBids = generateHigherUtilityBid(this.acceptanceValue);
94
95 // when too few rounds have passed, offer a random high utility
96 // bid
97 if (this.roundCounter < 5) {
98 return new Offer(getPartyId(), possibleBids.get(0));
99 }
100 // among high utility bids choose one that has best utility for
101 // next agent
102 else {
103 // find bid with highest utility for next agent
104 double maxUtilityForOpponent = 0.0;
105 Bid bestBidForNextAgent = null;
106
107 OpponentModel nextAgent = getNextAgentModel();
108
109 for (Bid bid : possibleBids) {
110 double bidUtility = nextAgent.EvaluateBidUtility(bid);
111
112 if (bidUtility > maxUtilityForOpponent) {
113 bestBidForNextAgent = bid;
114 maxUtilityForOpponent = bidUtility;
115 }
116 }
117
118 return new Offer(getPartyId(), bestBidForNextAgent);
119 }
120 }
121 }
122 }
123
124 /**
125 * find next agent among list of opponents
126 *
127 * @return model of next agent
128 */
129 private OpponentModel getNextAgentModel() {
130 OpponentModel nextAgent = null;
131
132 for (OpponentModel opponent : this.opponents) {
133 if (opponent.agent.equals(this.mostRecentBidder)) {
134 int indexOfPreviousBidder = this.opponents.indexOf(mostRecentBidder);
135
136 int indexOfNextAgent = (indexOfPreviousBidder + 1) % this.opponents.size();
137
138 nextAgent = this.opponents.get(indexOfNextAgent);
139 break;
140 }
141 }
142 return nextAgent;
143 }
144
145 /**
146 * All offers proposed by the other parties will be received as a message.
147 * You can use this information to your advantage, for example to predict
148 * their utility.
149 *
150 * @param sender
151 * The party that did the action.
152 * @param action
153 * The action that party did.
154 */
155 @Override
156 public void receiveMessage(AgentID sender, Action action) {
157 // handle first message from framework to initialize list of opponents
158 if (sender == null) {
159 super.receiveMessage(sender, action);
160
161 // get number of agents in the negotiation
162 Inform agentsInformation = (Inform) action;
163 int numberOfAgents = (Integer) agentsInformation.getValue();
164
165 // initialize list of other parties
166 if (numberOfAgents > 1) {
167 this.opponents = new ArrayList<OpponentModel>();
168 }
169 return;
170 }
171
172 this.mostRecentBidder = sender;
173
174 List<Issue> issues = getUtilitySpace().getDomain().getIssues();
175 // add sender agent to list of other parties if not present
176 if (this.opponents.contains(new OpponentModel(sender, issues)) == false) {
177 OpponentModel newOpponent = new OpponentModel(sender, issues);
178 this.opponents.add(newOpponent);
179 }
180
181 // store sender agent bid in its model among list of opponents
182 if ((action instanceof Offer)) {
183 mostRecentBid = ((Offer) action).getBid();
184
185 OpponentModel senderModel = null;
186
187 for (OpponentModel opponent : this.opponents) {
188 if (opponent.agent == sender) {
189 senderModel = opponent;
190 break;
191 }
192 }
193
194 if (senderModel != null) {
195 try {
196 senderModel.AddBid(mostRecentBid);
197 } catch (Exception e) {
198 e.printStackTrace();
199 return;
200 }
201 }
202 }
203 }
204
205 /**
206 * generates random bids which have higher utility than the parameter
207 *
208 * @param utilityValue
209 * lower bound of utility value for randomly generated bids
210 */
211 private List<Bid> generateHigherUtilityBid(double utilityValue) {
212 Bid randomBid;
213 List<Bid> randomBidsList = new ArrayList<Bid>();
214
215 double util;
216 do {
217 randomBid = generateRandomBid();
218
219 try {
220 util = utilitySpace.getUtility(randomBid);
221 } catch (Exception e) {
222 util = 0.0;
223 }
224
225 if (util > utilityValue && util < (utilityValue + 0.05)) {
226 randomBidsList.add(randomBid);
227 }
228 } while (randomBidsList.size() < 10);
229
230 return randomBidsList;
231 }
232
233 protected AgentID partyId = new AgentID("Group 8");
234
235 @Override
236 public String getDescription() {
237 return "ai2014 group8";
238 }
239
240}
Note: See TracBrowser for help on using the repository browser.