[338] | 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;
|
---|
[340] | 11 | import bargainingchips.wishlist.WishList;
|
---|
| 12 | import bargainingchips.wishlist.WishListBuilder;
|
---|
[338] | 13 |
|
---|
| 14 | /**
|
---|
| 15 | *
|
---|
| 16 | * This utility function evaluates the utility of an offer based on its separate utilities regarding the ratio of its total price {@link UF_LessPrice}
|
---|
| 17 | * with respect to the break even prices as well as the total deviation of the chips quantities {@link UF_CloseToQuantity} by considering the importance of price vs. quantity.
|
---|
| 18 | * It calculates two separate utility functions uP for total offered vs. desired prices as well as uQ for total offered vs desired quantities.
|
---|
| 19 | * The utility of the offered bundle is then is calculated by uP * uQ (dependent values).
|
---|
| 20 | *
|
---|
| 21 | *
|
---|
| 22 | * @author Faria Nassiri-Mofakham
|
---|
| 23 | *
|
---|
| 24 | */
|
---|
| 25 | public class UF_LessPriceCloseToQuantity implements UtilityFunction {
|
---|
| 26 |
|
---|
| 27 | private WishList wishlist;
|
---|
| 28 | private ChipIssueValue<Double> breakEvenPrices;
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | public UF_LessPriceCloseToQuantity(WishList w, ChipIssueValue<Double> bEP)
|
---|
| 32 | {
|
---|
| 33 | this.wishlist = w;
|
---|
| 34 | this.breakEvenPrices = bEP;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | @Override
|
---|
| 39 | public Double getUtility(Bundle b)
|
---|
| 40 | {
|
---|
| 41 | int totalDeviationQ = 0;
|
---|
| 42 | double desiredP=0.0;
|
---|
| 43 | for (Chip c : wishlist)
|
---|
| 44 | {
|
---|
| 45 | int desiredQ = wishlist.getQuantity(c);
|
---|
| 46 | Integer offeredQ = b.getQuantity(c);
|
---|
| 47 | if (offeredQ == null)
|
---|
| 48 | offeredQ = 0;
|
---|
| 49 |
|
---|
| 50 | int deviationOfferedQ = Math.abs(desiredQ - offeredQ);
|
---|
| 51 | totalDeviationQ += deviationOfferedQ;
|
---|
| 52 |
|
---|
| 53 | desiredP += ((c!=null) ? breakEvenPrices.getUnitValue(c) : 0.0);
|
---|
| 54 | }
|
---|
| 55 | double offeredP = ((b!=null) ? b.getTotalPrice() : 0.0);
|
---|
| 56 | if (offeredP > desiredP)
|
---|
| 57 | {
|
---|
| 58 | //System.out.println("offeredPrice "+ offeredP + " > desiredPrice "+ desiredP);
|
---|
| 59 | return 0.0;
|
---|
| 60 | }
|
---|
| 61 | double uP = 1.0 - offeredP/desiredP;
|
---|
| 62 | double uQ = 1.0 / (1 + totalDeviationQ);
|
---|
| 63 |
|
---|
| 64 | //System.out.println("uP "+uP+"\n"+"uQ "+uQ);
|
---|
| 65 |
|
---|
| 66 | double u = uP * uQ;
|
---|
| 67 | return ( Double.isNaN(u)? 0.0 : ( (u>1) ? 1 : ( u < 0) ? 0 : u));
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | @Override
|
---|
| 71 | public String toString()
|
---|
| 72 | {
|
---|
| 73 | return this.getClass().getSimpleName() + ": WishList " + wishlist.toString() + ": BreakEvenPrices "+ breakEvenPrices.toString();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public static void main(String[] args)
|
---|
| 77 | {
|
---|
| 78 |
|
---|
| 79 | WishList wishlist1 = new WishListBuilder().addWish("Red", 7).addWish("Green", 5).build();
|
---|
| 80 | ChipIssueValue<Double> prices1 = new ChipIssueValueBuilder<Double>().addIssue("Red", 100.0).addIssue("Green", 200.0).addIssue("Blue", 700.0).build();
|
---|
| 81 |
|
---|
| 82 | UF_LessPriceCloseToQuantity u1 = new UF_LessPriceCloseToQuantity(wishlist1, prices1);
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | WishList wishlist2 = new WishListBuilder().addWish("Red", 7).addWish("Green", 5).build();
|
---|
| 87 | ChipIssueValue<Double> prices2 = new ChipIssueValueBuilder<Double>().addIssue("Red", 10.0).addIssue("Green", 20.0).addIssue("Blue", 70.0).build();
|
---|
| 88 |
|
---|
| 89 | UF_LessPriceCloseToQuantity u2 = new UF_LessPriceCloseToQuantity(wishlist2, prices2);
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | WishList wishlist3 = new WishListBuilder().addWish("Green", 4).addWish("Yellow", 6).addWish("Orange", 40).build();
|
---|
| 94 | ChipIssueValue<Double> prices3 = new ChipIssueValueBuilder<Double>().addIssue("Green", 3.0).addIssue("Yellow", 5.0).addIssue("Orange", 1.0).build();
|
---|
| 95 |
|
---|
| 96 | UF_LessPriceCloseToQuantity u3 = new UF_LessPriceCloseToQuantity(wishlist3, prices3);
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | Bundle offer1 = new BundleBuilder()
|
---|
| 101 | .addStack("Red", 1.0, 6)
|
---|
| 102 | .addStack("Green", 3.0, 15)
|
---|
| 103 | .addStack("Purple", 0.10, 10)
|
---|
| 104 | .build();
|
---|
| 105 |
|
---|
| 106 | Bundle offer2 = new BundleBuilder()
|
---|
| 107 | .addStack("Red", 1.0, 1)
|
---|
| 108 | .addStack("Green", 3.0, 1)
|
---|
| 109 | .addStack("Purple", 0.10, 1)
|
---|
| 110 | .build();
|
---|
| 111 |
|
---|
| 112 | Bundle offer3 = new BundleBuilder()
|
---|
| 113 | // .addStack("Green", 2.0, 3)
|
---|
| 114 | // .addStack("Yellow", 5.0, 4)
|
---|
| 115 | // .addStack("Orange", 1.0, 17)
|
---|
| 116 | //---
|
---|
| 117 | .addStack("Green", 3.0, 4)
|
---|
| 118 | .addStack("Yellow", 5.0, 6)
|
---|
| 119 | .addStack("Orange", 1.0, 40)
|
---|
| 120 | //---
|
---|
| 121 | // .addStack("Green", 10.0, 1)
|
---|
| 122 | // .addStack("Yellow", 10.0, 1)
|
---|
| 123 | // .addStack("Orange", 10.0, 1)
|
---|
| 124 | .build();
|
---|
| 125 |
|
---|
| 126 | System.out.println("\nu1 : "+u1 +"\nOffer1 = "+offer1);
|
---|
| 127 | System.out.println("=> "+u1.getUtility(offer1));
|
---|
| 128 | System.out.println("\nu1 : "+u1 +"\nOffer2 = "+offer2);
|
---|
| 129 | System.out.println("=> "+u1.getUtility(offer2));
|
---|
| 130 | System.out.println("\nu1 : "+u1 +"\nOffer3 = "+offer3);
|
---|
| 131 | System.out.println("=> "+u1.getUtility(offer3));
|
---|
| 132 |
|
---|
| 133 | System.out.println("\nu2 : "+u2 +"\nOffer1 = "+offer1);
|
---|
| 134 | System.out.println("=> "+u2.getUtility(offer1));
|
---|
| 135 | System.out.println("\nu2 : "+u2 +"\nOffer2 = "+offer2);
|
---|
| 136 | System.out.println("=> "+u2.getUtility(offer2));
|
---|
| 137 | System.out.println("\nu2 : "+u2 +"\nOffer3 = "+offer3);
|
---|
| 138 | System.out.println("=> "+u2.getUtility(offer3));
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | System.out.println("\nu3 : "+u3 +"\nOffer1 = "+offer1);
|
---|
| 142 | System.out.println("=> "+u3.getUtility(offer1));
|
---|
| 143 | System.out.println("\nu3 : "+u3 +"\nOffer2 = "+offer2);
|
---|
| 144 | System.out.println("=> "+u3.getUtility(offer2));
|
---|
| 145 | System.out.println("\nu3 : "+u3 +"\nOffer3 = "+offer3);
|
---|
| 146 | System.out.println("=> "+u3.getUtility(offer3));
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | }
|
---|