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

Last change on this file since 340 was 340, checked in by Tim Baarslag, 4 years ago

Change BilateralProtocol loop to avoid busy wait; note that this fixes only a part of the busy wait problem.

Package structure now in line with latest Acumex discussions.

Pinpointed error avoidance in Agent.

File size: 5.8 KB
RevLine 
[316]1package bargainingchips.utilityfunctions;
[315]2
[316]3import bargainingchips.Bundle;
[338]4import bargainingchips.BundleBuilder;
[316]5import bargainingchips.Chip;
[338]6import bargainingchips.ChipIssueValue;
7import bargainingchips.ChipIssueValueBuilder;
[340]8import bargainingchips.wishlist.WishList;
9import bargainingchips.wishlist.WishListBuilder;
[315]10
11/**
12 *
[338]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.
[315]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
[338]16 * upward function respectively for quantities more than or less than the desired quantity, both with a peak at the desired quantity.
[315]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 *
[338]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 ]
[315]31 *
32 * where,
[338]33 * \psi_c = 1, if q_c >= \kappa_c, otherwise, \psi_c = -1.
[315]34 * \lambda_p + \lambda_q = 1
35 * \sum{\lambda_c} = 1
36 *
37 *
38 *
39 * @author Faria Nassiri-Mofakham
40 *
41 */
[338]42public class UF_PeakedPricePeakedQuantity implements UtilityFunction {
[315]43
[338]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
[315]50
51
[338]52 public UF_PeakedPricePeakedQuantity(WishList w, ChipIssueValue<Double> bEP, ChipIssueValue<Integer> qtyDev, ChipIssueValue<Double> lc, double lp, double lq)
[315]53 {
54 wishlist=w;
55 qtyDeviation=qtyDev;
56 breakEvenPrice=bEP;
[338]57 lambdaC=lc;
58 lambdaP=lp;
[315]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
[338]78 Integer offeredQ = b.getQuantity(c);
79 if (offeredQ == null)
80 offeredQ = 0;
81 Double offeredP= b.getUnitPrice(c);
[315]82
[338]83 int mC = ((offeredQ >= desiredQ) ? 1 : -1);
[315]84
[338]85 sumWeightedPriceOffered += importanceC * offeredP * offeredQ;
86 sumWeightedPriceDesired += importanceC * desiredP * desiredQ;
87 sumWeightedQty += importanceC * mC * (desiredQ + mC * devC - offeredQ)/devC;
[315]88 }
[338]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) );
[315]92 }
93 return 0.0;
94 }
95
96
97 @Override
98 public String toString()
99 {
[338]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;
[315]101 }
[338]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.