source: src/main/java/onetomany/bargainingchipsgame/players/utilityfunction/UF_Peaked.java@ 298

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

UF_Peaked comments

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