source: src/main/java/agents/anac/y2017/parscat2/ParsCat2.java@ 316

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

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 8.1 KB
Line 
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package agents.anac.y2017.parscat2;
7
8import java.util.List;
9
10import java.util.ArrayList;
11
12import genius.core.AgentID;
13import genius.core.Bid;
14import genius.core.BidHistory;
15import genius.core.actions.Accept;
16import genius.core.actions.Action;
17import genius.core.actions.EndNegotiationWithAnOffer;
18import genius.core.actions.Offer;
19import genius.core.bidding.BidDetails;
20import genius.core.list.Tuple;
21import genius.core.parties.AbstractNegotiationParty;
22import genius.core.parties.NegotiationInfo;
23import genius.core.persistent.PersistentDataType;
24import genius.core.persistent.StandardInfo;
25import genius.core.persistent.StandardInfoList;
26import genius.core.timeline.TimeLineInfo;
27import genius.core.utility.AbstractUtilitySpace;
28
29/**
30 *
31 * @author Delaram - Agent Name: ParsCat2 - Team members: Delaram Javdani,
32 * Maedeh Najar, Faria Nassiri-Mofakham - Affiliation: University of
33 * Isfahan - Contact person: Faria Nassiri-Mofakham - Contact E-mail(s):
34 * djavdani1391@yahoo.com, nmaedeh@rocketmail.com,
35 * fnasirimofakham@yahoo.com
36 */
37public class ParsCat2 extends AbstractNegotiationParty {
38
39 /**
40 * @param args
41 * the command line arguments
42 */
43 public static void main(String[] args) {
44 // TODO code application logic here
45 }
46
47 private StandardInfoList history;
48 private TimeLineInfo TimeLineInfo = null;
49 private AbstractUtilitySpace utilSpace = null;
50 private Bid maxBid = null;
51 private Bid lastReceivedBid = null;
52 private BidHistory currSessOppBidHistory;
53 private BidHistory prevSessionsAgreementBidHistory;
54 private int num = 0;
55 private int num1 = 0;
56 private List prevSessAvgUtilLis;
57
58 public ParsCat2() {
59 currSessOppBidHistory = new BidHistory();
60 this.prevSessAvgUtilLis = new ArrayList();
61 }
62
63 @Override
64 public void init(NegotiationInfo info) {
65 super.init(info);
66 this.utilSpace = getUtilitySpace();
67 TimeLineInfo = timeline;
68 try {
69 maxBid = getUtilitySpace().getMaxUtilityBid();
70 } catch (Exception ex) {
71 }
72 if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
73 throw new IllegalStateException("need standard persistent data");
74 }
75 history = (StandardInfoList) getData().get();
76
77 if (!history.isEmpty()) {
78 agreementHistory();
79 }
80 }
81
82 @Override
83 public Action chooseAction(List<Class<? extends Action>> validActions) {
84 if (lastReceivedBid != null) {
85 try {
86 Bid myBidByTime = generateRandomBidByTime();
87 double myBidUtilByTime = getUtility(myBidByTime);
88 double time = TimeLineInfo.getTime();
89 if (isAcceptable(getUtility(lastReceivedBid), time,
90 myBidUtilByTime))
91 return new Accept(getPartyId(), lastReceivedBid);
92 else
93 return new Offer(getPartyId(), myBidByTime);
94 } catch (Exception ex) {
95 }
96 }
97 return new Offer(getPartyId(), maxBid);
98 }
99
100 private boolean isAcceptable(double offeredUtilFromOtherAgent, double time,
101 double myBidUtilByTime) throws Exception {
102 if (offeredUtilFromOtherAgent >= myBidUtilByTime)
103 return true;
104 double Util = 1;
105 if (time <= .25)
106 Util = 1 - time * 0.4;
107 else if ((time > .25) && (time <= .375))
108 Util = .9 + (time - .25) * 0.4;
109 else if ((time > .375) && (time <= .5))
110 Util = .95 - (time - .375) * 0.4;
111 else if ((time > .5) && (time <= .6))
112 Util = .9 - (time - .5);
113 else if ((time > .6) && (time <= .7))
114 Util = .8 + (time - .6) * 2;
115 else if ((time > .7) && (time <= .8))
116 Util = 1 - (time - .7) * 3;
117 else if ((time > .8) && (time <= .9))
118 Util = .7 + (time - 0.8) * 1;
119 else if ((time > .9) && (time <= .95))
120 Util = .8 - (time - .9) * 6;
121 else if ((time > .95))
122 Util = .5 + (time - .95) * 4;
123 if (Util > 1)
124 Util = .8;
125 if (Util < 0)
126 Util = 0;
127 return offeredUtilFromOtherAgent >= Util;
128 }
129
130 private Bid generateRandomBidByTime() throws Exception {
131 double width = .01;
132 double thinner = 0;
133 double time = TimeLineInfo.getTime();
134 double tresh = 0;
135 if (time < .5) {
136 tresh = 1 - time / 4;
137 width = 0.01;
138 } else if ((time >= .5) && (time < .8)) {
139 tresh = .9 - time / 5;
140 width = .02;
141 } else if ((time >= .8) && (time < .9)) {
142 tresh = .7 + time / 5;
143 width = .02;
144 } else if ((time >= .9) && (time < .95)) {
145 tresh = .8 + time / 5;
146 width = .02;
147 } else if (time >= .95) {
148 tresh = 1 - time / 4 - .01;
149 width = .02;
150 } else if (time == 1) {
151 tresh = .5;
152 width = .05;
153 }
154 if (tresh > 1) {
155 tresh = 1;
156 width = .01;
157 }
158 if (tresh <= 0.5) {
159 tresh = .49;
160 width = .01;
161 }
162 if (!currSessOppBidHistory.isEmpty()
163 && tresh < getUtility(
164 currSessOppBidHistory.getBestBidDetails().getBid())
165 && getNumberOfParties() == 2)
166 tresh = getUtility(
167 currSessOppBidHistory.getBestBidDetails().getBid());
168 if (time > .25 && time < .3
169 && !prevSessionsAgreementBidHistory.isEmpty()
170 && tresh < getUtility(prevSessionsAgreementBidHistory
171 .getBestBidDetails().getBid()))
172 tresh = getUtility(prevSessionsAgreementBidHistory
173 .getBestBidDetails().getBid());
174 else if (time > .55 && time < .6
175 && !prevSessionsAgreementBidHistory.isEmpty()
176 && getUtility(prevSessionsAgreementBidHistory.getHistory()
177 .get(num).getBid()) > .5) {
178 tresh = getUtility(prevSessionsAgreementBidHistory.getHistory()
179 .get(num).getBid());
180 num++;
181 if (num >= this.prevSessionsAgreementBidHistory.size())
182 num = 0;
183 } else if (time > .65 && time < .7
184 && !prevSessionsAgreementBidHistory.isEmpty()
185 && getUtility(prevSessionsAgreementBidHistory
186 .getFirstBidDetails().getBid()) > .5)
187 tresh = getUtility(prevSessionsAgreementBidHistory
188 .getFirstBidDetails().getBid());
189 else if (time > .75 && time < .8
190 && !prevSessionsAgreementBidHistory.isEmpty()
191 && prevSessionsAgreementBidHistory.getAverageUtility() > .5)
192 tresh = prevSessionsAgreementBidHistory.getAverageUtility();
193 else if (time > .85 && time < .9 && !prevSessAvgUtilLis.isEmpty()) {
194 double util = (double) prevSessAvgUtilLis.get(num1);
195 if (util > .4) {
196 tresh = util;
197 num1++;
198 if (num1 >= prevSessAvgUtilLis.size())
199 num1 = 0;
200 }
201 }
202 if (tresh < 0)
203 tresh = .4;
204 for (int count = 0; count < 100; count++) {
205 for (int counter = 0; counter < 1000; counter++) {
206 Bid bid = generateRandomBid();
207 if ((getUtility(bid) > (tresh - width))
208 && (getUtility(bid) < (tresh + width)))
209 return bid;
210 }
211 thinner = thinner + .01;
212 tresh = tresh - thinner;
213 if (tresh < 0)
214 return generateRandomBid();
215 }
216 return generateRandomBid();
217 }
218
219 @Override
220 public void receiveMessage(AgentID sender, Action action) {
221 super.receiveMessage(sender, action);
222 if (action instanceof Offer) {
223 lastReceivedBid = ((Offer) action).getBid();
224 try {
225 BidDetails opponentBid = new BidDetails(lastReceivedBid,
226 getUtility(lastReceivedBid), TimeLineInfo.getTime());
227 currSessOppBidHistory.add(opponentBid);
228 } catch (Exception e) {
229 EndNegotiationWithAnOffer endNegotiationWithAnOffer = new EndNegotiationWithAnOffer(
230 this.getPartyId(), maxBid);
231 }
232 }
233 }
234
235 public void agreementHistory() {
236 prevSessionsAgreementBidHistory = new BidHistory();
237 int k = 0;
238 if (history.size() > 10)
239 k = history.size() - 11;
240 for (int h = history.size() - 1; h >= k; h--) {
241 StandardInfo lastinfo = history.get(h);
242 Tuple<Bid, Double> agree = lastinfo.getAgreement();
243 BidDetails opponentBid = new BidDetails(agree.get1(), agree.get2(),
244 TimeLineInfo.getTime());
245 prevSessionsAgreementBidHistory.add(opponentBid);
246 double count = 0;
247 double sum = 0;
248 for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
249 Double util = offered.get2();
250 count++;
251 sum = sum + util;
252 }
253 if (count != 0) {
254 double avg = sum / count;
255 prevSessAvgUtilLis.add(avg);
256 }
257 }
258 }
259
260 @Override
261 public String getDescription() {
262 return "ANAC2017";
263 }
264
265}
Note: See TracBrowser for help on using the repository browser.