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

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

Initial import : Genius 9.0.0

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