source: src/test/java/boaexample/TimeDependent_Offering.java@ 161

Last change on this file since 161 was 161, checked in by Tim Baarslag, 6 years ago

Reordered BOA repository and added documentation

File size: 4.7 KB
Line 
1package boaexample;
2
3import java.util.HashSet;
4import java.util.Map;
5import java.util.Set;
6
7import genius.core.bidding.BidDetails;
8import genius.core.boaframework.BOAparameter;
9import genius.core.boaframework.NegotiationSession;
10import genius.core.boaframework.NoModel;
11import genius.core.boaframework.OMStrategy;
12import genius.core.boaframework.OfferingStrategy;
13import genius.core.boaframework.OpponentModel;
14import genius.core.boaframework.SortedOutcomeSpace;
15
16/**
17 * This is an abstract class used to implement a TimeDependentAgent Strategy
18 * adapted from [1] [1] S. Shaheen Fatima Michael Wooldridge Nicholas R.
19 * Jennings Optimal Negotiation Strategies for Agents with Incomplete
20 * Information http://eprints.ecs.soton.ac.uk/6151/1/atal01.pdf
21 *
22 * The default strategy was extended to enable the usage of opponent models.
23 */
24public class TimeDependent_Offering extends OfferingStrategy {
25
26 /**
27 * k in [0, 1]. For k = 0 the agent starts with a bid of maximum utility
28 */
29 private double k;
30 /** Maximum target utility */
31 private double Pmax;
32 /** Minimum target utility */
33 private double Pmin;
34 /** Concession factor */
35 private double e;
36 /** Outcome space */
37 private SortedOutcomeSpace outcomespace;
38
39 /**
40 * Method which initializes the agent by setting all parameters. The
41 * parameter "e" is the only parameter which is required.
42 */
43 @Override
44 public void init(NegotiationSession negoSession, OpponentModel model, OMStrategy oms,
45 Map<String, Double> parameters) throws Exception {
46 super.init(negoSession, parameters);
47 if (parameters.get("e") != null) {
48 this.negotiationSession = negoSession;
49
50 outcomespace = new SortedOutcomeSpace(negotiationSession.getUtilitySpace());
51 negotiationSession.setOutcomeSpace(outcomespace);
52
53 this.e = parameters.get("e");
54
55 if (parameters.get("k") != null)
56 this.k = parameters.get("k");
57 else
58 this.k = 0;
59
60 if (parameters.get("min") != null)
61 this.Pmin = parameters.get("min");
62 else
63 this.Pmin = negoSession.getMinBidinDomain().getMyUndiscountedUtil();
64
65 if (parameters.get("max") != null) {
66 Pmax = parameters.get("max");
67 } else {
68 BidDetails maxBid = negoSession.getMaxBidinDomain();
69 Pmax = maxBid.getMyUndiscountedUtil();
70 }
71
72 this.opponentModel = model;
73
74 this.omStrategy = oms;
75 } else {
76 throw new Exception("Constant \"e\" for the concession speed was not set.");
77 }
78 }
79
80 @Override
81 public BidDetails determineOpeningBid() {
82 return determineNextBid();
83 }
84
85 /**
86 * Simple offering strategy which retrieves the target utility and looks for
87 * the nearest bid if no opponent model is specified. If an opponent model
88 * is specified, then the agent return a bid according to the opponent model
89 * strategy.
90 */
91 @Override
92 public BidDetails determineNextBid() {
93 double time = negotiationSession.getTime();
94 double utilityGoal;
95 utilityGoal = p(time);
96
97 // System.out.println("[e=" + e + ", Pmin = " +
98 // BilateralAgent.round2(Pmin) + "] t = " + BilateralAgent.round2(time)
99 // + ". Aiming for " + utilityGoal);
100
101 // if there is no opponent model available
102 if (opponentModel instanceof NoModel) {
103 nextBid = negotiationSession.getOutcomeSpace().getBidNearUtility(utilityGoal);
104 } else {
105 nextBid = omStrategy.getBid(outcomespace, utilityGoal);
106 }
107 return nextBid;
108 }
109
110 /**
111 * From [1]:
112 *
113 * A wide range of time dependent functions can be defined by varying the
114 * way in which f(t) is computed. However, functions must ensure that 0 <=
115 * f(t) <= 1, f(0) = k, and f(1) = 1.
116 *
117 * That is, the offer will always be between the value range, at the
118 * beginning it will give the initial constant and when the deadline is
119 * reached, it will offer the reservation value.
120 *
121 * For e = 0 (special case), it will behave as a Hardliner.
122 */
123 public double f(double t) {
124 if (e == 0)
125 return k;
126 double ft = k + (1 - k) * Math.pow(t, 1.0 / e);
127 return ft;
128 }
129
130 /**
131 * Makes sure the target utility with in the acceptable range according to
132 * the domain. Goes from Pmax to Pmin!
133 *
134 * @param t
135 * @return double
136 */
137 public double p(double t) {
138 return Pmin + (Pmax - Pmin) * (1 - f(t));
139 }
140
141 public NegotiationSession getNegotiationSession() {
142 return negotiationSession;
143 }
144
145 @Override
146 public Set<BOAparameter> getParameterSpec() {
147 Set<BOAparameter> set = new HashSet<BOAparameter>();
148 set.add(new BOAparameter("e", 1.0, "Concession rate"));
149 set.add(new BOAparameter("k", 0.0, "Offset"));
150 set.add(new BOAparameter("min", 0.0, "Minimum utility"));
151 set.add(new BOAparameter("max", 0.99, "Maximum utility"));
152
153 return set;
154 }
155
156 @Override
157 public String getName() {
158 return "TimeDependent Offering example";
159 }
160}
Note: See TracBrowser for help on using the repository browser.