source: src/main/java/bargainingchips/utilityfunctions/UF_Peaked.java@ 330

Last change on this file since 330 was 316, checked in by Tim Baarslag, 5 years ago

new packages complete

File size: 4.2 KB
Line 
1package bargainingchips.utilityfunctions;
2
3import bargainingchips.Bundle;
4import bargainingchips.Chip;
5import bargainingchips.ChipMappingType;
6import bargainingchips.Stack;
7import bargainingchips.WishList;
8
9/**
10 *
11 * According to Equation (1) [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.
12 * 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.
13 * 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
14 * upward function respectively for quantities greater than or less than the desired quantity, both with a peak at the desired quantity.
15 *
16 * UF_peaked ignores any color which is not introduced in wishlist (i.e., free disposal) and takes the following values as input:
17 * \phi_c, \kappa_c, \sigma_c, and \lambda_c, respectively the break even unit price, the exact quantity, the acceptable deviation around \kappa_c,
18 * the importance of the chip with color c,
19 * 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
20 *
21 * And outputs u(\omega), where \omega is the offer to evaluate.
22 *
23 *
24 * Equation (1):
25 *
26 * UF_Peacked(Bundle \omega) = \lambda_p [ ( \sum{\lambda_c * p_c * q_c} - \sum{\lambda_c * \phi_c * \kappa_c} ) / \sum{\lambda_c * \phi_c * \kappa_c} - 1 ]
27 * + \lambda_q [ (-1)^\psi_c * (q_c - \kappa_c) / \sigma_c - 1 ]
28 *
29 * where,
30 * \psi_c = 1, if q_c >= \kappa_c, otherwise, \psi_c = 0.
31 * \lambda_p + \lambda_q = 1
32 * \sum{\lambda_c} = 1
33 *
34 *
35 *
36 * Reference:
37 * [1] T. Baarslag and F. Nassiri-Mofakham, `Bargaining Chips: A Test-bed for Multi-Deal One-to-Many Negotiations', AAMAS'20, May 2020, Auckland, New Zeland.
38 *
39 *
40 *
41 * @author Faria Nassiri-Mofakham
42 *
43 */
44public class UF_Peaked implements UtilityFunction {
45
46 private WishList wishlist; //q_c
47 private ChipMappingType<Integer> qtyDeviation; // sigma_c. Assuming a symmetric deviation. Of course, two different deviation could also be considered for quantities less or more than the exact qty per chip
48 private ChipMappingType<Double> breakEvenPrice, lambdaC; // kappa_c and lambda_c
49 private double lambdaP,lambdaQ; // lambda_p and lambda_q
50
51
52 public UF_Peaked(WishList w, ChipMappingType<Integer> qtyDev, ChipMappingType<Double> bEP, ChipMappingType<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
63 @Override
64 public Double getUtility(Bundle b)
65 {
66 // TODO Auto-generated method stub
67
68 double sumWeightedPriceOffered=0.0;
69 double sumWeightedPriceDesired=0.0;
70 double sumWeightedQty=0.0;
71
72 if (b!=null)
73 {
74 for (Chip c : wishlist)
75 {
76 int desiredQ = wishlist.getQuantity(c);
77 Double desiredP= breakEvenPrice.getUnitValue(c);
78 Double importanceC= lambdaC.getUnitValue(c);
79 int devC= qtyDeviation.getUnitValue(c);
80
81
82 for (Stack s : b)
83 {
84 Integer offeredQ = b.getQuantity(c);
85 Double offeredP= b.getUnitPrice(c);
86
87 int sign = ((offeredQ >= desiredQ) ? 1 : 0);
88
89 if (s.getChip().equals(c) && offeredQ != null)
90 {
91 sumWeightedPriceOffered += importanceC * offeredP * offeredQ;
92 sumWeightedPriceDesired += importanceC * desiredP * desiredQ;
93 sumWeightedQty += importanceC * (Math.pow(-1,sign)*(offeredQ - desiredQ)/devC - 1);
94 }
95 }
96 }
97 // return lambdaP * (1- (sumWeightedPriceOffered-sumWeightedPriceDesired)/sumWeightedPriceDesired) + lambdaQ * sumWeightedQty;
98 return lambdaP * ((sumWeightedPriceOffered-sumWeightedPriceDesired)/sumWeightedPriceDesired-1) + lambdaQ * sumWeightedQty; //after changing the signs of sums
99 }
100 return 0.0;
101 }
102
103
104 @Override
105 public String toString()
106 {
107 return this.getClass().getSimpleName();
108 }
109}
Note: See TracBrowser for help on using the repository browser.