source: src/main/java/agents/anac/y2016/parscat/ParsCat.java@ 326

Last change on this file since 326 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: 7.6 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.y2016.parscat;
7
8import java.util.List;
9
10import java.util.HashMap;
11import java.util.Random;
12import java.util.logging.Level;
13import java.util.logging.Logger;
14
15import genius.core.AgentID;
16import genius.core.Bid;
17import genius.core.BidHistory;
18import genius.core.actions.Accept;
19import genius.core.actions.Action;
20import genius.core.actions.EndNegotiationWithAnOffer;
21import genius.core.actions.Offer;
22import genius.core.bidding.BidDetails;
23import genius.core.issue.Issue;
24import genius.core.issue.IssueDiscrete;
25import genius.core.issue.IssueInteger;
26import genius.core.issue.Value;
27import genius.core.issue.ValueInteger;
28import genius.core.parties.AbstractNegotiationParty;
29import genius.core.parties.NegotiationInfo;
30import genius.core.timeline.TimeLineInfo;
31import genius.core.utility.AbstractUtilitySpace;
32
33/**
34 *
35 * @author Delaram
36 */
37public class ParsCat 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 TimeLineInfo TimeLineInfo = null;
48 private Bid maxBid = null;
49 private AbstractUtilitySpace utilSpace = null;
50 private BidHistory OtherAgentsBidHistory;
51 private double tresh;
52 private double t1 = 0;
53 private double u2 = 1;
54
55 public ParsCat() {
56 this.OtherAgentsBidHistory = new BidHistory();
57 }
58
59 @Override
60 public void init(NegotiationInfo info) {
61 super.init(info);
62
63 this.utilSpace = getUtilitySpace();// read utility space
64 TimeLineInfo = timeline; // read time line info
65
66 try {
67 maxBid = utilSpace.getMaxUtilityBid();
68 } catch (Exception ex) {
69 Logger.getLogger(ParsCat.class.getName()).log(Level.SEVERE, null,
70 ex);
71 }
72
73 }
74
75 /**
76 * Each round this method gets called and ask you to accept or offer. The
77 * first party in the first round is a bit different, it can only propose an
78 * offer.
79 *
80 * @param validActions
81 * Either a list containing both accept and offer or only offer.
82 * @return The chosen action.
83 */
84
85 @Override
86 public Action chooseAction(List<Class<? extends Action>> validActions) {
87 Action action;
88 try {
89 if (OtherAgentsBidHistory.isEmpty()) {
90 return new Offer(getPartyId(), maxBid);
91 }
92 action = new Offer(getPartyId(), getRandomBid());
93 Bid myBid = ((Offer) action).getBid();
94 double myOfferedUtil = getUtility(myBid);
95 double time = TimeLineInfo.getTime();// get current time
96
97 if (OtherAgentsBidHistory.getLastBid() == myBid) {
98 return new Accept(getPartyId(),
99 OtherAgentsBidHistory.getLastBid());
100 } else {
101 Bid OtherAgentBid = OtherAgentsBidHistory.getLastBid();
102 double offeredUtilFromOpponent = getUtility(OtherAgentBid);
103 if (isAcceptable(offeredUtilFromOpponent, myOfferedUtil,
104 time)) {
105 return new Accept(getPartyId(), OtherAgentBid);
106 } else {
107 return action;
108 }
109
110 }
111 } catch (Exception e) {
112 return new Offer(getPartyId(), maxBid);
113 }
114 }
115
116 private boolean isAcceptable(double offeredUtilFromOtherAgent,
117 double myOfferedUtil, double time) throws Exception {
118 if (offeredUtilFromOtherAgent == myOfferedUtil)
119 return true;
120 double t = time;
121 double Util = 1;
122 if (time <= .25) {
123 Util = 1 - t * 0.4;
124 }
125 if ((time > .25) && (time <= .375)) {
126 Util = .9 + (t - .25) * 0.4;
127 }
128 if ((time > .375) && (time <= .5)) {
129 Util = .95 - (t - .375) * 0.4;
130 }
131 if ((time > .5) && (time <= .6)) {
132 Util = .9 - (t - .5);
133 }
134 if ((time > .6) && (time <= .7)) {
135 Util = .8 + (t - .6) * 2;
136 }
137 if ((time > .7) && (time <= .8)) {
138 Util = 1 - (t - .7) * 3;
139 }
140 if ((time > .8) && (time <= .9)) {
141 Util = .7 + (t - 0.8) * 1;
142 }
143 if ((time > .9) && (time <= .95)) {
144 Util = .8 - (t - .9) * 6;
145 }
146 if ((time > .95)) {
147 Util = .5 + (t - .95) * 4;
148 }
149 if (Util > 1) {
150 Util = .8;
151 }
152 // it will accept other agents offer if their offer is bigger than the
153 // utility calculated
154 return offeredUtilFromOtherAgent >= Util;
155 }
156
157 private Bid getRandomBid() throws Exception {
158 HashMap<Integer, Value> values = new HashMap<>();
159 List<Issue> issues = utilSpace.getDomain().getIssues();
160 Random randomnr = new Random();
161 Bid bid = null;
162 double xxx = .001;
163 long counter = 1000;
164 double check = 0;
165 while (counter == 1000) {
166 counter = 0;
167 do {
168 for (Issue lIssue : issues) {
169 switch (lIssue.getType()) {
170 case DISCRETE:
171 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
172 int optionIndex = randomnr
173 .nextInt(lIssueDiscrete.getNumberOfValues());
174 values.put(lIssue.getNumber(),
175 lIssueDiscrete.getValue(optionIndex));
176 break;
177
178 case INTEGER:
179 IssueInteger lIssueInteger = (IssueInteger) lIssue;
180 int optionIndex2 = lIssueInteger.getLowerBound()
181 + randomnr.nextInt(lIssueInteger.getUpperBound()
182 - lIssueInteger.getLowerBound());
183 values.put(lIssueInteger.getNumber(),
184 new ValueInteger(optionIndex2));
185 break;
186 default:
187 throw new Exception("issue type " + lIssue.getType()
188 + " not supported by SamantaAgent2");
189 }
190 }
191 bid = new Bid(utilitySpace.getDomain(), values);
192
193 if (t1 < .5) {
194 tresh = 1 - t1 / 4;
195 xxx = 0.01;
196 }
197 if ((t1 >= .5) && (t1 < .8)) {
198 tresh = .9 - t1 / 5;
199 xxx = .02;
200 }
201 if ((t1 >= .8) && (t1 < .9)) {
202 tresh = .7 + t1 / 5;
203 xxx = .02;
204 }
205 if ((t1 >= .9) && (t1 < .95)) {
206 tresh = .8 + t1 / 5;
207 xxx = .02;
208 }
209 if (t1 >= .95) {
210 tresh = 1 - t1 / 4 - .01;
211 xxx = .02;
212 }
213 if (t1 == 1) {
214 tresh = .5;
215 xxx = .05;
216 }
217 tresh = tresh - check;
218 if (tresh > 1) {
219 tresh = 1;
220 xxx = .01;
221 }
222 if (tresh <= 0.5) {
223 tresh = 0.49;
224 xxx = .01;
225
226 }
227 counter++;
228 } // check if the utility of the bid is in the correct interval if
229 // not it will search again.
230 while (((getUtility(bid) < (tresh - xxx))
231 || (getUtility(bid) > (tresh + xxx))) && (counter < 1000));
232 check = check + .01;
233 }
234 // if the utility of my bid is smaller than the other Agent bid we will
235 // send the best bid we get till that time
236 // otherwise we will send our random bid
237 if ((getUtility(bid) < getUtility(
238 OtherAgentsBidHistory.getBestBidDetails().getBid()))
239 && getNumberOfParties() == 2)
240 return OtherAgentsBidHistory.getBestBidDetails().getBid();
241
242 return bid;
243 }
244
245 /**
246 * All offers proposed by the other parties will be received as a message.
247 * You can use this information to your advantage, for example to predict
248 * their utility.
249 *
250 * @param sender
251 * The party that did the action. Can be null.
252 * @param action
253 * The action that party did.
254 */
255
256 @Override
257 public void receiveMessage(AgentID sender, Action action) {
258 super.receiveMessage(sender, action);
259 // Here you hear other parties' messages
260 if (action instanceof Offer) {
261 Bid bid = ((Offer) action).getBid();
262 try {
263 BidDetails opponentBid = new BidDetails(bid,
264 utilSpace.getUtility(bid), TimeLineInfo.getTime());
265 u2 = utilSpace.getUtility(bid);
266 t1 = TimeLineInfo.getTime();
267 OtherAgentsBidHistory.add(opponentBid);
268
269 } catch (Exception e) {
270 EndNegotiationWithAnOffer end = new EndNegotiationWithAnOffer(
271 this.getPartyId(), maxBid);
272 }
273 }
274 }
275
276 @Override
277 public String getDescription() {
278 return "ANAC2016";
279 }
280
281}
Note: See TracBrowser for help on using the repository browser.