source: src/main/java/agents/anac/y2019/ibasic/boacomponents/IBasicBS.java@ 202

Last change on this file since 202 was 200, checked in by Katsuhide Fujita, 6 years ago

Add ANAC 2019 agents

File size: 7.5 KB
Line 
1package agents.anac.y2019.ibasic.boacomponents;
2
3import java.util.ArrayList;
4import java.util.HashSet;
5import java.util.List;
6import java.util.Map;
7import java.util.Set;
8
9import java.util.Random;
10
11import genius.core.Bid;
12import genius.core.bidding.BidDetails;
13import genius.core.boaframework.*;
14import genius.core.uncertainty.UserModel;
15import genius.core.utility.AbstractUtilitySpace;
16
17public class IBasicBS extends OfferingStrategy{
18 //list of all possible bids
19 private SortedOutcomeSpace outcomespace;
20 AbstractUtilitySpace utilSpace;
21 List<BidDetails> OpponentBidHistory;
22 private double pmax;
23 private double pmin;
24 private double e;
25 static Random r = new Random();
26 int stage = 0;
27 UserModel usermodel;
28 double opponentconsession = 0;
29 double reservationValue;
30 private IBasicOM opponentModel;
31 private IBasicOMStrategy omStrategy;
32
33 @Override
34 public void init(NegotiationSession negoSession, OpponentModel model, OMStrategy oms,
35 Map<String, Double> parameters) {
36 super.init(negoSession, parameters);
37 this.negotiationSession = negoSession;
38 this.opponentModel = (IBasicOM) model;
39 this.omStrategy = (IBasicOMStrategy) oms;
40 //Initializes the usermodel, utility space and reservation value.
41 this.usermodel = negotiationSession.getUserModel();
42 this.utilSpace = negotiationSession.getUtilitySpace();
43 this.reservationValue = utilSpace.getReservationValueUndiscounted();
44 System.out.println("Reservationvalue ="+this.reservationValue);
45 CalculateEValue();
46
47 //If we operate under preference uncertainty, we recalculate the utility space.
48 if (usermodel != null)
49 this.utilSpace = IBasicPU.createUtilitySpace(negotiationSession.getDomain(), usermodel);
50
51 //Sets the outcomespace with the respective utility space
52 this.outcomespace = new SortedOutcomeSpace(utilSpace);
53 this.negotiationSession.setOutcomeSpace(outcomespace);
54 this.OpponentBidHistory = new ArrayList<BidDetails>();
55 }
56
57 @Override
58 public BidDetails determineNextBid() {
59 //the opponent bids are stored after every bid
60 OpponentBidHistory.add(negotiationSession.getOpponentBidHistory().getLastBidDetails());
61 //This method checks in which of the 3 stages the negotiation is and adapts it's P range and e according to it
62 ConsessionStage();
63
64 // every 200 bids, we will evaluate how much concessions the opponent is making
65 if(OpponentBidHistory.size() % 100 == 0) {
66 opponentconsession = this.opponentModel.EvaluateConsessionOpp();
67 }
68
69 double time = GetTimeInterval(negotiationSession.getTime());
70
71 if( usermodel != null) {
72 if (usermodel.getBidRanking().getSize() < 30 ) {
73
74 return LowBidRanking();
75 }
76 }
77
78 //utilitygoal will be measured according to stage, time in stage and consessions that the opponent makes
79 double utilityGoal;
80 utilityGoal = p(time);
81
82 // best bids in range of utility goal are selected, and the OM strategy returns the best bid
83 nextBid = omStrategy.BestBid(utilityGoal, OpponentBidHistory);
84
85 // if we have the last bid, we will select a high bid in range .9 - 1, because we predict that every opponent will accept the last bid
86 if(negotiationSession.getTimeline().getCurrentTime() >= negotiationSession.getTimeline().getTotalTime() -5 )
87 {
88 utilityGoal = .85;
89 nextBid = omStrategy.BestBid(utilityGoal, OpponentBidHistory);
90
91 }
92 return nextBid;
93 }
94
95 //Calculates the time ratio within a certain stage
96 private double GetTimeInterval(Double time) {
97 if(stage == 1) {
98 return MapValue( 0, .666, 0, 1, time);
99 }
100 else if (stage == 2) {
101 return MapValue( .666, .95, 0, 1, time);
102 }
103 else {
104 double t = MapValue(.95, 1, 0, 1, time);
105 return t;
106 }
107 }
108
109 //Calculates the concession line that our agent is following
110 //by looking at the P range and the f(t) functing with t being time
111 private double p(double t) {
112 return pmin +(pmax - pmin) * f(t);
113 }
114
115 //calculates the concession line
116 private double f(double t) {
117
118 double ft = 1D - Math.pow(t, 1.0 / e);
119
120 return ft;
121 }
122
123 private void CalculateEValue() {
124 if(this.reservationValue > .5) {
125 this.e = MapValue(.5, 1, .1, 0.02, this.reservationValue);
126 }
127 else {
128 this.e = .1;
129 }
130 }
131
132 private double ReservationValue(int stage, double lowerbound) {
133 if(this.reservationValue > .5) {
134 double plower = (1- lowerbound)* this.reservationValue + lowerbound;
135 return plower;
136 }
137 return lowerbound;
138 }
139
140 //Divides the negotiation session in different stages and changes the p range depending on time
141 //and concession rate of the opponent
142 private void ConsessionStage() {
143 double lowerbound;
144 if(negotiationSession.getTime() <= 2D/ 3) {
145 stage = 1;
146 pmax = 1;
147 lowerbound = 0.88;
148 pmin = ReservationValue(stage, lowerbound);
149 }
150
151 else if (negotiationSession.getTime() <= .95) {
152 stage = 2;
153 if(opponentconsession > .1) {
154 pmax = 1;
155 lowerbound = .88;
156 pmin = ReservationValue(stage, lowerbound);
157 }
158 else {
159 pmax = 1;
160 lowerbound = 0.85;
161 pmin = ReservationValue(stage, lowerbound);
162 }
163 }
164 else {
165 // in de laatste fase wordt e aangepast om later te gaan conceden
166 stage = 3;
167 if(opponentconsession > .1) {
168
169 if(this.reservationValue > 0.5) {
170 pmin = this.reservationValue + .05;
171 pmax = .95;
172 }
173 else {
174 pmax = .95;
175 pmin = .85;
176 }
177 }
178 else {
179
180 if(this.reservationValue > 0.5) {
181 pmin = this.reservationValue + .05;
182 pmax = Math.max(this.reservationValue + .1, .9);
183 }
184 else {
185 pmax = .9;
186 pmin = .65;
187 }
188
189 }
190 }
191 }
192
193 private BidDetails LowBidRanking() {
194
195 BidDetails nextBid = null;
196 //the bids of the uncertainty preference are stored
197 List<Bid> uncertaintybids = usermodel.getBidRanking().getBidOrder();
198
199 // negotiation is in stage 1, only the upper 10% of the bids is played
200 if(stage == 1) {
201 nextBid = outcomespace.getMaxBidPossible();
202
203 }
204
205 //in stage 2 only the upper 20% is played
206 else if(stage == 2) {
207 double percentile = .8;
208 int Minrange = (int)(uncertaintybids.size()* percentile);
209 int random = r.nextInt(uncertaintybids.size() - Minrange) + Minrange;
210 nextBid = new BidDetails(uncertaintybids.get((random)), 0D);
211
212 }
213
214 //only the top 30% is played
215 else if (stage == 3) {
216 double percentile = .7;
217 int Minrange = (int)(uncertaintybids.size()* percentile);
218 int random = r.nextInt(uncertaintybids.size() - Minrange) + Minrange;
219 nextBid = new BidDetails(uncertaintybids.get(random), 0D);
220
221 }
222 return nextBid;
223
224 }
225
226 //returns max bid
227 @Override
228 public BidDetails determineOpeningBid() {
229 return outcomespace.getMaxBidPossible();
230 }
231
232 @Override
233 public String getName() {
234 return "IBasicBS";
235 }
236
237 @Override
238 public Set<BOAparameter> getParameterSpec() {
239 Set<BOAparameter> set = new HashSet<BOAparameter>();
240 set.add(new BOAparameter("e", 4D, "Concession rate"));
241 set.add(new BOAparameter("k", 0.0, "Offset"));
242 set.add(new BOAparameter("min", 0.0, "Minimum utility"));
243 set.add(new BOAparameter("max", 0.99, "Maximum utility"));
244
245 return set;
246 }
247
248 public double MapValue(double curmin, double curmax, double tarmin, double tarmax, double curval)
249 {
250 return tarmin + (tarmax - tarmin) * ((curval - curmin)/ (curmax - curmin));
251 }
252}
Note: See TracBrowser for help on using the repository browser.