source: src/main/java/agents/anac/y2018/groupy/GroupY.java

Last change on this file was 345, checked in by Tim Baarslag, 4 years ago

Fixed agent 2018 descriptions

File size: 7.1 KB
Line 
1package agents.anac.y2018.groupy;
2import java.util.List;
3
4import java.util.ArrayList;
5import java.util.HashMap;
6import java.util.Map;
7
8import genius.core.AgentID;
9import genius.core.Bid;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.Offer;
13import genius.core.bidding.BidDetails;
14import genius.core.boaframework.SortedOutcomeSpace;
15import genius.core.list.Tuple;
16import genius.core.misc.Range;
17import genius.core.parties.AbstractNegotiationParty;
18import genius.core.parties.NegotiationInfo;
19import genius.core.persistent.PersistentDataType;
20import genius.core.persistent.StandardInfo;
21import genius.core.persistent.StandardInfoList;
22
23/**
24 * Sample party that accepts the Nth offer, where N is the number of sessions
25 * this [agent-profile] already did.
26 */
27public class GroupY extends AbstractNegotiationParty {
28 /**
29 *
30 */
31 private static final long serialVersionUID = 1L;
32 private double timeTreshhold;
33 private Bid lastReceivedBid = null;
34 private int nrChosenActions = 0; // number of times chosenAction was called.
35 private StandardInfoList history;
36 private Bid Max = null;
37 private Double reservationV;
38 private Bid Min = null;
39 private Range r = new Range(0, 0);
40 private OpponentModelHolder hold;
41 private ArrayList<AgentID> agentId;
42 SortedOutcomeSpace sos;
43 private ArrayList<Bid> loopB = new ArrayList<Bid>();
44 int loopCounter = 0;
45 private boolean first = true;
46
47 @Override
48 public void init(NegotiationInfo info) {
49
50 super.init(info);
51 hold = new OpponentModelHolder();
52 agentId = new ArrayList<AgentID>();
53 sos = new SortedOutcomeSpace(utilitySpace);
54
55 try {
56 Max = utilitySpace.getMaxUtilityBid();
57 Min = utilitySpace.getMinUtilityBid();
58 r.setUpperbound(getUtility(Max));
59 reservationV = utilitySpace.getReservationValue();
60
61 } catch (Exception e) {
62 // TODO Auto-generated catch block
63 e.printStackTrace();
64 }
65 System.out.println("Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
66 System.out.println("Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
67
68 if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
69 throw new IllegalStateException("need standard persistent data");
70 }
71 history = (StandardInfoList) getData().get();
72
73 if (!history.isEmpty()) {
74
75 Map<String, Double> maxutils = new HashMap<String, Double>();
76 StandardInfo lastinfo = history.get(history.size() - 1);
77
78 if (hold.getAgentModels().get(getPartyId()) == null) {
79 hold.getAgentModels().put(getPartyId(), new OpponentModel(utilitySpace, timeline.getTime()));
80 agentId.add(getPartyId());
81
82 }
83 int remember =0;
84 double normalize=102;
85 for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
86
87 String party = offered.get1();
88 Double util = offered.get2();
89 Bid bid = sos.getBidNearUtility(util).getBid();
90 hold.getAgentModels().get(getPartyId()).updateModel(bid,(int)normalize);
91 if(remember==100000)break;
92 // maxutils.put(party, maxutils.containsKey(party) ?
93 // Math.max(maxutils.get(party), util) : util);
94 remember++;
95 normalize=normalize-0.001;
96 }
97 // System.out.println(maxutils); // notice tournament suppresses all
98 // output.
99 }
100 }
101
102 public Action chooseAction(List<Class<? extends Action>> validActions) {
103 nrChosenActions++;
104
105 if (nrChosenActions < 4) {
106 loopCounter = loopCounter + 1;
107 if (lastReceivedBid != null && getUtility(lastReceivedBid) == getUtility(Max)) {
108
109 return new Accept(getPartyId(), lastReceivedBid);
110
111 }
112 loopB.add(Max);
113 return new Offer(getPartyId(), Max);
114
115 } else {
116 // if generatebid<lastReceivedBid
117 // reservation value must change to undiscounted
118 if (timeline.getTime() < 0.99) {
119 if (lastReceivedBid != null && getUtility(lastReceivedBid) >= getUtility(getSuperOffer())
120 && reservationV < getUtility(lastReceivedBid)) {
121 return new Accept(getPartyId(), lastReceivedBid);
122
123 } else {
124 loopCounter = loopCounter + 1;
125 if (first) {
126 loopB.add(getSuperOffer());
127 first = false;
128 }
129
130 if (loopCounter == 5) {
131 loopCounter = 1;
132 if (!loopB.isEmpty())
133 loopB.remove(0);
134 loopB.add(getSuperOffer());
135 }
136
137 // return new Offer(getPartyId(), Max);
138 return new Offer(getPartyId(), loopB.get(loopCounter - 1));
139
140 }
141 } else {
142 if (0.65 <= getUtility(lastReceivedBid))
143 return new Accept(getPartyId(), lastReceivedBid);
144 return new Offer(getPartyId(), sos.getBidNearUtility(0.7).getBid());
145
146 }
147
148 }
149
150 }
151
152 @Override
153 public void receiveMessage(AgentID sender, Action action) {
154 super.receiveMessage(sender, action);
155 if (action instanceof Offer) {
156 lastReceivedBid = ((Offer) action).getBid();
157
158 if (hold.getAgentModels().get(sender) == null) {
159 hold.getAgentModels().put(sender, new OpponentModel(utilitySpace, timeline.getTime()));
160 agentId.add(sender);
161
162 }
163
164 hold.getAgentModels().get(sender).updateModel(lastReceivedBid,1);
165 }
166
167 }
168
169 @Override
170 public String getDescription() {
171 return "ANAC2018";
172 }
173
174 /*
175 * public double timeDeal() {
176 *
177 * Double remTimeRatio = 1 - timeline.getTime();
178 *
179 * double minUtility = 0 + getUtility(Min); if (remTimeRatio > 0.5) { minUtility
180 * = 0.8 + getUtility(Min); } else if (remTimeRatio > 0.1) { minUtility = 0.6 +
181 * getUtility(Min); } else { minUtility = 0.3 + getUtility(Min); }
182 *
183 * return minUtility + (getUtility(Max) - minUtility) * Math.pow(remTimeRatio, 1
184 * / Math.E); }
185 */
186 public double timeDeal() {
187
188 Double remTimeRatio = 1 - timeline.getTime();
189
190 double minUtility = 0 + getUtility(Min);
191 if (remTimeRatio > 0.5) {
192 minUtility = 0.85 + getUtility(Min);
193 } else if (remTimeRatio > 0.2) {
194 minUtility = 0.65 + getUtility(Min);
195 } else {
196 minUtility = 0.45 + getUtility(Min);
197 }
198
199 return minUtility + (getUtility(Max) - minUtility) * Math.pow(remTimeRatio, 1 / Math.E);
200 }
201
202 /*
203 * public Bid getSuperOffer() {
204 *
205 * double utilBid; timeTreshhold = timeDeal(); r.setLowerbound(timeTreshhold);
206 * List<BidDetails> bids = sos.getBidsinRange(r); Set set =
207 * hold.getAgentModels().entrySet(); Iterator iterator = set.iterator(); Bid
208 * bestBid = bids.get(0).getBid(); double bestBidUtil = 0; for (BidDetails
209 * bidTot : bids) { utilBid = 0; while (iterator.hasNext()) { Map.Entry entry =
210 * (Map.Entry) iterator.next(); OpponentModel op = (OpponentModel)
211 * entry.getValue(); utilBid = utilBid + op.ExpectedUtility(bidTot.getBid());
212 *
213 * } if (bestBidUtil < utilBid) bestBid = bidTot.getBid();
214 *
215 * }
216 *
217 * return bestBid; }
218 */
219 public Bid getSuperOffer() {
220
221 double utilBid;
222 timeTreshhold = timeDeal();
223 r.setLowerbound(timeTreshhold);
224
225 List<BidDetails> bids = sos.getBidsinRange(r);
226
227 Bid bestBid = bids.get(0).getBid();
228 if (bestBid == null)
229 bestBid = Max;
230 double bestBidUtil = 0;
231 for (BidDetails bidTot : bids) {
232 utilBid = 0;
233 for (AgentID id : agentId) {
234
235 OpponentModel op = hold.getAgentModels().get(id);
236
237 utilBid = utilBid + op.ExpectedUtility(bidTot.getBid());
238
239 }
240 if (bestBidUtil < utilBid) {
241 bestBid = bidTot.getBid();
242 bestBidUtil = utilBid;
243 }
244 }
245
246 // System.out.println("bestbid: " + bestBid);
247
248 return bestBid;
249 }
250
251}
Note: See TracBrowser for help on using the repository browser.