1 | /**
|
---|
2 | *
|
---|
3 | */
|
---|
4 | package bargainingchips.utilityfunctions;
|
---|
5 |
|
---|
6 | import bargainingchips.Bundle;
|
---|
7 | import bargainingchips.BundleBuilder;
|
---|
8 | import bargainingchips.Chip;
|
---|
9 | import bargainingchips.ChipIssueValue;
|
---|
10 | import bargainingchips.ChipIssueValueBuilder;
|
---|
11 | import bargainingchips.wishlist.WishList;
|
---|
12 | import bargainingchips.wishlist.WishListBuilder;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | *
|
---|
16 | * If total price of the offered bundle is higher that the total price of the Wishlist, returns 0.0.
|
---|
17 | * Otherwise, it evaluates the offered bundle based on its price ratio (with respect to the Wishlist).
|
---|
18 | *
|
---|
19 | * As specific cases, when the unit prices are equal but the total price regarding the quantities,
|
---|
20 | * it evaluates the offer as 0.0. Moreover, in case of chip unit prices where the total price regarding
|
---|
21 | * the offered quantities is equal or less than the total desired price, it returns 1.0.
|
---|
22 | *
|
---|
23 | * For other cases, this ignoring quantity utility function returns a value between 0.0 and 1.0.
|
---|
24 | *
|
---|
25 | *
|
---|
26 | * @author Faria Nassiri-Mofakham
|
---|
27 | *
|
---|
28 | */
|
---|
29 | public class UF_LessPrice implements UtilityFunction {
|
---|
30 |
|
---|
31 | private WishList wishlist;
|
---|
32 | private ChipIssueValue<Double> breakEvenPrices;
|
---|
33 |
|
---|
34 | public UF_LessPrice(WishList w, ChipIssueValue<Double> bEP)
|
---|
35 | {
|
---|
36 | this.wishlist = w;
|
---|
37 | this.breakEvenPrices = bEP;
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public Double getUtility(Bundle b)
|
---|
43 | {
|
---|
44 | double desired=0.0;
|
---|
45 | for (Chip c : wishlist)
|
---|
46 | desired += ((c!=null) ? ((breakEvenPrices.getUnitValue(c)>0.0) ? breakEvenPrices.getUnitValue(c) : 0.0): 0.0);
|
---|
47 | double offered = (b!=null ? b.getTotalPrice() : 0.0);
|
---|
48 | // System.out.println("offered " + offered + " desired " + desired);
|
---|
49 | return ((offered > desired) ? 0.0 : 1.0 - offered/desired);
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public String toString()
|
---|
54 | {
|
---|
55 | return this.getClass().getSimpleName() + ": WishList " + wishlist.toString() + ": BreakEvenPrices "+ breakEvenPrices.toString();
|
---|
56 | }
|
---|
57 |
|
---|
58 | public static void main(String[] args)
|
---|
59 | {
|
---|
60 | WishList wishlist1 = new WishListBuilder().addWish("Red", 7).addWish("Green", 5).build();
|
---|
61 | ChipIssueValue<Double> prices1 = new ChipIssueValueBuilder<Double>().addIssue("Red", 100.0).addIssue("Green", 200.0).addIssue("Blue", 700.0).build();
|
---|
62 |
|
---|
63 | UF_LessPrice u1 = new UF_LessPrice(wishlist1, prices1);
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | WishList wishlist2 = new WishListBuilder().addWish("Red", 7).addWish("Green", 5).build();
|
---|
68 | ChipIssueValue<Double> prices2 = new ChipIssueValueBuilder<Double>().addIssue("Red", 10.0).addIssue("Green", 20.0).addIssue("Blue", 70.0).build();
|
---|
69 |
|
---|
70 | UF_LessPrice u2 = new UF_LessPrice(wishlist2, prices2);
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 | WishList wishlist3 = new WishListBuilder().addWish("Green", 4).addWish("Yellow", 6).addWish("Orange", 40).build();
|
---|
75 | ChipIssueValue<Double> prices3 = new ChipIssueValueBuilder<Double>().addIssue("Green", 3.0).addIssue("Yellow", 5.0).addIssue("Orange", 1.0).build();
|
---|
76 |
|
---|
77 | UF_LessPrice u3 = new UF_LessPrice(wishlist3, prices3);
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | Bundle offer1 = new BundleBuilder()
|
---|
82 | .addStack("Red", 1.0, 6)
|
---|
83 | .addStack("Green", 3.0, 15)
|
---|
84 | .addStack("Purple", 0.10, 10)
|
---|
85 | .build();
|
---|
86 |
|
---|
87 | Bundle offer2 = new BundleBuilder()
|
---|
88 | .addStack("Red", 1.0, 1)
|
---|
89 | .addStack("Green", 3.0, 1)
|
---|
90 | .addStack("Purple", 0.10, 1)
|
---|
91 | .build();
|
---|
92 |
|
---|
93 | Bundle offer3 = new BundleBuilder()
|
---|
94 | // .addStack("Green", 2.0, 3)
|
---|
95 | // .addStack("Yellow", 5.0, 4)
|
---|
96 | // .addStack("Orange", 1.0, 17)
|
---|
97 | //---
|
---|
98 | .addStack("Green", 3.0, 4)
|
---|
99 | .addStack("Yellow", 5.0, 6)
|
---|
100 | .addStack("Orange", 1.0, 40)
|
---|
101 | //---
|
---|
102 | // .addStack("Green", 10.0, 1)
|
---|
103 | // .addStack("Yellow", 10.0, 1)
|
---|
104 | // .addStack("Orange", 10.0, 1)
|
---|
105 | .build();
|
---|
106 |
|
---|
107 | System.out.println("\nu1 : "+u1 +"\nOffer1 = "+offer1);
|
---|
108 | System.out.println("=> "+u1.getUtility(offer1));
|
---|
109 | System.out.println("\nu1 : "+u1 +"\nOffer2 = "+offer2);
|
---|
110 | System.out.println("=> "+u1.getUtility(offer2));
|
---|
111 | System.out.println("\nu1 : "+u1 +"\nOffer3 = "+offer3);
|
---|
112 | System.out.println("=> "+u1.getUtility(offer3));
|
---|
113 |
|
---|
114 | System.out.println("\nu2 : "+u2 +"\nOffer1 = "+offer1);
|
---|
115 | System.out.println("=> "+u2.getUtility(offer1));
|
---|
116 | System.out.println("\nu2 : "+u2 +"\nOffer2 = "+offer2);
|
---|
117 | System.out.println("=> "+u2.getUtility(offer2));
|
---|
118 | System.out.println("\nu2 : "+u2 +"\nOffer3 = "+offer3);
|
---|
119 | System.out.println("=> "+u2.getUtility(offer3));
|
---|
120 |
|
---|
121 | System.out.println("\nu3 : "+u3 +"\nOffer1 = "+offer1);
|
---|
122 | System.out.println("=> "+u3.getUtility(offer1));
|
---|
123 | System.out.println("\nu3 : "+u3 +"\nOffer2 = "+offer2);
|
---|
124 | System.out.println("=> "+u3.getUtility(offer2));
|
---|
125 | System.out.println("\nu3 : "+u3 +"\nOffer3 = "+offer3);
|
---|
126 | System.out.println("=> "+u3.getUtility(offer3));
|
---|
127 | }
|
---|
128 | }
|
---|