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

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

File size: 7.1 KB
Line 
1package agents.anac.y2018.groupy;
2import java.util.ArrayList;
3import java.util.HashMap;
4import java.util.List;
5import java.util.Map;
6
7import list.Tuple;
8import misc.Range;
9import negotiator.AgentID;
10import negotiator.Bid;
11import negotiator.actions.Accept;
12import negotiator.actions.Action;
13import negotiator.actions.EndNegotiation;
14import negotiator.actions.Offer;
15import negotiator.bidding.BidDetails;
16import negotiator.boaframework.SortedOutcomeSpace;
17
18import negotiator.parties.AbstractNegotiationParty;
19import negotiator.parties.NegotiationInfo;
20import negotiator.persistent.PersistentDataType;
21import negotiator.persistent.StandardInfo;
22import negotiator.persistent.StandardInfoList;
23
24/**
25 * Sample party that accepts the Nth offer, where N is the number of sessions
26 * this [agent-profile] already did.
27 */
28public class GroupY extends AbstractNegotiationParty {
29 /**
30 *
31 */
32 private static final long serialVersionUID = 1L;
33 private double timeTreshhold;
34 private Bid lastReceivedBid = null;
35 private int nrChosenActions = 0; // number of times chosenAction was called.
36 private StandardInfoList history;
37 private Bid Max = null;
38 private Double reservationV;
39 private Bid Min = null;
40 private Range r = new Range(0, 0);
41 private OpponentModelHolder hold;
42 private ArrayList<AgentID> agentId;
43 SortedOutcomeSpace sos;
44 private ArrayList<Bid> loopB = new ArrayList<Bid>();
45 int loopCounter = 0;
46 private boolean first = true;
47
48 @Override
49 public void init(NegotiationInfo info) {
50
51 super.init(info);
52 hold = new OpponentModelHolder();
53 agentId = new ArrayList<AgentID>();
54 sos = new SortedOutcomeSpace(utilitySpace);
55
56 try {
57 Max = utilitySpace.getMaxUtilityBid();
58 Min = utilitySpace.getMinUtilityBid();
59 r.setUpperbound(getUtility(Max));
60 reservationV = utilitySpace.getReservationValue();
61
62 } catch (Exception e) {
63 // TODO Auto-generated catch block
64 e.printStackTrace();
65 }
66 System.out.println("Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
67 System.out.println("Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
68
69 if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
70 throw new IllegalStateException("need standard persistent data");
71 }
72 history = (StandardInfoList) getData().get();
73
74 if (!history.isEmpty()) {
75
76 Map<String, Double> maxutils = new HashMap<String, Double>();
77 StandardInfo lastinfo = history.get(history.size() - 1);
78
79 if (hold.getAgentModels().get(getPartyId()) == null) {
80 hold.getAgentModels().put(getPartyId(), new OpponentModel(utilitySpace, timeline.getTime()));
81 agentId.add(getPartyId());
82
83 }
84 int remember =0;
85 double normalize=102;
86 for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
87
88 String party = offered.get1();
89 Double util = offered.get2();
90 Bid bid = sos.getBidNearUtility(util).getBid();
91 hold.getAgentModels().get(getPartyId()).updateModel(bid,(int)normalize);
92 if(remember==100000)break;
93 // maxutils.put(party, maxutils.containsKey(party) ?
94 // Math.max(maxutils.get(party), util) : util);
95 remember++;
96 normalize=normalize-0.001;
97 }
98 // System.out.println(maxutils); // notice tournament suppresses all
99 // output.
100 }
101 }
102
103 public Action chooseAction(List<Class<? extends Action>> validActions) {
104 nrChosenActions++;
105
106 if (nrChosenActions < 4) {
107 loopCounter = loopCounter + 1;
108 if (lastReceivedBid != null && getUtility(lastReceivedBid) == getUtility(Max)) {
109
110 return new Accept(getPartyId(), lastReceivedBid);
111
112 }
113 loopB.add(Max);
114 return new Offer(getPartyId(), Max);
115
116 } else {
117 // if generatebid<lastReceivedBid
118 // reservation value must change to undiscounted
119 if (timeline.getTime() < 0.99) {
120 if (lastReceivedBid != null && getUtility(lastReceivedBid) >= getUtility(getSuperOffer())
121 && reservationV < getUtility(lastReceivedBid)) {
122 return new Accept(getPartyId(), lastReceivedBid);
123
124 } else {
125 loopCounter = loopCounter + 1;
126 if (first) {
127 loopB.add(getSuperOffer());
128 first = false;
129 }
130
131 if (loopCounter == 5) {
132 loopCounter = 1;
133 if (!loopB.isEmpty())
134 loopB.remove(0);
135 loopB.add(getSuperOffer());
136 }
137
138 // return new Offer(getPartyId(), Max);
139 return new Offer(getPartyId(), loopB.get(loopCounter - 1));
140
141 }
142 } else {
143 if (0.65 <= getUtility(lastReceivedBid))
144 return new Accept(getPartyId(), lastReceivedBid);
145 return new Offer(getPartyId(), sos.getBidNearUtility(0.7).getBid());
146
147 }
148
149 }
150
151 }
152
153 @Override
154 public void receiveMessage(AgentID sender, Action action) {
155 super.receiveMessage(sender, action);
156 if (action instanceof Offer) {
157 lastReceivedBid = ((Offer) action).getBid();
158
159 if (hold.getAgentModels().get(sender) == null) {
160 hold.getAgentModels().put(sender, new OpponentModel(utilitySpace, timeline.getTime()));
161 agentId.add(sender);
162
163 }
164
165 hold.getAgentModels().get(sender).updateModel(lastReceivedBid,1);
166 }
167
168 }
169
170 public String getDescription() {
171 return "Hi accept Nth offer";
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.