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

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

Initial import : Genius 9.0.0

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