package bargainingchips.utilityfunctions; import bargainingchips.Bundle; import bargainingchips.BundleBuilder; import bargainingchips.Chip; import bargainingchips.ChipIssueValue; import bargainingchips.ChipIssueValueBuilder; import bargainingchips.WishList; import bargainingchips.WishListBuilder; //import bargainingchips.utilityfunctions.helperMethods; /** * * This utility function inputs {@link wishList} (i.e., quantity of each desired {@link Chip}), and price per each * {@link Chip} as curves, flattened at peak. * For quantity, the buyer may accept, with degrees of satisfaction, offered quantity around the peak, which is * determined by the deviation from the peak per each {@link Chip}. It is in a Guassian form. * For the price, the buyer would designate the 2 points, so that they determine the left peaked flat part and the * right downward curve of prices per each {@link Chip}. The prices could be in integer or real format, determined * by type T[] (i.e, `Integer[]' or `Double[]', etc). Actually, the second point determines the buyer's budget for * the {@link Chip} (i.e., RV, the reservation value), and the flat part determines AV (the aspiration value). * It is worth to mention that this function considers the importance of issues (i.e., for price, quantity, etc.) * as well as the importance of Chips (i.e., colors) with respect to each other. * * * @author Faria Nassiri-Mofakham * */ public class UF_PeakedFlatCurvePriceGaussianQuantity implements UtilityFunction { // T for the type of `price' data points private WishList wishlist; // the exact wished quantity per each Chip // Other parts of the buyer's preferences are assigned with desirability degrees of a variety of prices and quantities per each Chip. private ChipIssueValue qtyDeviation; // sigma_c. A symmetric deviation considered for quantities less than or more than the exact qty per chip. private ChipIssueValue flatCurvePrice; // list of `2' data points of type T determining the price curve private ChipIssueValue uFlatCurve; // utility in jumping from flat to curve at the first data point private ChipIssueValue lambdaC; // importance of each Chip (i.e, color) private double lambdaP,lambdaQ; // importance of issues (i.e., price, quantity, etc) public UF_PeakedFlatCurvePriceGaussianQuantity(WishList w, ChipIssueValue price, ChipIssueValue uPrice, ChipIssueValue qtyDev, ChipIssueValue lc, double lp, double lq) { wishlist=w; qtyDeviation=qtyDev; flatCurvePrice=price; uFlatCurve=uPrice; lambdaC=lc; lambdaP=lp; lambdaQ=lq; } @Override public Double getUtility(Bundle b) { double sumWeightedPrice = 0.0; double sumWeightedQty = 0.0; if (b!=null) { for (Chip c : wishlist) { int desiredQ = wishlist.getQuantity(c); T[] desiredP = flatCurvePrice.getUnitValue(c); if (desiredP.length > 2) throw new IllegalStateException("\n\n[Warning] UF_PeakedFlatCurvePriceAndGaussianQuantity::getUtility(Bundle). Input only 2 price data points! "+ desiredP); Double uPrice = uFlatCurve.getUnitValue(c); Double importanceC= lambdaC.getUnitValue(c); int devC= qtyDeviation.getUnitValue(c); Integer offeredQ = b.getQuantity(c); if (offeredQ == null) offeredQ = 0; Double offeredP= b.getUnitPrice(c); sumWeightedPrice += importanceC * flatCurve(desiredP, uPrice, offeredP); sumWeightedQty += importanceC / (devC * 2 * Math.sqrt(Math.PI)) * Math.pow(Math.E, -0.5 * Math.pow((offeredQ - desiredQ)/devC, 2)); } double u = lambdaP * sumWeightedPrice + lambdaQ * sumWeightedQty; return ( (u>1) ? 1 : ( (u<0) ? 0 : u) ); } return 0.0; } /** * @param input parameter (e.g., an offered price per a {@link Chip}, * and `n' data points of type T (e.g., as of Double[], Integer[], etc). * * @return Bezier value of rank `n' for the offered parameter. **/ private double flatCurve(T[] desired, Double uDesired, Double offered) { Double data[] = (Double[]) desired; double fc = ( (offered <= data[0]) ? 1.0 : ( (offered > data[1]) ? 0.0 : uDesired * (offered - data[1]) / (data[0]-data[1]) )); return ( (fc>1) ? 1 : (fc<0) ? 0 : fc); } /** * @return an String list of values assigned to a single variable, e.g. list of quantities or prices of a {@link Chip} **/ private String writeT(ChipIssueValue t) { String s = "{"; T[] j; if (t!=null) { for (Chip c: t) { s += " " + c.toString() + "={"; j = t.getUnitValue(c); for (int k=0; k prices = new ChipIssueValueBuilder().addIssue("Green", new Double[] {3.0, 4.8}).addIssue("Yellow", new Double[] {5.0, 8.0}).addIssue("Orange", new Double[] {1.0, 2.5}).build(); ChipIssueValue uPrices = new ChipIssueValueBuilder().addIssue("Green", 1.0).addIssue("Yellow", 0.8).addIssue("Orange", 0.75).build(); ChipIssueValue deviations = new ChipIssueValueBuilder().addIssue("Green", 1).addIssue("Yellow", 1).addIssue("Orange", 10).build(); ChipIssueValue wC = new ChipIssueValueBuilder().addIssue("Green", 0.5).addIssue("Yellow", 0.3).addIssue("Orange", 0.2).build(); double wP = 0.6; double wQ = 0.4; UF_PeakedFlatCurvePriceGaussianQuantity u = new UF_PeakedFlatCurvePriceGaussianQuantity (wishlist, prices, uPrices, deviations, wC, wP, wQ); System.out.println(u); Bundle offer = new BundleBuilder() .addStack("Green", 2.0, 3) .addStack("Yellow", 5.0, 4) .addStack("Orange", 1.0, 17) //--- // .addStack("Green", 3.0, 4) //should give utility 1.0 in weighted additive // .addStack("Yellow", 5.0, 6) // .addStack("Orange", 1.0, 40) //--- // .addStack("Green", 10.0, 1) //should give utility 0.0 in weighted additive // .addStack("Yellow", 10.0, 1) // .addStack("Orange", 10.0, 1) //--- // .addStack("Red", 1.0, 6) // .addStack("Green", 3.0, 15) // .addStack("Purple", 0.10, 10) .build(); System.out.println(u.getUtility(offer)); } }