package bargainingchips.utilityfunctions; import bargainingchips.Chip; import bargainingchips.ChipIssueValue; /** * * This class contains mathematical methods helping computational procedures mostly in utility functions, * namely, * - Bezier // mathematical curve * - comb // mathematical combination * - fc // mathematical factorial * - uSlope // y value respected to x value at a sloped line * - writeT // String list of values (e.g., prices, quantities, etc) assigned to a single variable (e.g. {@link Chip}) * * * @author Faria Nassiri-Mofakham * */ public class UtilityHelperMethods { /** * @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. **/ public double bezier(T[] desired, Double offered) { double bez = 0.0; int n= desired.length; for (int i=0; i (double) desired[n-1]) ? 0.0 : comb(n,i)*Math.pow(1-offered, n)*Math.pow(i, n)*(double)desired[i])); } return ( (bez>1) ? 1 : (bez<0) ? 0 : bez); } /** * @return combination of `n' and `k' **/ public int comb(int n, int k) { return fc(n)/(fc(n-k)*fc(k)); } /** * @return factorial of `n' **/ public int fc(int n) { int result = 1; for (; n > 1; n--) { result *= n; } return result; } /** * @param a param and 2 data points and respected utilities, showing a sloped line * @return utility of param **/ public double uSlope(double param, T tData1, T tData2, Double uData1, Double uData2) { Double data1 = (Double) tData1; Double data2 = (Double) tData2; return (param-data1)*(uData1-uData2)/(data1-data2)+uData1; } /** * @return an String list of values assigned to a single variable, e.g. list of quantities or prices per a {@link Chip} **/ public String writeT(ChipIssueValue t) { String s = "{"; T[] j; for (Chip c: t) { s += " " + c.toString() + "={"; j= t.getUnitValue(c); //System.out.println("j: "+j); for (int k=0; k