source: src/main/java/agents/anac/y2014/BraveCat/OfferingStrategies/BRTOfferingStrategy.java@ 345

Last change on this file since 345 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: 6.9 KB
Line 
1package agents.anac.y2014.BraveCat.OfferingStrategies;
2
3import java.util.HashMap;
4import java.util.Random;
5
6import agents.anac.y2014.BraveCat.OpponentModelStrategies.OMStrategy;
7import agents.anac.y2014.BraveCat.OpponentModels.NoModel;
8import agents.anac.y2014.BraveCat.OpponentModels.OpponentModel;
9import agents.anac.y2014.BraveCat.necessaryClasses.BidGenerator;
10import agents.anac.y2014.BraveCat.necessaryClasses.NegotiationSession;
11import agents.anac.y2014.BraveCat.necessaryClasses.Schedular;
12import genius.core.bidding.BidDetails;
13import genius.core.utility.NonlinearUtilitySpace;
14
15public class BRTOfferingStrategy extends OfferingStrategy {
16 private BidGenerator bidGenerator;
17 private Random random300;
18 private BidDetails LastBestBid = null;
19 private double k;
20 private double Pmax;
21 private double Pmin;
22 private double e;// This value should be adjusted by the estimated
23 // concession value of the opponent.
24
25 public BRTOfferingStrategy(NegotiationSession negoSession,
26 OpponentModel model, OMStrategy oms, double e, double k) {
27 random300 = new Random();
28 this.e = e;// beta value.
29 this.k = k;
30 this.negotiationSession = negoSession;
31 bidGenerator = new BidGenerator(negotiationSession);
32
33 if (this.negotiationSession.getUtilitySpace() instanceof NonlinearUtilitySpace)
34 System.out.println("Nonlinear Utility Space!");
35 this.omStrategy = oms;
36 try {
37 this.Pmax = 1;
38 System.out.println("Pmax: " + this.Pmax);
39 this.Pmin = this.negotiationSession.getUtilitySpace()
40 .getReservationValueUndiscounted();
41 System.out.println("Pmin: " + this.Pmin);
42 this.schedular = new Schedular(negotiationSession);
43 } catch (Exception ex) {
44 System.out
45 .println("Exception occured when determining Pmax and Pmin!");
46 }
47 }
48
49 @Override
50 public void init(NegotiationSession negoSession, OpponentModel model,
51 OMStrategy oms, HashMap<String, Double> parameters)
52 throws Exception {
53 if (parameters.get("e") != null) {
54 this.negotiationSession = negoSession;
55
56 this.e = ((Double) parameters.get("e")).doubleValue();
57
58 if (parameters.get("k") != null)
59 this.k = ((Double) parameters.get("k")).doubleValue();
60 else {
61 this.k = 0.0D;
62 }
63 if (parameters.get("min") != null)
64 this.Pmin = ((Double) parameters.get("min")).doubleValue();
65 else {
66 this.Pmin = negoSession.getMinBidinDomain()
67 .getMyUndiscountedUtil();
68 }
69 if (parameters.get("max") != null) {
70 this.Pmax = ((Double) parameters.get("max")).doubleValue();
71 } else {
72 BidDetails maxBid = negoSession.getMaxBidinDomain();
73 this.Pmax = maxBid.getMyUndiscountedUtil();
74 }
75
76 this.opponentModel = model;
77 this.omStrategy = oms;
78 } else {
79 throw new Exception(
80 "Constant \"e\" for the concession speed was not set.");
81 }
82 }
83
84 @Override
85 public BidDetails determineOpeningBid() {
86 BidDetails temp = null;
87 try {
88 temp = this.bidGenerator.selectBid(Pmax);
89 System.out.println("Opening Bid Utility is: "
90 + this.negotiationSession.getUtilitySpace().getUtility(
91 temp.getBid()));
92 } catch (Exception ex) {
93 }
94 return temp;
95 }
96
97 @Override
98 public BidDetails determineNextBid() {
99 double time = this.negotiationSession.getTime();
100
101 this.Pmin = this.negotiationSession.getUtilitySpace()
102 .getReservationValueWithDiscount(time);
103
104 // If this is the last bid, the agent chooses to send the best bid
105 // received from the opponent, so as to avoid a break off,
106 // hoping that this bid is still acceptable for the opponent, and it
107 // will result in an agreement.
108 if (this.schedular.FinalRounds() || this.schedular.LastRound())
109 return negotiationSession.getOpponentBidHistory()
110 .getBestDiscountedBidDetails(
111 negotiationSession.getUtilitySpace());
112 double targetUtility = TargetUtilityGenerator(time, this.Pmax,
113 this.Pmin, this.e, this.k);
114 // System.out.println(targetUtility);
115 targetUtility = TargetUtilityRandomizer(targetUtility);
116 // System.out.println(targetUtility);
117 try {
118 targetUtility = BehaviouralTargetUtility(targetUtility);
119 } catch (Exception ex) {
120 System.out
121 .println("Exception occured when calculating behavioral target utility!");
122 }
123 // System.out.println(targetUtility);
124 try {
125 if (targetUtility > 1)
126 targetUtility = 1;
127 } catch (Exception ex) {
128 System.out
129 .println("Exception occured when bringing the target utility into the range!");
130 }
131
132 // System.out.println(targetUtility);
133
134 if ((this.opponentModel instanceof NoModel))
135 this.nextBid = this.negotiationSession.getOutcomeSpace()
136 .getBidNearUtility(targetUtility);
137 else {
138 try {
139 this.nextBid = this.omStrategy.getBid(this.bidGenerator
140 .NBidsNearUtility(targetUtility, 10));
141 } catch (Exception ex) {
142 }
143 }
144 return this.nextBid;
145 }
146
147 public double BehaviouralTargetUtility(double targetUtility)
148 throws Exception {
149 if (LastBestBid == null) {
150 // System.out.println(this.negotiationSession.getOpponentBidHistory().size());
151 LastBestBid = this.negotiationSession.getOpponentBidHistory()
152 .getLastBidDetails();
153 return targetUtility;
154 } else {
155 if (this.negotiationSession.getUtilitySpace().getUtility(
156 LastBestBid.getBid()) < this.negotiationSession
157 .getUtilitySpace().getUtility(
158 this.negotiationSession.getOpponentBidHistory()
159 .getLastBid())) {
160 double NewUtility = targetUtility
161 - (this.negotiationSession.getUtilitySpace()
162 .getUtility(
163 this.negotiationSession
164 .getOpponentBidHistory()
165 .getLastBid()) - this.negotiationSession
166 .getUtilitySpace().getUtility(
167 LastBestBid.getBid()));
168 LastBestBid = this.negotiationSession.getOpponentBidHistory()
169 .getLastBidDetails();
170 // System.out.println(NewUtility - targetUtility);
171 return NewUtility;
172 }
173 }
174 return targetUtility;
175 }
176
177 public double TargetUtilityRandomizer(double targetUtility) {
178 Random r = new Random();
179 double z = Math.abs(r.nextGaussian());
180 return targetUtility
181 - ((double) ((1 - targetUtility) * z * (1 - this.negotiationSession
182 .getTime())) / 2.58);
183 }
184
185 public double TargetUtilityGenerator(double t, double Pmax, double Pmin,
186 double e, double k) {
187 double temp = Pmin + (Pmax - Pmin) * (1.0D - f(t, e, k));
188 return temp;
189 }
190
191 public double f(double t, double e, double k) {
192 if (e == 0.0D)
193 return k;
194 double ft = k + (1.0D - k) * Math.pow(t, 1.0D / e);
195 return ft;
196 }
197
198 public NegotiationSession getNegotiationSession() {
199 return this.negotiationSession;
200 }
201
202 public double EstimateOpponentConcession() {
203 return 1 - ((double) this.negotiationSession.getOpponentBidHistory().numberOfUniqueBidsInBidHistory / this.negotiationSession
204 .getOpponentBidHistory().numberOfTotalBidsInBidHistory);
205 }
206
207 @Override
208 public String GetName() {
209 return "BRTOfferingStrategy";
210 }
211}
Note: See TracBrowser for help on using the repository browser.