1 | package bargainingchips.utilityfunctions;
|
---|
2 |
|
---|
3 |
|
---|
4 | import bargainingchips.Bundle;
|
---|
5 | import bargainingchips.BundleBuilder;
|
---|
6 | import bargainingchips.Chip;
|
---|
7 | import bargainingchips.ChipIssueValue;
|
---|
8 | import bargainingchips.ChipIssueValueBuilder;
|
---|
9 | //import bargainingchips.utilityfunctions.helperMethods;
|
---|
10 | import bargainingchips.wishlist.WishList;
|
---|
11 | import bargainingchips.wishlist.WishListBuilder;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | *
|
---|
15 | * This utility function inputs {@link wishList} (i.e., quantity of each desired {@link Chip}), and price per each
|
---|
16 | * {@link Chip} as curves, flattened at peak.
|
---|
17 | * For quantity, the buyer may accept, with degrees of satisfaction, offered quantity around the peak, which is
|
---|
18 | * determined by the deviation from the peak per each {@link Chip}. It is in a Guassian form.
|
---|
19 | * For the price, the buyer would designate the 2 points, so that they determine the left peaked flat part and the
|
---|
20 | * right downward curve of prices per each {@link Chip}. The prices could be in integer or real format, determined
|
---|
21 | * by type T[] (i.e, `Integer[]' or `Double[]', etc). Actually, the second point determines the buyer's budget for
|
---|
22 | * the {@link Chip} (i.e., RV, the reservation value), and the flat part determines AV (the aspiration value).
|
---|
23 | * It is worth to mention that this function considers the importance of issues (i.e., for price, quantity, etc.)
|
---|
24 | * as well as the importance of Chips (i.e., colors) with respect to each other.
|
---|
25 | *
|
---|
26 | *
|
---|
27 | * @author Faria Nassiri-Mofakham
|
---|
28 | *
|
---|
29 | */
|
---|
30 |
|
---|
31 | public class UF_PeakedFlatCurvePriceGaussianQuantity<T> implements UtilityFunction {
|
---|
32 | // T for the type of `price' data points
|
---|
33 |
|
---|
34 | private WishList wishlist; // the exact wished quantity per each Chip
|
---|
35 | // Other parts of the buyer's preferences are assigned with desirability degrees of a variety of prices and quantities per each Chip.
|
---|
36 | private ChipIssueValue<Integer> qtyDeviation; // sigma_c. A symmetric deviation considered for quantities less than or more than the exact qty per chip.
|
---|
37 | private ChipIssueValue<T[]> flatCurvePrice; // list of `2' data points of type T determining the price curve
|
---|
38 | private ChipIssueValue<Double> uFlatCurve; // utility in jumping from flat to curve at the first data point
|
---|
39 | private ChipIssueValue<Double> lambdaC; // importance of each Chip (i.e, color)
|
---|
40 | private double lambdaP,lambdaQ; // importance of issues (i.e., price, quantity, etc)
|
---|
41 |
|
---|
42 |
|
---|
43 | public UF_PeakedFlatCurvePriceGaussianQuantity(WishList w, ChipIssueValue<T[]> price, ChipIssueValue<Double> uPrice, ChipIssueValue<Integer> qtyDev, ChipIssueValue<Double> lc, double lp, double lq)
|
---|
44 | {
|
---|
45 | wishlist=w;
|
---|
46 | qtyDeviation=qtyDev;
|
---|
47 | flatCurvePrice=price;
|
---|
48 | uFlatCurve=uPrice;
|
---|
49 | lambdaC=lc;
|
---|
50 | lambdaP=lp;
|
---|
51 | lambdaQ=lq;
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public Double getUtility(Bundle b)
|
---|
56 | {
|
---|
57 | double sumWeightedPrice = 0.0;
|
---|
58 | double sumWeightedQty = 0.0;
|
---|
59 |
|
---|
60 | if (b!=null)
|
---|
61 | {
|
---|
62 | for (Chip c : wishlist)
|
---|
63 | {
|
---|
64 | int desiredQ = wishlist.getQuantity(c);
|
---|
65 | T[] desiredP = flatCurvePrice.getUnitValue(c);
|
---|
66 | if (desiredP.length > 2)
|
---|
67 | throw new IllegalStateException("\n\n[Warning] UF_PeakedFlatCurvePriceAndGaussianQuantity::getUtility(Bundle). Input only 2 price data points! "+ desiredP);
|
---|
68 | Double uPrice = uFlatCurve.getUnitValue(c);
|
---|
69 | Double importanceC= lambdaC.getUnitValue(c);
|
---|
70 | int devC= qtyDeviation.getUnitValue(c);
|
---|
71 |
|
---|
72 | Integer offeredQ = b.getQuantity(c);
|
---|
73 | if (offeredQ == null)
|
---|
74 | offeredQ = 0;
|
---|
75 | Double offeredP= b.getUnitPrice(c);
|
---|
76 |
|
---|
77 | sumWeightedPrice += importanceC * flatCurve(desiredP, uPrice, offeredP);
|
---|
78 | sumWeightedQty += importanceC / (devC * 2 * Math.sqrt(Math.PI)) * Math.pow(Math.E, -0.5 * Math.pow((offeredQ - desiredQ)/devC, 2));
|
---|
79 | }
|
---|
80 | double u = lambdaP * sumWeightedPrice + lambdaQ * sumWeightedQty;
|
---|
81 | return ( (u>1) ? 1 : ( (u<0) ? 0 : u) );
|
---|
82 | }
|
---|
83 | return 0.0;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * @param input parameter (e.g., an offered price per a {@link Chip},
|
---|
88 | * and `n' data points of type T (e.g., as of Double[], Integer[], etc).
|
---|
89 | *
|
---|
90 | * @return Bezier value of rank `n' for the offered parameter.
|
---|
91 | **/
|
---|
92 | private double flatCurve(T[] desired, Double uDesired, Double offered)
|
---|
93 | {
|
---|
94 | Double data[] = (Double[]) desired;
|
---|
95 | double fc = ( (offered <= data[0]) ? 1.0 : ( (offered > data[1]) ? 0.0 : uDesired * (offered - data[1]) / (data[0]-data[1]) ));
|
---|
96 | return ( (fc>1) ? 1 : (fc<0) ? 0 : fc);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * @return an String list of values assigned to a single variable, e.g. list of quantities or prices of a {@link Chip}
|
---|
101 | **/
|
---|
102 | private String writeT(ChipIssueValue<T[]> t)
|
---|
103 | {
|
---|
104 | String s = "{";
|
---|
105 | T[] j;
|
---|
106 | if (t!=null)
|
---|
107 | {
|
---|
108 | for (Chip c: t)
|
---|
109 | {
|
---|
110 | s += " " + c.toString() + "={";
|
---|
111 | j = t.getUnitValue(c);
|
---|
112 | for (int k=0; k<j.length; k++)
|
---|
113 | s += j[k].toString()+((k<j.length-1) ? ", " : "");
|
---|
114 | s += "}";
|
---|
115 | }
|
---|
116 | }
|
---|
117 | s += " }";
|
---|
118 | return s;
|
---|
119 | }
|
---|
120 |
|
---|
121 | @Override
|
---|
122 | public String toString()
|
---|
123 | {
|
---|
124 | return this.getClass().getSimpleName() + ": WishList " + wishlist + ": FlatCurvePrice "+ writeT(flatCurvePrice)+ ": uFlatCurvePrice" + uFlatCurve + ": QtyDeviations "+ qtyDeviation + ": Colors' weights "+ lambdaC + ": Issue Price's weight "+ lambdaP + ": Issue Quantity's weight " + lambdaQ;
|
---|
125 | }
|
---|
126 |
|
---|
127 | public static void main(String[] args)
|
---|
128 | {
|
---|
129 | WishList wishlist = new WishListBuilder().addWish("Green", 4).addWish("Yellow", 6).addWish("Orange", 40).build();
|
---|
130 | ChipIssueValue<Double[]> prices = new ChipIssueValueBuilder<Double[]>().addIssue("Green", new Double[] {3.0, 4.8}).addIssue("Yellow", new Double[] {5.0, 8.0}).addIssue("Orange", new Double[] {1.0, 2.5}).build();
|
---|
131 | ChipIssueValue<Double> uPrices = new ChipIssueValueBuilder<Double>().addIssue("Green", 1.0).addIssue("Yellow", 0.8).addIssue("Orange", 0.75).build();
|
---|
132 | ChipIssueValue<Integer> deviations = new ChipIssueValueBuilder<Integer>().addIssue("Green", 1).addIssue("Yellow", 1).addIssue("Orange", 10).build();
|
---|
133 | ChipIssueValue<Double> wC = new ChipIssueValueBuilder<Double>().addIssue("Green", 0.5).addIssue("Yellow", 0.3).addIssue("Orange", 0.2).build();
|
---|
134 | double wP = 0.6;
|
---|
135 | double wQ = 0.4;
|
---|
136 |
|
---|
137 | UF_PeakedFlatCurvePriceGaussianQuantity<Double> u = new UF_PeakedFlatCurvePriceGaussianQuantity<Double> (wishlist, prices, uPrices, deviations, wC, wP, wQ);
|
---|
138 | System.out.println(u);
|
---|
139 |
|
---|
140 | Bundle offer = new BundleBuilder()
|
---|
141 | .addStack("Green", 2.0, 3)
|
---|
142 | .addStack("Yellow", 5.0, 4)
|
---|
143 | .addStack("Orange", 1.0, 17)
|
---|
144 | //---
|
---|
145 | // .addStack("Green", 3.0, 4) //should give utility 1.0 in weighted additive
|
---|
146 | // .addStack("Yellow", 5.0, 6)
|
---|
147 | // .addStack("Orange", 1.0, 40)
|
---|
148 | //---
|
---|
149 | // .addStack("Green", 10.0, 1) //should give utility 0.0 in weighted additive
|
---|
150 | // .addStack("Yellow", 10.0, 1)
|
---|
151 | // .addStack("Orange", 10.0, 1)
|
---|
152 | //---
|
---|
153 | // .addStack("Red", 1.0, 6)
|
---|
154 | // .addStack("Green", 3.0, 15)
|
---|
155 | // .addStack("Purple", 0.10, 10)
|
---|
156 | .build();
|
---|
157 | System.out.println(u.getUtility(offer));
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|