source: src/main/java/agents/ai2014/group4/Group4.java@ 1

Last change on this file since 1 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.group4;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.DeadlineType;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.DefaultAction;
13import genius.core.actions.Offer;
14import genius.core.issue.Issue;
15import genius.core.issue.IssueDiscrete;
16import genius.core.issue.Value;
17import genius.core.issue.ValueDiscrete;
18import genius.core.parties.AbstractNegotiationParty;
19import genius.core.parties.NegotiationInfo;
20import genius.core.utility.AbstractUtilitySpace;
21
22/**
23 * This is your negotiation party.
24 */
25public class Group4 extends AbstractNegotiationParty {
26
27 private Double currentUtility = 0.0;
28 private Double threshold;
29 private Double RESERVATION_VALUE;
30 private final Double STARTING_THRESHOLD = 0.9;
31 private final Double COMPROMISE_RATE = 4.0; // 1 is linear, higher is slower
32 // to compromise
33 private int turns;
34 private int round = 0;
35
36 private Bid highestBid;
37 private Bid lastGivenBid;
38 private Bid lastReceivedBid;
39 private HashMap<String, Party> parties = new HashMap<String, Party>();
40 private ArrayList<List<ValueDiscrete>> values = new ArrayList<List<ValueDiscrete>>();
41 private BidGenerator bidGenerator;
42
43 private HashMap<Bid, Double> possibleBids = new HashMap<Bid, Double>();
44 private AbstractUtilitySpace utilitySpace;
45
46 /**
47 * Please keep this constructor. This is called by genius.
48 *
49 * @param utilitySpace
50 * Your utility space.
51 * @param deadlines
52 * The deadlines set for this negotiation.
53 * @param timeline
54 * Value counting from 0 (start) to 1 (end).
55 * @param randomSeed
56 * If you use any randomisation, use this seed for it.
57 */
58 @Override
59 public void init(NegotiationInfo info) {
60 // Make sure that this constructor calls it's parent.
61 super.init(info);
62
63 this.utilitySpace = info.getUtilitySpace();
64 for (Issue issue : utilitySpace.getDomain().getIssues()) {
65 values.add(((IssueDiscrete) issue).getValues());
66 }
67
68 // creates the generator
69 generatePossibleBids(0, null);
70 turns = getDeadlines().getType() == DeadlineType.ROUND ? getDeadlines().getValue() : 0; // -1
71 // helps
72 // with
73 // very
74 // low
75 // deadline,
76 // doesn't
77 // hurt
78 // large.
79 bidGenerator = new BidGenerator(this, possibleBids, turns);
80
81 RESERVATION_VALUE = utilitySpace.getReservationValue();
82 }
83
84 private void generatePossibleBids(int n, HashMap<Integer, Value> bidValues) {
85 if (n >= values.size()) {
86 Bid b = null;
87
88 try {
89 b = new Bid(utilitySpace.getDomain(), bidValues);
90 possibleBids.put(b, getUtility(b));
91 } catch (Exception e) {
92 e.printStackTrace();
93 }
94 return;
95 }
96 for (Value v : values.get(n)) {
97 HashMap<Integer, Value> currentBid;
98
99 if (n == 0) {
100 currentBid = new HashMap<Integer, Value>();
101 } else {
102 currentBid = (HashMap<Integer, Value>) bidValues.clone();
103 }
104
105 currentBid.put(n + 1, v);
106 generatePossibleBids(n + 1, currentBid);
107 }
108 }
109
110 /**
111 * Each round this method gets called and ask you to accept or offer. The
112 * first party in the first round is a bit different, it can only propose an
113 * offer.
114 *
115 * @param validActions
116 * Either a list containing both accept and offer or only offer.
117 * @return The chosen action.
118 */
119 @Override
120 public Action chooseAction(List<Class<? extends Action>> validActions) {
121 round++;
122 threshold = STARTING_THRESHOLD
123 - (STARTING_THRESHOLD - RESERVATION_VALUE) * Math.pow((double) round / (double) turns, COMPROMISE_RATE);
124
125 /*
126 * if(round >= turns){ return new Accept(); }
127 */
128
129 if (!validActions.contains(Accept.class) || currentUtility < threshold) {
130 Bid b = null;
131 // if it's first turn, get out with best possible bid
132 if (lastGivenBid == null) {
133 try {
134 b = utilitySpace.getMaxUtilityBid();
135 } catch (Exception e) {
136 // TODO Auto-generated catch block
137 e.printStackTrace();
138 }
139 }
140
141 // do something to get the bid as answer
142 else {
143 // it generates the best not used bid
144 int index = 0;
145 do {
146 b = bidGenerator.generateBestBid();
147
148 index++;
149 if (index > 100) {
150 index = 0;
151 threshold = threshold - 0.01; // safety measure
152 }
153 } while (getUtility(b) < threshold);
154
155 }
156 setLastGivenBid(b);
157 return new Offer(getPartyId(), b);
158
159 } else {
160 return new Accept(getPartyId(), lastReceivedBid);
161 }
162 }
163
164 /**
165 * All offers proposed by the other parties will be received as a message.
166 * You can use this information to your advantage, for example to predict
167 * their utility.
168 *
169 * @param sender
170 * The party that did the action.
171 * @param action
172 * The action that party did.
173 */
174 @Override
175 public void receiveMessage(AgentID sender, Action action) {
176 super.receiveMessage(sender, action);
177
178 if (!parties.containsKey(sender.toString())) {
179 Party party = new Party(sender.toString(), utilitySpace.getDomain(), sender);
180 parties.put(sender.toString(), party);
181 }
182
183 if (lastReceivedBid != null) {
184 parties.get(sender.toString()).updateWithBid(lastReceivedBid, action);
185 }
186
187 if (action instanceof Offer) {
188 lastReceivedBid = DefaultAction.getBidFromAction(action);
189 currentUtility = getUtility(lastReceivedBid);
190 updateHighestBid(lastReceivedBid);
191 } else if (action instanceof Accept) {
192 }
193
194 }
195
196 private void updateHighestBid(Bid b) {
197 // TODO it check if it is the highest and in case update it
198 }
199
200 // *******GETTER AND SETTER********
201
202 public Double getCurrentUtility() {
203 return currentUtility;
204 }
205
206 public void setCurrentUtility(Double currentUtility) {
207 this.currentUtility = currentUtility;
208 }
209
210 public Double getThreshold() {
211 return threshold;
212 }
213
214 public void setThreshold(Double threshold) {
215 this.threshold = threshold;
216 }
217
218 public Bid getHighestBid() {
219 return highestBid;
220 }
221
222 public void setHighestBid(Bid highestBid) {
223 this.highestBid = highestBid;
224 }
225
226 public Bid getLastGivenBid() {
227 return lastGivenBid;
228 }
229
230 public void setLastGivenBid(Bid lastGivenBid) {
231 this.lastGivenBid = lastGivenBid;
232 }
233
234 public HashMap<String, Party> getParties() {
235 return parties;
236 }
237
238 public void setParties(HashMap<String, Party> parties) {
239 this.parties = parties;
240 }
241
242 public int getTurns() {
243 return turns;
244 }
245
246 protected AgentID partyId = new AgentID("Group 4");
247
248 @Override
249 public String getDescription() {
250 return "ai2014 group4";
251 }
252
253}
Note: See TracBrowser for help on using the repository browser.