source: src/main/java/bargainingchips/utilityfunctions/UF_PeakedPricePeakedQuantity.java@ 338

Last change on this file since 338 was 338, checked in by Faria Nassiri Mofakham, 5 years ago

An extended version of Buyer (BuyerExtended), which can be constructed using one among many utility functions. UF_LessPrice and seven complex utility functions based on price+quantity and two types of weights: UF_LessPriceCloseToQuantity, UF_IntensifiedLessPriceCloseToQuantity, UF_PeakedPricePeakedQuantity, UF_PeakedFlatPricePeakedFlatQuantity, UF_PeakedFlatCurvePriceGaussianQuantity, UF_BezierPriceBezierQuantity, and UF_BezierPriceGaussianQuantity. Two more fundamental helper classes: ChipIssueValue, ChipIssueValueBuilder. Adding a validity check to Stack. An update in Bundle main. Adding getSampleBid function to Bid. An update in k variable in Agent. A UF class and UtilityHelperMethods for individual passing utility functions. Adding some more tests in UF_CloseToQuantity main. An update on BundleTest.

File size: 5.8 KB
Line 
1package bargainingchips.utilityfunctions;
2
3import bargainingchips.Bundle;
4import bargainingchips.BundleBuilder;
5import bargainingchips.Chip;
6import bargainingchips.ChipIssueValue;
7import bargainingchips.ChipIssueValueBuilder;
8import bargainingchips.WishList;
9import bargainingchips.WishListBuilder;
10
11/**
12 *
13 * According to Equation (1), the buyer with peaked utility function evaluates bundles with price 0, as 1.0, and any price greater than the total break even unit price of the chips in the bundle, as 0.0.
14 * For any other price between the two, she follows a linear downward function. However, regarding the quantity she checks per chip, so that if the quantity of the chip is equal to what she wished, it gets 1.0.
15 * She may tolerate a deviation around this desired quantity. Any quantity outside this range would be evaluated as 0.0. The quantities within this range would be evaluated via a linear downward function and linear
16 * upward function respectively for quantities more than or less than the desired quantity, both with a peak at the desired quantity.
17 *
18 * UF_peaked ignores any color which is not introduced in wishlist (i.e., free disposal) and takes the following values as input:
19 * \phi_c, \kappa_c, \sigma_c, and \lambda_c, respectively the break even unit price, the exact quantity, the acceptable deviation around \kappa_c,
20 * the importance of the chip with color c,
21 * p_c, q_c, \lambda_q, and \lambda_p, respectively the unit price, quantity of the chip with color c and the importance of quantity and price in offer \omega
22 *
23 * And outputs u(\omega), where \omega is the offer to evaluate.
24 *
25 *
26 * Equation (1):
27 *
28 * UF_PeakedPricePeakedQuantity(Bundle \omega) = \lambda_p [ 1 - ( \sum{\lambda_c * \phi_c * \kappa_c}
29 * - \sum{\lambda_c * p_c * q_c}) / \sum{\lambda_c * \phi_c * \kappa_c} ]
30 * + \lambda_q [ \lambda_c * \psi_c * (\kappa_c + \psi_c * \sigma_c - q_c) / \sigma_c ]
31 *
32 * where,
33 * \psi_c = 1, if q_c >= \kappa_c, otherwise, \psi_c = -1.
34 * \lambda_p + \lambda_q = 1
35 * \sum{\lambda_c} = 1
36 *
37 *
38 *
39 * @author Faria Nassiri-Mofakham
40 *
41 */
42public class UF_PeakedPricePeakedQuantity implements UtilityFunction {
43
44 private WishList wishlist; // q_c
45 // Other parts of the buyer's preferences are assigned with desirability degrees of a variety of prices and quantities per each Chip.
46 private ChipIssueValue<Integer> qtyDeviation; // sigma_c. Assuming a symmetric deviation. Of course, two different deviation could also be considered
47 // for quantities less or more than the exact qty per chip
48 private ChipIssueValue<Double> breakEvenPrice, lambdaC; // kappa_c and lambda_c
49 private double lambdaP,lambdaQ; // lambda_p and lambda_q
50
51
52 public UF_PeakedPricePeakedQuantity(WishList w, ChipIssueValue<Double> bEP, ChipIssueValue<Integer> qtyDev, ChipIssueValue<Double> lc, double lp, double lq)
53 {
54 wishlist=w;
55 qtyDeviation=qtyDev;
56 breakEvenPrice=bEP;
57 lambdaC=lc;
58 lambdaP=lp;
59 lambdaQ=lq;
60 }
61
62 @Override
63 public Double getUtility(Bundle b)
64 {
65 double sumWeightedPriceOffered=0.0;
66 double sumWeightedPriceDesired=0.0;
67 double sumWeightedQty=0.0;
68
69 if (b!=null)
70 {
71 for (Chip c : wishlist)
72 {
73 int desiredQ = wishlist.getQuantity(c);
74 Double desiredP= breakEvenPrice.getUnitValue(c);
75 Double importanceC= lambdaC.getUnitValue(c);
76 int devC= qtyDeviation.getUnitValue(c);
77
78 Integer offeredQ = b.getQuantity(c);
79 if (offeredQ == null)
80 offeredQ = 0;
81 Double offeredP= b.getUnitPrice(c);
82
83 int mC = ((offeredQ >= desiredQ) ? 1 : -1);
84
85 sumWeightedPriceOffered += importanceC * offeredP * offeredQ;
86 sumWeightedPriceDesired += importanceC * desiredP * desiredQ;
87 sumWeightedQty += importanceC * mC * (desiredQ + mC * devC - offeredQ)/devC;
88 }
89 double u = lambdaP * (1 - (sumWeightedPriceOffered-sumWeightedPriceDesired)/sumWeightedPriceDesired) + lambdaQ * sumWeightedQty; //after changing the signs of sums
90
91 return ( (u>1) ? 1 : ( (u<0) ? 0 : u) );
92 }
93 return 0.0;
94 }
95
96
97 @Override
98 public String toString()
99 {
100 return this.getClass().getSimpleName() + ": WishList " + wishlist + ": BreakEvenPrices "+ breakEvenPrice.toString()+ ": QtyDeviations "+ qtyDeviation + ": Colors' weights "+ lambdaC + ": Issue Price's weight "+ lambdaP + ": Issue Quantity's weight " + lambdaQ;
101 }
102
103 public static void main(String[] args)
104 {
105 WishList wishlist = new WishListBuilder().addWish("Green", 4).addWish("Yellow", 6).addWish("Orange", 40).build();
106 ChipIssueValue<Double> prices = new ChipIssueValueBuilder<Double>().addIssue("Green", 3.0).addIssue("Yellow", 5.0).addIssue("Orange", 1.0).build();
107 ChipIssueValue<Integer> deviations = new ChipIssueValueBuilder<Integer>().addIssue("Green", 1).addIssue("Yellow", 1).addIssue("Orange", 10).build();
108 ChipIssueValue<Double> wC = new ChipIssueValueBuilder<Double>().addIssue("Green", 0.5).addIssue("Yellow", 0.3).addIssue("Orange", 0.2).build();
109 double wP = 0.6;
110 double wQ = 0.4;
111
112 UF_PeakedPricePeakedQuantity u = new UF_PeakedPricePeakedQuantity (wishlist, prices, deviations, wC, wP, wQ);
113 System.out.println(u);
114
115 Bundle offer = new BundleBuilder()
116 .addStack("Green", 2.0, 3)
117 .addStack("Yellow", 5.0, 4)
118 .addStack("Orange", 1.0, 17)
119//---
120// .addStack("Green", 3.0, 4) //should give utility 1.0
121// .addStack("Yellow", 5.0, 6)
122// .addStack("Orange", 1.0, 40)
123//---
124// .addStack("Green", 10.0, 1) //should give utility 0.0
125// .addStack("Yellow", 10.0, 1)
126// .addStack("Orange", 10.0, 1)
127//---
128// .addStack("Red", 1.0, 6)
129// .addStack("Green", 3.0, 15)
130// .addStack("Purple", 0.10, 10)
131 .build();
132 System.out.println(u.getUtility(offer));
133 }
134}
135
Note: See TracBrowser for help on using the repository browser.