Search in sources :

Example 1 with Distribution

use of umontreal.ssj.probdist.Distribution in project Stochastic-Inventory by RobinChen121.

the class LevelFitsS method main.

public static void main(String[] args) {
    double truncationQuantile = 0.9999;
    double stepSize = 1;
    double minInventory = -500;
    double maxInventory = 1000;
    double fixedOrderingCost = 250;
    double variOrderingCost = 0;
    double penaltyCost = 26;
    // double[] meanDemand = { 20, 40, 60, 40 };
    double holdingCost = 1;
    int maxOrderQuantity = 41;
    boolean isForDrawGy = true;
    // // get demand possibilities for each period
    // int T = meanDemand.length;
    // Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(T)
    // //.mapToObj(i -> new PoissonDist(meanDemand[i]))
    // .mapToObj(i -> new NormalDist(meanDemand[i], coeValue * meanDemand[i]))
    // .toArray(Distribution[]::new);
    // double[][][] pmf = new GetPmf(distributions, truncationQuantile, stepSize).getpmf();
    // int T = 8;
    // double[] values = {6, 7};
    // double[] probs = {0.95, 0.05};
    // Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(T)
    // .mapToObj(i -> new DiscreteDistribution(values, probs, values.length)) // can be changed to other distributions
    // .toArray(DiscreteDistribution[]::new);
    // double[][][] pmf = new GetPmf(distributions, truncationQuantile, stepSize).getpmf();
    int T = 4;
    double[][] values = { { 34, 159, 281, 286 }, { 14, 223, 225, 232 }, { 5, 64, 115, 171 }, { 35, 48, 145, 210 } };
    double[][] probs = { { 0.018, 0.888, 0.046, 0.048 }, { 0.028, 0.271, 0.17, 0.531 }, { 0.041, 0.027, 0.889, 0.043 }, { 0.069, 0.008, 0.019, 0.904 } };
    Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(T).mapToObj(// can be changed to other distributions
    i -> new DiscreteDistribution(values[i], probs[i], values[i].length)).toArray(DiscreteDistribution[]::new);
    double[][][] pmf = new GetPmf(distributions, truncationQuantile, stepSize).getpmf();
    // feasible actions
    Function<State, double[]> getFeasibleAction = s -> {
        double[] feasibleActions = new double[(int) (maxOrderQuantity / stepSize) + 1];
        int index = 0;
        for (double i = 0; i <= maxOrderQuantity; i = i + stepSize) {
            feasibleActions[index] = i;
            index++;
        }
        return feasibleActions;
    };
    // state transition function
    StateTransitionFunction<State, Double, Double, State> stateTransition = (state, action, randomDemand) -> {
        double nextInventory = state.getIniInventory() + action - randomDemand;
        nextInventory = nextInventory > maxInventory ? maxInventory : nextInventory;
        nextInventory = nextInventory < minInventory ? minInventory : nextInventory;
        return new State(state.getPeriod() + 1, nextInventory);
    };
    // immediate value
    ImmediateValueFunction<State, Double, Double, Double> immediateValue = (state, action, randomDemand) -> {
        double fixedCost = 0, variableCost = 0, inventoryLevel = 0, holdingCosts = 0, penaltyCosts = 0;
        fixedCost = action > 0 ? fixedOrderingCost : 0;
        variableCost = variOrderingCost * action;
        inventoryLevel = state.getIniInventory() + action - randomDemand;
        holdingCosts = holdingCost * Math.max(inventoryLevel, 0);
        penaltyCosts = penaltyCost * Math.max(-inventoryLevel, 0);
        double totalCosts = fixedCost + variableCost + holdingCosts + penaltyCosts;
        return totalCosts;
    };
    /**
     *****************************************************************
     * Solve
     */
    Recursion recursion = new Recursion(OptDirection.MIN, pmf, getFeasibleAction, stateTransition, immediateValue);
    int period = 1;
    double iniInventory = 500;
    State initialState = new State(period, iniInventory);
    long currTime = System.currentTimeMillis();
    double opt = recursion.getExpectedValue(initialState);
    System.out.println("final optimal expected value is: " + opt);
    System.out.println("optimal order quantity in the first priod is : " + recursion.getAction(initialState));
    double time = (System.currentTimeMillis() - currTime) / 1000;
    System.out.println("running time is " + time + "s");
    /**
     *****************************************************************
     * Simulating sdp results
     */
    int sampleNum = 10000;
    SimulateFitsS simuation = new SimulateFitsS(distributions, sampleNum, recursion);
    simuation.simulateSDPGivenSamplNum(initialState);
    double error = 0.0001;
    double confidence = 0.95;
    simuation.simulateSDPwithErrorConfidence(initialState, error, confidence);
    /**
     *****************************************************************
     * Fit (s, S) levels
     */
    System.out.println("");
    double[][] optTable = recursion.getOptTable();
    MIPFitsS findsS = new MIPFitsS(maxOrderQuantity, T);
    double[][] optsS = findsS.getSinglesS(optTable);
    System.out.println("single s, S level: " + Arrays.deepToString(optsS));
    optsS = findsS.getTwosS(optTable);
    System.out.println("two s, S level: " + Arrays.deepToString(optsS));
    optsS = findsS.getThreesS(optTable);
    System.out.println("three s, S level: " + Arrays.deepToString(optsS));
    double sim1 = simuation.simulateSinglesS(initialState, optsS, maxOrderQuantity);
    System.out.printf("one level gap is %.2f%%\n", (sim1 - opt) * 100 / opt);
    double sim2 = simuation.simulateTwosS(initialState, optsS, maxOrderQuantity);
    System.out.printf("two level gap is %.2f%%\n", (sim2 - opt) * 100 / opt);
    double sim3 = simuation.simulateThreesS(initialState, optsS, maxOrderQuantity);
    System.out.printf("three level gap is %.2f%%\n", (sim3 - opt) * 100 / opt);
}
Also used : IntStream(java.util.stream.IntStream) ImmediateValueFunction(sdp.inventory.ImmediateValue.ImmediateValueFunction) Arrays(java.util.Arrays) DiscreteDistribution(umontreal.ssj.probdist.DiscreteDistribution) NormalDist(umontreal.ssj.probdist.NormalDist) MIPFitsS(milp.MIPFitsS) Function(java.util.function.Function) StateTransitionFunction(sdp.inventory.StateTransition.StateTransitionFunction) GetPmf(sdp.inventory.GetPmf) OptDirection(sdp.inventory.Recursion.OptDirection) CheckKConvexity(sdp.inventory.CheckKConvexity) State(sdp.inventory.State) Recursion(sdp.inventory.Recursion) PoissonDist(umontreal.ssj.probdist.PoissonDist) Drawing(sdp.inventory.Drawing) Distribution(umontreal.ssj.probdist.Distribution) Recursion(sdp.inventory.Recursion) MIPFitsS(milp.MIPFitsS) State(sdp.inventory.State) DiscreteDistribution(umontreal.ssj.probdist.DiscreteDistribution) Distribution(umontreal.ssj.probdist.Distribution) GetPmf(sdp.inventory.GetPmf) DiscreteDistribution(umontreal.ssj.probdist.DiscreteDistribution)

Example 2 with Distribution

use of umontreal.ssj.probdist.Distribution in project Stochastic-Inventory by RobinChen121.

the class MultiItemCashLookPolicy method main.

public static void main(String[] args) {
    double[] price = { 10, 5 };
    // higher margin vs lower margin
    double[] variCost = { 4, 2 };
    // initial cash
    double iniCash = 25;
    // initial inventory
    int iniInventory1 = 0;
    int iniInventory2 = 0;
    // higher average demand vs lower average demand
    double[][] demand = { { 6, 6 }, { 8, 8 } };
    // higher variance vs lower variance
    double[] coe = { 0.5, 0.25 };
    double[] salPrice = { 2, 1 };
    // horizon length
    int T = demand[0].length;
    double truncationQuantile = 0.999;
    int stepSize = 1;
    double minCashState = 0;
    double maxCashState = 10000;
    int minInventoryState = 0;
    int maxInventoryState = 200;
    int Qbound = 100;
    double discountFactor = 1;
    double Rmin = 25;
    double Rmax = 80;
    int incre = 2;
    int rowNum = (int) ((Rmax - Rmin) / incre) + 2;
    int row = 0;
    double[][] optResults = new double[rowNum][5];
    for (iniCash = Rmin; iniCash <= Rmax; iniCash = iniCash + incre) {
        // get demand possibilities for each period
        Distribution[][] distributions = new Distribution[demand.length][T];
        for (int t = 0; t < T; t++) {
            for (int i = 0; i < demand.length; i++) {
                distributions[t][i] = new PoissonDist(demand[i][t]);
            }
        }
        double[][][] pmf = new GetPmf(distributions, truncationQuantile, stepSize).getpmfMulti();
        // build action list for two items
        Function<CashStateMulti, ArrayList<Actions>> buildActionList = s -> {
            ArrayList<Actions> actions = new ArrayList<>();
            for (int i = 0; i < Qbound; i++) for (int j = 0; j < Qbound; j++) {
                if (variCost[0] * i + variCost[1] * j < s.getIniCash() + 0.1) {
                    Actions thisAction = new Actions(i, j);
                    actions.add(thisAction);
                }
            }
            return actions;
        };
        // Immediate Value Function
        ImmediateValueFunction<CashStateMulti, Actions, Demands, Double> immediateValue = (IniState, Actions, RandomDemands) -> {
            double action1 = Actions.getFirstAction();
            double action2 = Actions.getSecondAction();
            double demand1 = RandomDemands.getFirstDemand();
            double demand2 = RandomDemands.getSecondDemand();
            double endInventory1 = Math.max(0, IniState.getIniInventory1() + action1 - demand1);
            double endInventory2 = Math.max(0, IniState.getIniInventory2() + action2 - demand2);
            double revenue = price[0] * (IniState.getIniInventory1() + action1 - endInventory1) + price[1] * (IniState.getIniInventory2() + action2 - endInventory2);
            double orderingCosts = variCost[0] * action1 + variCost[1] * action2;
            double salValue = 0;
            if (IniState.getPeriod() == T - 1) {
                salValue = salPrice[0] * endInventory1 + salPrice[1] * endInventory2;
            }
            return revenue - orderingCosts + salValue;
        };
        // State Transition Function
        StateTransitionFunction<CashStateMulti, Actions, Demands, CashStateMulti> stateTransition = (IniState, Actions, RandomDemands) -> {
            double endInventory1 = IniState.getIniInventory1() + Actions.getFirstAction() - RandomDemands.getFirstDemand();
            endInventory1 = Math.max(0, endInventory1);
            double endInventory2 = IniState.getIniInventory2() + Actions.getSecondAction() - RandomDemands.getSecondDemand();
            endInventory2 = Math.max(0, endInventory2);
            double nextCash = IniState.getIniCash() + immediateValue.apply(IniState, Actions, RandomDemands);
            nextCash = nextCash > maxCashState ? maxCashState : nextCash;
            nextCash = nextCash < minCashState ? minCashState : nextCash;
            endInventory1 = endInventory1 > maxInventoryState ? maxInventoryState : endInventory1;
            endInventory2 = endInventory2 < minInventoryState ? minInventoryState : endInventory2;
            // rounding states to save computing time
            nextCash = (int) nextCash;
            endInventory1 = (int) endInventory1;
            endInventory2 = (int) endInventory2;
            return new CashStateMulti(IniState.getPeriod() + 1, endInventory1, endInventory2, nextCash);
        };
        /**
         *****************************************************************
         * Solve
         */
        CashRecursionMulti recursion = new CashRecursionMulti(discountFactor, pmf, buildActionList, stateTransition, immediateValue, T);
        int period = 1;
        CashStateMulti iniState = new CashStateMulti(period, iniInventory1, iniInventory2, iniCash);
        long currTime = System.currentTimeMillis();
        double finalValue = iniCash + recursion.getExpectedValueMulti(iniState);
        System.out.println("final optimal cash  is " + finalValue);
        System.out.println("optimal order quantity in the first priod is :  Q1 = " + recursion.getAction(iniState).getFirstAction() + ", Q2 = " + recursion.getAction(iniState).getSecondAction());
        double time = (System.currentTimeMillis() - currTime) / 1000;
        System.out.println("running time is " + time + "s");
        /**
         *****************************************************************
         * Simulating sdp results
         *
         * simulating results a little lower than SDP
         */
        int sampleNum = 10000;
        CashSimulationMulti simuation = new CashSimulationMulti(sampleNum, distributions, discountFactor, recursion, stateTransition, immediateValue);
        double simFinalValue = simuation.simulateSDPGivenSamplNumMulti(iniState);
        System.out.println(simFinalValue);
        /**
         *****************************************************************
         * try to find some ordering patters from optTable
         *
         * output results to excel
         */
        double Q1 = recursion.getAction(iniState).getFirstAction();
        double Q2 = recursion.getAction(iniState).getSecondAction();
        System.out.println("");
        optResults[row][0] = iniInventory1;
        optResults[row][1] = iniInventory2;
        optResults[row][2] = iniCash;
        optResults[row][3] = Q1;
        optResults[row][4] = Q2;
        row++;
    }
    System.out.println("**************************************************");
    WriteToExcel wr = new WriteToExcel();
    String fileName = "optTable2.xls";
    String headString = "x1" + "\t" + "x2" + "\t" + "R" + "\t" + "Q1" + "\t" + "Q2";
    wr.writeArrayToExcel(optResults, fileName, headString);
}
Also used : ImmediateValueFunction(sdp.inventory.ImmediateValue.ImmediateValueFunction) Demands(sdp.cash.multiItem.Demands) CashRecursionMulti(sdp.cash.multiItem.CashRecursionMulti) Actions(sdp.cash.multiItem.Actions) Function(java.util.function.Function) StateTransitionFunction(sdp.inventory.StateTransition.StateTransitionFunction) ArrayList(java.util.ArrayList) GetPmf(sdp.inventory.GetPmf) GetPmfMulti(sdp.cash.multiItem.GetPmfMulti) BiNormalDist(umontreal.ssj.probdistmulti.BiNormalDist) WriteToExcel(sdp.write.WriteToExcel) CashSimulationMulti(sdp.cash.multiItem.CashSimulationMulti) CashStateMulti(sdp.cash.multiItem.CashStateMulti) PoissonDist(umontreal.ssj.probdist.PoissonDist) Distribution(umontreal.ssj.probdist.Distribution) PoissonDist(umontreal.ssj.probdist.PoissonDist) Actions(sdp.cash.multiItem.Actions) Demands(sdp.cash.multiItem.Demands) ArrayList(java.util.ArrayList) CashStateMulti(sdp.cash.multiItem.CashStateMulti) CashSimulationMulti(sdp.cash.multiItem.CashSimulationMulti) WriteToExcel(sdp.write.WriteToExcel) Distribution(umontreal.ssj.probdist.Distribution) GetPmf(sdp.inventory.GetPmf) CashRecursionMulti(sdp.cash.multiItem.CashRecursionMulti)

Example 3 with Distribution

use of umontreal.ssj.probdist.Distribution in project Stochastic-Inventory by RobinChen121.

the class LocalSearch method testLocalOptima.

public static void testLocalOptima() {
    long[] seed = { 1, 2, 3, 4, 5, 6 };
    MRG32k3aL randomGenerator = new MRG32k3aL();
    randomGenerator.setSeed(seed);
    PiecewiseComplementaryFirstOrderLossFunction[] pwcfolfs = new PiecewiseComplementaryFirstOrderLossFunction[2];
    double[] observations1 = { 28.0741, 37.0565, 17.8413, 36.5158, 21.6293, 20.4246, 71.4112, 37.6059, 37.9011, 36.325, 33.5892, 25.9398, 40.6084, 11.3667, 15.0024, 19.465, 27.265, 78.504, 27.1685, 76.4571, 72.0118, 23.7986, 70.5609, 26.463, 25.3521, 17.4925, 37.513, 22.7177, 32.0754, 17.4422, 33.2551, 23.8737, 47.2574, 67.5549, 29.6037, 22.3234, 54.5201, 73.9199, 32.543, 17.1827, 59.1714, 39.2098, 35.6647, 19.1226, 64.8445, 33.8207, 36.1044, 28.4903, 83.8897, 29.9214, 21.8565, 27.2275, 34.6711, 54.8081, 19.7576, 50.0901, 37.721, 33.0879, 57.5642, 35.861, 68.1631, 20.3139, 84.9478, 47.0687, 37.5119, 21.7852, 14.3257, 10.6876, 33.1993, 28.261, 33.2155, 72.4989, 32.2685, 19.1746, 73.9071, 20.9411, 23.4219, 26.4588, 34.7484, 28.6204, 83.3349, 27.4877, 25.5364, 31.3102, 40.1026, 32.2763, 33.9677, 31.4265, 21.5841, 80.9962, 73.9571, 38.615, 56.6494, 64.2206, 33.9953, 37.6291, 31.3204, 26.6406, 28.5466, -2.56407, 35.7539, 28.754, 60.4775, 69.5395, 34.5684, 31.4762, 32.1759, 19.9471, 30.4914, 15.3123, 17.905, 27.962, 25.1847, 25.2175, 42.4135, 25.4947, 70.2815, 14.2841, 82.3108, 19.0916, 49.0102, 65.6284, 18.0347, 18.5975, 47.6527, 37.7432, 24.0594, 26.3102, 23.7305, 12.6009, 21.9906, 32.4108, 23.6196, 9.21787, 54.7988, 42.6507, 73.5334, 25.6067, 40.7631, 41.9349, 33.7569, 35.2573, 24.3099, 84.2028, 25.7688, 34.3607, 26.5855, 72.5383, 18.8661, 43.656, 68.8784, 60.6869, 71.5258, 75.1431, 39.7538, 29.4983, 25.2816, 23.6204, 56.6435, 22.9425, 31.8486, 70.2084, 11.9978, 44.7344, 34.2046, 33.7131, 31.5913, 28.6397, 22.9598, 23.4668, 26.7419, 22.5111, 41.7394, 13.3714, 88.2541, 39.1714, 72.4239, 45.7921, 51.9322, 32.2951, 37.3388, 20.0179, 76.4912, 24.1718, 77.2087, 65.8098, 19.62, 66.0744, 82.2651, 71.2201, 31.6994, 23.6553, 33.0635, 40.4197, 32.6747, 19.7996, 36.0052, 38.047, 3.42543, 42.1742, 47.4269, 66.4148, 30.5918, 72.4994, 19.8016, 24.2546, 18.7883, 32.4965, 65.2762, 63.9234, 30.3478, 16.0009, 32.2717, 1.65196, 38.535, 18.3457, 67.7012, 65.6919, 23.9415, 46.8337, 16.2651, 30.1157, 31.8795, 32.3591, 67.1413, 57.5025, 71.8455, 75.0887, 36.4344, 73.0453, 27.7212, 61.0768, 28.8377, 53.9263, 31.5856, 16.1044, 3.69301, 32.019, 57.5973, 23.2975, 18.7782, 24.2909, 34.7884, 11.5381, 68.7499, 26.5432, 34.1972, 10.5637, 31.3054, 52.754, 39.1474, 18.1672, 31.4205, 30.3261, 18.3458, 80.6453, 48.8155, 11.3507, 80.1665, 37.2467, 32.2537, 33.6072, 18.2034, 72.6979, 38.2461, 32.6766, 61.6329, 25.8569, 47.2018, 28.3907, 82.2836, 33.8426, 15.9098, 55.6322, 28.8267, 36.0302, 47.4414, 26.6971, 64.2641, 64.7451, 33.8348, 70.7965, 36.2064, 75.1953, 31.2499, 20.7991, 21.3809, 27.5349, 24.9914, 39.1093, 19.0464, 73.5757, 15.6159, 34.3066, 24.6083, 17.9586, 75.8947, 91.4498, 36.1667, 40.1685, 23.598, 21.148, 24.6226, 35.7321, 63.3948, 74.7273, 28.7412, 68.3333, 28.5688, 21.9989, 21.1213, 26.1011, 35.5599, 28.1384, 20.021, 75.1544, 35.1936, 25.2616, 1.70038, 17.8895, 76.8902, 35.1254, 73.2399, 15.0038, 29.8682, 14.2947, 22.5822, 39.2031, 28.0553, 24.9845, 14.5433, 27.4424, 22.7428, 24.0465, 23.6355, 61.8469, 26.462, 39.7285, 46.4482, 32.341, 25.0918, 38.3904, 26.284, 30.667, 35.4871, 16.3957, 39.1846, 17.7234, 15.7191, 25.2957, 15.7521, 70.6436, 82.3403, 45.3663, 11.2882, 13.1438, 41.1792, 33.1248, 56.0817, 27.1867, 25.2638, 76.2728, 62.2844, 58.8604, 22.7928, 53.4659, 48.3358, 37.8583, 26.3246, 33.9605, 39.0206, 25.6244, 32.7355, 20.9361, 19.0955, 43.0133, 15.0526, 32.7747, 44.5282, 23.7317, 72.6272, 47.6351, 75.0638, 28.8967, 22.3245, 24.9527, 29.5371, 71.4213, 17.6563, 45.5411, 43.5561, 21.7395, 58.4722, 72.613, 33.405, 32.6981, 52.7684, 72.994, 23.1276, 28.9063 };
    Distribution[] distributions1 = { new EmpiricalDist(observations1) };
    pwcfolfs[0] = new PiecewiseComplementaryFirstOrderLossFunction(distributions1, seed);
    double[] observations2 = { 63.4049, 49.7431, 98.2874, 72.1489, 6.70325, 55.0911, 8.16425, 82.3973, 60.2456, 28.687, 97.931, 60.6241, 61.9652, 18.0754, 5.84652, 53.9288, 33.7648, 18.3471, 68.259, 44.8769, 74.7729, 9.37814, 72.2867, 41.2157, 10.2297, 60.669, 67.8683, 54.0558, 85.6881, 6.54943, 64.9499, 58.3083, 61.1755, 83.5816, 3.522, 0.251908, 35.498, 55.8284, 46.8813, 36.2971, 61.3581, 58.3464, 30.5702, 68.3962, 3.02535, 74.2239, 69.7271, 65.2046, 24.0099, 9.66892, 26.1496, 104.464, 53.0333, 44.0788, 90.7747, 6.67427, 4.69108, 89.7861, 60.0749, 35.3153, 71.3723, 1.93182, 66.4741, 25.1942, 83.0325, 88.2236, 87.9208, 21.8986, 57.9547, 34.6292, 5.85153, 82.153, 17.8169, 48.1183, 41.6441, 60.4861, 59.0518, 78.9059, 48.8856, 26.4719, 47.327, 1.62829, 42.9448, 0.983071, 82.8186, 73.1106, 8.37273, 75.131, 37.0327, 68.8736, 49.0243, 46.0151, 11.6974, 37.8142, 37.7773, 84.679, 46.8882, 66.7545, 7.46726, 49.7849, 77.1833, 25.9418, 90.9709, 52.351, 12.3385, 2.77454, 4.59362, 65.3159, 25.5208, 60.627, 14.2435, 0.858485, 45.5093, 44.2894, 63.1954, 23.5834, 53.0563, 23.5659, 2.47876, 7.0748, 69.4835, 10.0951, 62.1781, 73.4596, 63.0113, 83.1602, 3.79486, 66.7396, 8.8963, 42.173, 13.0026, 76.9337, 76.5908, 91.464, 4.47613, 64.0771, 1.17219, 4.6857, 0.812106, 66.9142, 85.04, 4.86323, 1.77279, 16.2038, 60.96, 77.9269, 13.5308, 47.6034, 18.2706, 32.5374, 23.7074, 26.6945, 52.257, 41.2909, 11.9714, 1.32484, 39.7415, 45.419, 29.4219, 87.5243, 33.0665, 14.2467, 0.796378, 49.4508, 67.184, 8.65801, 87.9505, 34.8374, 66.4889, 57.5287, 0.185386, 37.1761, 80.1379, 11.7232, 79.0982, 82.0065, 29.6477, 21.0023, 47.9231, 54.6587, 78.6668, 78.3218, 55.0015, 108.432, 94.6621, 40.893, 3.4765, 2.50739, 52.1598, 6.95193, 83.596, 14.3164, 14.5686, 49.4514, 69.6493, 65.9588, 73.4052, 56.9232, 50.7877, 75.3402, 99.0672, 15.507, 22.5798, 0.832404, 75.7336, 90.0872, 71.0788, 52.2645, 62.9782, 26.1946, 66.4443, 63.7976, 95.3219, 0.128229, 65.0506, 38.8051, 3.31758, 16.5506, 4.50226, 96.7296, 103.263, 84.7201, 11.8774, 51.6167, 44.2268, 0.525752, 58.3541, 65.6275, 37.118, 31.2515, 29.1207, 47.5121, 74.6872, 87.7308, 72.3813, 68.4761, 5.28055, 49.7506, 44.4426, 43.3843, 76.3153, 60.7385, 1.09989, 69.7635, 41.924, 1.24718, 3.92268, 0.336283, 19.7256, 46.4883, 70.1879, 78.9288, 21.3933, 33.7022, 48.1611, 2.95351, 1.48788, 22.3215, 80.1718, 97.617, 35.8137, 83.0107, 5.49969, 80.9309, 44.6753, 53.6202, 68.042, 69.3151, 59.8003, 54.2005, 73.1622, 63.8349, 73.2136, 73.3634, 40.4595, 61.0203, 46.9732, 45.5854, 59.8298, 23.2752, 49.556, 60.1231, 57.5179, 11.3818, 79.6682, 103.481, 99.1486, 4.82067, 36.6592, 6.82595, 43.8694, 67.6414, 36.354, 44.5273, 44.281, 49.1332, 76.4088, 59.8129, 15.3144, 53.2114, 52.2487, 11.17, 37.8858, 62.7593, 88.4599, 31.0753, 2.67468, 47.8929, 4.98802, 2.23822, 58.8278, 10.5323, 10.1903, 83.8942, 63.436, 25.4112, 42.9789, 33.7188, 93.7439, 91.2494, 8.46958, 41.7114, 55.0515, 87.0487, 55.6446, 14.8123, 53.7773, 44.2562, 63.3135, 39.2929, 23.8872, 75.3651, 68.6517, 6.5044, 20.1349, 3.19185, 43.7163, 9.21238, 7.54149, 53.4388, 69.902, 99.9, 71.6383, 82.8874, 82.8314, 90.2156, 60.4963, 55.7917, 66.4666, 93.7426, 47.7014, 74.4245, 3.3344, 10.9358, 27.8028, 48.5167, 72.8611, 0.804015, 74.455, 83.8912, 26.5895, 3.6511, 21.9575, 20.063, 26.505, 83.5355, 93.7192, 7.00239, 54.4818, 84.0105, 72.2029, 15.5663, 27.3149, 78.499, 33.5704, 13.7192, 39.0149, 57.9133, 14.9824, 56.6921, 16.5191, 47.431, 58.9464, 36.8409, 29.2285, 38.4334, 70.4695, 85.8938, 4.60473, 27.3362, 50.345, 49.2085, 12.4552, 40.9776, 13.9681, 3.25816, 11.3622, 37.1044, 61.4925, 25.2853 };
    Distribution[] distributions2 = { new EmpiricalDist(observations2) };
    pwcfolfs[1] = new PiecewiseComplementaryFirstOrderLossFunction(distributions2, seed);
    int nbSamples = 1000;
    // double[] bestMass = {0.3,0.3,0.1,0.04,0.26};
    double[] bestMass = { 0.16, 0.3, 0.1, 0.18, 0.26 };
    // double[] bestMass = {0.04,0.3,0.1,0.3,0.26};
    double maxApproxError = 0;
    for (int p = 0; p < pwcfolfs.length; p++) {
        maxApproxError = Math.max(maxApproxError, pwcfolfs[p].getMaxApproximationError(bestMass, nbSamples));
    }
    System.out.println(maxApproxError);
    pwcfolfs[0].plotPiecewiseLossFunction(0, 85, -1, bestMass, nbSamples, 0.1, false);
    pwcfolfs[1].plotPiecewiseLossFunction(0, 85, -1, bestMass, nbSamples, 0.1, false);
}
Also used : EmpiricalDist(umontreal.ssj.probdist.EmpiricalDist) Distribution(umontreal.ssj.probdist.Distribution) MRG32k3aL(umontreal.ssj.rng.MRG32k3aL) PiecewiseComplementaryFirstOrderLossFunction(milp.PiecewiseComplementaryFirstOrderLossFunction)

Example 4 with Distribution

use of umontreal.ssj.probdist.Distribution in project Stochastic-Inventory by RobinChen121.

the class LocalSearch method exhaustiveEnumeration.

public static void exhaustiveEnumeration() {
    long[] seed = { 1, 2, 3, 4, 5, 6 };
    MRG32k3aL randomGenerator = new MRG32k3aL();
    randomGenerator.setSeed(seed);
    PiecewiseComplementaryFirstOrderLossFunction[] pwcfolfs = new PiecewiseComplementaryFirstOrderLossFunction[2];
    double[] observations1 = { 28.0741, 37.0565, 17.8413, 36.5158, 21.6293, 20.4246, 71.4112, 37.6059, 37.9011, 36.325, 33.5892, 25.9398, 40.6084, 11.3667, 15.0024, 19.465, 27.265, 78.504, 27.1685, 76.4571, 72.0118, 23.7986, 70.5609, 26.463, 25.3521, 17.4925, 37.513, 22.7177, 32.0754, 17.4422, 33.2551, 23.8737, 47.2574, 67.5549, 29.6037, 22.3234, 54.5201, 73.9199, 32.543, 17.1827, 59.1714, 39.2098, 35.6647, 19.1226, 64.8445, 33.8207, 36.1044, 28.4903, 83.8897, 29.9214, 21.8565, 27.2275, 34.6711, 54.8081, 19.7576, 50.0901, 37.721, 33.0879, 57.5642, 35.861, 68.1631, 20.3139, 84.9478, 47.0687, 37.5119, 21.7852, 14.3257, 10.6876, 33.1993, 28.261, 33.2155, 72.4989, 32.2685, 19.1746, 73.9071, 20.9411, 23.4219, 26.4588, 34.7484, 28.6204, 83.3349, 27.4877, 25.5364, 31.3102, 40.1026, 32.2763, 33.9677, 31.4265, 21.5841, 80.9962, 73.9571, 38.615, 56.6494, 64.2206, 33.9953, 37.6291, 31.3204, 26.6406, 28.5466, -2.56407, 35.7539, 28.754, 60.4775, 69.5395, 34.5684, 31.4762, 32.1759, 19.9471, 30.4914, 15.3123, 17.905, 27.962, 25.1847, 25.2175, 42.4135, 25.4947, 70.2815, 14.2841, 82.3108, 19.0916, 49.0102, 65.6284, 18.0347, 18.5975, 47.6527, 37.7432, 24.0594, 26.3102, 23.7305, 12.6009, 21.9906, 32.4108, 23.6196, 9.21787, 54.7988, 42.6507, 73.5334, 25.6067, 40.7631, 41.9349, 33.7569, 35.2573, 24.3099, 84.2028, 25.7688, 34.3607, 26.5855, 72.5383, 18.8661, 43.656, 68.8784, 60.6869, 71.5258, 75.1431, 39.7538, 29.4983, 25.2816, 23.6204, 56.6435, 22.9425, 31.8486, 70.2084, 11.9978, 44.7344, 34.2046, 33.7131, 31.5913, 28.6397, 22.9598, 23.4668, 26.7419, 22.5111, 41.7394, 13.3714, 88.2541, 39.1714, 72.4239, 45.7921, 51.9322, 32.2951, 37.3388, 20.0179, 76.4912, 24.1718, 77.2087, 65.8098, 19.62, 66.0744, 82.2651, 71.2201, 31.6994, 23.6553, 33.0635, 40.4197, 32.6747, 19.7996, 36.0052, 38.047, 3.42543, 42.1742, 47.4269, 66.4148, 30.5918, 72.4994, 19.8016, 24.2546, 18.7883, 32.4965, 65.2762, 63.9234, 30.3478, 16.0009, 32.2717, 1.65196, 38.535, 18.3457, 67.7012, 65.6919, 23.9415, 46.8337, 16.2651, 30.1157, 31.8795, 32.3591, 67.1413, 57.5025, 71.8455, 75.0887, 36.4344, 73.0453, 27.7212, 61.0768, 28.8377, 53.9263, 31.5856, 16.1044, 3.69301, 32.019, 57.5973, 23.2975, 18.7782, 24.2909, 34.7884, 11.5381, 68.7499, 26.5432, 34.1972, 10.5637, 31.3054, 52.754, 39.1474, 18.1672, 31.4205, 30.3261, 18.3458, 80.6453, 48.8155, 11.3507, 80.1665, 37.2467, 32.2537, 33.6072, 18.2034, 72.6979, 38.2461, 32.6766, 61.6329, 25.8569, 47.2018, 28.3907, 82.2836, 33.8426, 15.9098, 55.6322, 28.8267, 36.0302, 47.4414, 26.6971, 64.2641, 64.7451, 33.8348, 70.7965, 36.2064, 75.1953, 31.2499, 20.7991, 21.3809, 27.5349, 24.9914, 39.1093, 19.0464, 73.5757, 15.6159, 34.3066, 24.6083, 17.9586, 75.8947, 91.4498, 36.1667, 40.1685, 23.598, 21.148, 24.6226, 35.7321, 63.3948, 74.7273, 28.7412, 68.3333, 28.5688, 21.9989, 21.1213, 26.1011, 35.5599, 28.1384, 20.021, 75.1544, 35.1936, 25.2616, 1.70038, 17.8895, 76.8902, 35.1254, 73.2399, 15.0038, 29.8682, 14.2947, 22.5822, 39.2031, 28.0553, 24.9845, 14.5433, 27.4424, 22.7428, 24.0465, 23.6355, 61.8469, 26.462, 39.7285, 46.4482, 32.341, 25.0918, 38.3904, 26.284, 30.667, 35.4871, 16.3957, 39.1846, 17.7234, 15.7191, 25.2957, 15.7521, 70.6436, 82.3403, 45.3663, 11.2882, 13.1438, 41.1792, 33.1248, 56.0817, 27.1867, 25.2638, 76.2728, 62.2844, 58.8604, 22.7928, 53.4659, 48.3358, 37.8583, 26.3246, 33.9605, 39.0206, 25.6244, 32.7355, 20.9361, 19.0955, 43.0133, 15.0526, 32.7747, 44.5282, 23.7317, 72.6272, 47.6351, 75.0638, 28.8967, 22.3245, 24.9527, 29.5371, 71.4213, 17.6563, 45.5411, 43.5561, 21.7395, 58.4722, 72.613, 33.405, 32.6981, 52.7684, 72.994, 23.1276, 28.9063 };
    Distribution[] distributions1 = { new EmpiricalDist(observations1) };
    pwcfolfs[0] = new PiecewiseComplementaryFirstOrderLossFunction(distributions1, seed);
    double[] observations2 = { 63.4049, 49.7431, 98.2874, 72.1489, 6.70325, 55.0911, 8.16425, 82.3973, 60.2456, 28.687, 97.931, 60.6241, 61.9652, 18.0754, 5.84652, 53.9288, 33.7648, 18.3471, 68.259, 44.8769, 74.7729, 9.37814, 72.2867, 41.2157, 10.2297, 60.669, 67.8683, 54.0558, 85.6881, 6.54943, 64.9499, 58.3083, 61.1755, 83.5816, 3.522, 0.251908, 35.498, 55.8284, 46.8813, 36.2971, 61.3581, 58.3464, 30.5702, 68.3962, 3.02535, 74.2239, 69.7271, 65.2046, 24.0099, 9.66892, 26.1496, 104.464, 53.0333, 44.0788, 90.7747, 6.67427, 4.69108, 89.7861, 60.0749, 35.3153, 71.3723, 1.93182, 66.4741, 25.1942, 83.0325, 88.2236, 87.9208, 21.8986, 57.9547, 34.6292, 5.85153, 82.153, 17.8169, 48.1183, 41.6441, 60.4861, 59.0518, 78.9059, 48.8856, 26.4719, 47.327, 1.62829, 42.9448, 0.983071, 82.8186, 73.1106, 8.37273, 75.131, 37.0327, 68.8736, 49.0243, 46.0151, 11.6974, 37.8142, 37.7773, 84.679, 46.8882, 66.7545, 7.46726, 49.7849, 77.1833, 25.9418, 90.9709, 52.351, 12.3385, 2.77454, 4.59362, 65.3159, 25.5208, 60.627, 14.2435, 0.858485, 45.5093, 44.2894, 63.1954, 23.5834, 53.0563, 23.5659, 2.47876, 7.0748, 69.4835, 10.0951, 62.1781, 73.4596, 63.0113, 83.1602, 3.79486, 66.7396, 8.8963, 42.173, 13.0026, 76.9337, 76.5908, 91.464, 4.47613, 64.0771, 1.17219, 4.6857, 0.812106, 66.9142, 85.04, 4.86323, 1.77279, 16.2038, 60.96, 77.9269, 13.5308, 47.6034, 18.2706, 32.5374, 23.7074, 26.6945, 52.257, 41.2909, 11.9714, 1.32484, 39.7415, 45.419, 29.4219, 87.5243, 33.0665, 14.2467, 0.796378, 49.4508, 67.184, 8.65801, 87.9505, 34.8374, 66.4889, 57.5287, 0.185386, 37.1761, 80.1379, 11.7232, 79.0982, 82.0065, 29.6477, 21.0023, 47.9231, 54.6587, 78.6668, 78.3218, 55.0015, 108.432, 94.6621, 40.893, 3.4765, 2.50739, 52.1598, 6.95193, 83.596, 14.3164, 14.5686, 49.4514, 69.6493, 65.9588, 73.4052, 56.9232, 50.7877, 75.3402, 99.0672, 15.507, 22.5798, 0.832404, 75.7336, 90.0872, 71.0788, 52.2645, 62.9782, 26.1946, 66.4443, 63.7976, 95.3219, 0.128229, 65.0506, 38.8051, 3.31758, 16.5506, 4.50226, 96.7296, 103.263, 84.7201, 11.8774, 51.6167, 44.2268, 0.525752, 58.3541, 65.6275, 37.118, 31.2515, 29.1207, 47.5121, 74.6872, 87.7308, 72.3813, 68.4761, 5.28055, 49.7506, 44.4426, 43.3843, 76.3153, 60.7385, 1.09989, 69.7635, 41.924, 1.24718, 3.92268, 0.336283, 19.7256, 46.4883, 70.1879, 78.9288, 21.3933, 33.7022, 48.1611, 2.95351, 1.48788, 22.3215, 80.1718, 97.617, 35.8137, 83.0107, 5.49969, 80.9309, 44.6753, 53.6202, 68.042, 69.3151, 59.8003, 54.2005, 73.1622, 63.8349, 73.2136, 73.3634, 40.4595, 61.0203, 46.9732, 45.5854, 59.8298, 23.2752, 49.556, 60.1231, 57.5179, 11.3818, 79.6682, 103.481, 99.1486, 4.82067, 36.6592, 6.82595, 43.8694, 67.6414, 36.354, 44.5273, 44.281, 49.1332, 76.4088, 59.8129, 15.3144, 53.2114, 52.2487, 11.17, 37.8858, 62.7593, 88.4599, 31.0753, 2.67468, 47.8929, 4.98802, 2.23822, 58.8278, 10.5323, 10.1903, 83.8942, 63.436, 25.4112, 42.9789, 33.7188, 93.7439, 91.2494, 8.46958, 41.7114, 55.0515, 87.0487, 55.6446, 14.8123, 53.7773, 44.2562, 63.3135, 39.2929, 23.8872, 75.3651, 68.6517, 6.5044, 20.1349, 3.19185, 43.7163, 9.21238, 7.54149, 53.4388, 69.902, 99.9, 71.6383, 82.8874, 82.8314, 90.2156, 60.4963, 55.7917, 66.4666, 93.7426, 47.7014, 74.4245, 3.3344, 10.9358, 27.8028, 48.5167, 72.8611, 0.804015, 74.455, 83.8912, 26.5895, 3.6511, 21.9575, 20.063, 26.505, 83.5355, 93.7192, 7.00239, 54.4818, 84.0105, 72.2029, 15.5663, 27.3149, 78.499, 33.5704, 13.7192, 39.0149, 57.9133, 14.9824, 56.6921, 16.5191, 47.431, 58.9464, 36.8409, 29.2285, 38.4334, 70.4695, 85.8938, 4.60473, 27.3362, 50.345, 49.2085, 12.4552, 40.9776, 13.9681, 3.25816, 11.3622, 37.1044, 61.4925, 25.2853 };
    Distribution[] distributions2 = { new EmpiricalDist(observations2) };
    pwcfolfs[1] = new PiecewiseComplementaryFirstOrderLossFunction(distributions2, seed);
    int nbSamples = 1000;
    double precision = 0.02;
    try {
        File out = new File("plot.txt");
        out.delete();
        out = new File("plot.txt");
        PrintWriter pw = new PrintWriter(out);
        double m = 0.3;
        double n = 0.1;
        for (double i = precision; i + m + n < 1; i += precision) {
            for (double j = precision; j + i + m + n < 1; j += precision) {
                // for(double n = precision; j + i + m + n < 1; n+=precision){
                double k = 1.0 - i - j - m - n;
                double[] probabilityMass = { i, m, n, j, k };
                double maxApproxError = 0;
                for (int p = 0; p < pwcfolfs.length; p++) {
                    maxApproxError = Math.max(maxApproxError, pwcfolfs[p].getMaxApproximationError(probabilityMass, nbSamples));
                }
                // if(maxApproxError <= 1.2){
                pw.print("{");
                for (int p = 0; p < probabilityMass.length; p++) {
                    if (p == 1 || p == 2 || p == 4)
                        continue;
                    double sum = 0;
                    for (int l = 0; l <= p; l++) sum += probabilityMass[l];
                    pw.print(sum + ",");
                }
                // pw.println("},");
                // }
                pw.println(maxApproxError + "},");
            // }
            }
        }
        /*
			double m = 0.3;
			for(double i = precision; i + m < 1; i+=precision){
				for(double j = precision; j + i + m < 1; j+=precision){
					for(double n = precision; j + i + m + n < 1; n+=precision){
						double k = 1.0-i-j-m-n;
						double[] probabilityMass = {i,m,n,j,k};
						double maxApproxError = 0;
						for(int p = 0; p < pwcfolfs.length; p++){
							maxApproxError = Math.max(maxApproxError,pwcfolfs[p].getMaxApproximationError(probabilityMass, nbSamples));
						}
						if(maxApproxError <= 1.2){
							pw.print("{");
							for(int p = 0; p < probabilityMass.length; p++){
								if(p==1||p==4)continue;
								double sum = 0;
								for(int l = 0; l <= p; l++) sum += probabilityMass[l];
								pw.print(sum+",");
							}
							pw.println("},");
						}
						//pw.println(maxApproxError+"},");
					}
				}
			}
			*/
        /*double m = 0.1;
			double n = 0.3;
			double j = 0.1;
			for(double i = precision; i + m + n + j < 1; i+=precision){
				double k = 1.0-i-j-m-n;
				double[] probabilityMass = {i,j,k,n,m};
				double maxApproxError = 0;
				for(int p = 0; p < pwcfolfs.length; p++){
					maxApproxError = Math.max(maxApproxError,pwcfolfs[p].getMaxApproximationError(probabilityMass, nbSamples));
				}
				pw.print("{");
				pw.print(probabilityMass[0]+",");
				pw.println(maxApproxError+"},");
			}*/
        /*double m = 0.1;
			double n = 0.3;
			double j = 0.2;
			for(double i = precision; i + m + n + j < 1; i+=precision){
				double k = 1.0-i-j-m-n;
				double[] probabilityMass = {j,i,k,n,m};
				double maxApproxError = 0;
				for(int p = 0; p < pwcfolfs.length; p++){
					maxApproxError = Math.max(maxApproxError,pwcfolfs[p].getMaxApproximationError(probabilityMass, nbSamples));
				}
				pw.print("{");
				pw.print(probabilityMass[1]+",");
				pw.println(maxApproxError+"},");
			}*/
        pw.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : EmpiricalDist(umontreal.ssj.probdist.EmpiricalDist) FileNotFoundException(java.io.FileNotFoundException) Distribution(umontreal.ssj.probdist.Distribution) MRG32k3aL(umontreal.ssj.rng.MRG32k3aL) File(java.io.File) PiecewiseComplementaryFirstOrderLossFunction(milp.PiecewiseComplementaryFirstOrderLossFunction) PrintWriter(java.io.PrintWriter)

Example 5 with Distribution

use of umontreal.ssj.probdist.Distribution in project Stochastic-Inventory by RobinChen121.

the class LocalSearch method testUniformPartitioning.

public static void testUniformPartitioning() {
    long[] seed = { 1, 2, 3, 4, 5, 6 };
    PiecewiseComplementaryFirstOrderLossFunction[] pwcfolfs = new PiecewiseComplementaryFirstOrderLossFunction[2];
    double[] observations1 = { 28.0741, 37.0565, 17.8413, 36.5158, 21.6293, 20.4246, 71.4112, 37.6059, 37.9011, 36.325, 33.5892, 25.9398, 40.6084, 11.3667, 15.0024, 19.465, 27.265, 78.504, 27.1685, 76.4571, 72.0118, 23.7986, 70.5609, 26.463, 25.3521, 17.4925, 37.513, 22.7177, 32.0754, 17.4422, 33.2551, 23.8737, 47.2574, 67.5549, 29.6037, 22.3234, 54.5201, 73.9199, 32.543, 17.1827, 59.1714, 39.2098, 35.6647, 19.1226, 64.8445, 33.8207, 36.1044, 28.4903, 83.8897, 29.9214, 21.8565, 27.2275, 34.6711, 54.8081, 19.7576, 50.0901, 37.721, 33.0879, 57.5642, 35.861, 68.1631, 20.3139, 84.9478, 47.0687, 37.5119, 21.7852, 14.3257, 10.6876, 33.1993, 28.261, 33.2155, 72.4989, 32.2685, 19.1746, 73.9071, 20.9411, 23.4219, 26.4588, 34.7484, 28.6204, 83.3349, 27.4877, 25.5364, 31.3102, 40.1026, 32.2763, 33.9677, 31.4265, 21.5841, 80.9962, 73.9571, 38.615, 56.6494, 64.2206, 33.9953, 37.6291, 31.3204, 26.6406, 28.5466, -2.56407, 35.7539, 28.754, 60.4775, 69.5395, 34.5684, 31.4762, 32.1759, 19.9471, 30.4914, 15.3123, 17.905, 27.962, 25.1847, 25.2175, 42.4135, 25.4947, 70.2815, 14.2841, 82.3108, 19.0916, 49.0102, 65.6284, 18.0347, 18.5975, 47.6527, 37.7432, 24.0594, 26.3102, 23.7305, 12.6009, 21.9906, 32.4108, 23.6196, 9.21787, 54.7988, 42.6507, 73.5334, 25.6067, 40.7631, 41.9349, 33.7569, 35.2573, 24.3099, 84.2028, 25.7688, 34.3607, 26.5855, 72.5383, 18.8661, 43.656, 68.8784, 60.6869, 71.5258, 75.1431, 39.7538, 29.4983, 25.2816, 23.6204, 56.6435, 22.9425, 31.8486, 70.2084, 11.9978, 44.7344, 34.2046, 33.7131, 31.5913, 28.6397, 22.9598, 23.4668, 26.7419, 22.5111, 41.7394, 13.3714, 88.2541, 39.1714, 72.4239, 45.7921, 51.9322, 32.2951, 37.3388, 20.0179, 76.4912, 24.1718, 77.2087, 65.8098, 19.62, 66.0744, 82.2651, 71.2201, 31.6994, 23.6553, 33.0635, 40.4197, 32.6747, 19.7996, 36.0052, 38.047, 3.42543, 42.1742, 47.4269, 66.4148, 30.5918, 72.4994, 19.8016, 24.2546, 18.7883, 32.4965, 65.2762, 63.9234, 30.3478, 16.0009, 32.2717, 1.65196, 38.535, 18.3457, 67.7012, 65.6919, 23.9415, 46.8337, 16.2651, 30.1157, 31.8795, 32.3591, 67.1413, 57.5025, 71.8455, 75.0887, 36.4344, 73.0453, 27.7212, 61.0768, 28.8377, 53.9263, 31.5856, 16.1044, 3.69301, 32.019, 57.5973, 23.2975, 18.7782, 24.2909, 34.7884, 11.5381, 68.7499, 26.5432, 34.1972, 10.5637, 31.3054, 52.754, 39.1474, 18.1672, 31.4205, 30.3261, 18.3458, 80.6453, 48.8155, 11.3507, 80.1665, 37.2467, 32.2537, 33.6072, 18.2034, 72.6979, 38.2461, 32.6766, 61.6329, 25.8569, 47.2018, 28.3907, 82.2836, 33.8426, 15.9098, 55.6322, 28.8267, 36.0302, 47.4414, 26.6971, 64.2641, 64.7451, 33.8348, 70.7965, 36.2064, 75.1953, 31.2499, 20.7991, 21.3809, 27.5349, 24.9914, 39.1093, 19.0464, 73.5757, 15.6159, 34.3066, 24.6083, 17.9586, 75.8947, 91.4498, 36.1667, 40.1685, 23.598, 21.148, 24.6226, 35.7321, 63.3948, 74.7273, 28.7412, 68.3333, 28.5688, 21.9989, 21.1213, 26.1011, 35.5599, 28.1384, 20.021, 75.1544, 35.1936, 25.2616, 1.70038, 17.8895, 76.8902, 35.1254, 73.2399, 15.0038, 29.8682, 14.2947, 22.5822, 39.2031, 28.0553, 24.9845, 14.5433, 27.4424, 22.7428, 24.0465, 23.6355, 61.8469, 26.462, 39.7285, 46.4482, 32.341, 25.0918, 38.3904, 26.284, 30.667, 35.4871, 16.3957, 39.1846, 17.7234, 15.7191, 25.2957, 15.7521, 70.6436, 82.3403, 45.3663, 11.2882, 13.1438, 41.1792, 33.1248, 56.0817, 27.1867, 25.2638, 76.2728, 62.2844, 58.8604, 22.7928, 53.4659, 48.3358, 37.8583, 26.3246, 33.9605, 39.0206, 25.6244, 32.7355, 20.9361, 19.0955, 43.0133, 15.0526, 32.7747, 44.5282, 23.7317, 72.6272, 47.6351, 75.0638, 28.8967, 22.3245, 24.9527, 29.5371, 71.4213, 17.6563, 45.5411, 43.5561, 21.7395, 58.4722, 72.613, 33.405, 32.6981, 52.7684, 72.994, 23.1276, 28.9063 };
    Distribution[] distributions1 = { new EmpiricalDist(observations1) };
    pwcfolfs[0] = new PiecewiseComplementaryFirstOrderLossFunction(distributions1, seed);
    double[] observations2 = { 63.4049, 49.7431, 98.2874, 72.1489, 6.70325, 55.0911, 8.16425, 82.3973, 60.2456, 28.687, 97.931, 60.6241, 61.9652, 18.0754, 5.84652, 53.9288, 33.7648, 18.3471, 68.259, 44.8769, 74.7729, 9.37814, 72.2867, 41.2157, 10.2297, 60.669, 67.8683, 54.0558, 85.6881, 6.54943, 64.9499, 58.3083, 61.1755, 83.5816, 3.522, 0.251908, 35.498, 55.8284, 46.8813, 36.2971, 61.3581, 58.3464, 30.5702, 68.3962, 3.02535, 74.2239, 69.7271, 65.2046, 24.0099, 9.66892, 26.1496, 104.464, 53.0333, 44.0788, 90.7747, 6.67427, 4.69108, 89.7861, 60.0749, 35.3153, 71.3723, 1.93182, 66.4741, 25.1942, 83.0325, 88.2236, 87.9208, 21.8986, 57.9547, 34.6292, 5.85153, 82.153, 17.8169, 48.1183, 41.6441, 60.4861, 59.0518, 78.9059, 48.8856, 26.4719, 47.327, 1.62829, 42.9448, 0.983071, 82.8186, 73.1106, 8.37273, 75.131, 37.0327, 68.8736, 49.0243, 46.0151, 11.6974, 37.8142, 37.7773, 84.679, 46.8882, 66.7545, 7.46726, 49.7849, 77.1833, 25.9418, 90.9709, 52.351, 12.3385, 2.77454, 4.59362, 65.3159, 25.5208, 60.627, 14.2435, 0.858485, 45.5093, 44.2894, 63.1954, 23.5834, 53.0563, 23.5659, 2.47876, 7.0748, 69.4835, 10.0951, 62.1781, 73.4596, 63.0113, 83.1602, 3.79486, 66.7396, 8.8963, 42.173, 13.0026, 76.9337, 76.5908, 91.464, 4.47613, 64.0771, 1.17219, 4.6857, 0.812106, 66.9142, 85.04, 4.86323, 1.77279, 16.2038, 60.96, 77.9269, 13.5308, 47.6034, 18.2706, 32.5374, 23.7074, 26.6945, 52.257, 41.2909, 11.9714, 1.32484, 39.7415, 45.419, 29.4219, 87.5243, 33.0665, 14.2467, 0.796378, 49.4508, 67.184, 8.65801, 87.9505, 34.8374, 66.4889, 57.5287, 0.185386, 37.1761, 80.1379, 11.7232, 79.0982, 82.0065, 29.6477, 21.0023, 47.9231, 54.6587, 78.6668, 78.3218, 55.0015, 108.432, 94.6621, 40.893, 3.4765, 2.50739, 52.1598, 6.95193, 83.596, 14.3164, 14.5686, 49.4514, 69.6493, 65.9588, 73.4052, 56.9232, 50.7877, 75.3402, 99.0672, 15.507, 22.5798, 0.832404, 75.7336, 90.0872, 71.0788, 52.2645, 62.9782, 26.1946, 66.4443, 63.7976, 95.3219, 0.128229, 65.0506, 38.8051, 3.31758, 16.5506, 4.50226, 96.7296, 103.263, 84.7201, 11.8774, 51.6167, 44.2268, 0.525752, 58.3541, 65.6275, 37.118, 31.2515, 29.1207, 47.5121, 74.6872, 87.7308, 72.3813, 68.4761, 5.28055, 49.7506, 44.4426, 43.3843, 76.3153, 60.7385, 1.09989, 69.7635, 41.924, 1.24718, 3.92268, 0.336283, 19.7256, 46.4883, 70.1879, 78.9288, 21.3933, 33.7022, 48.1611, 2.95351, 1.48788, 22.3215, 80.1718, 97.617, 35.8137, 83.0107, 5.49969, 80.9309, 44.6753, 53.6202, 68.042, 69.3151, 59.8003, 54.2005, 73.1622, 63.8349, 73.2136, 73.3634, 40.4595, 61.0203, 46.9732, 45.5854, 59.8298, 23.2752, 49.556, 60.1231, 57.5179, 11.3818, 79.6682, 103.481, 99.1486, 4.82067, 36.6592, 6.82595, 43.8694, 67.6414, 36.354, 44.5273, 44.281, 49.1332, 76.4088, 59.8129, 15.3144, 53.2114, 52.2487, 11.17, 37.8858, 62.7593, 88.4599, 31.0753, 2.67468, 47.8929, 4.98802, 2.23822, 58.8278, 10.5323, 10.1903, 83.8942, 63.436, 25.4112, 42.9789, 33.7188, 93.7439, 91.2494, 8.46958, 41.7114, 55.0515, 87.0487, 55.6446, 14.8123, 53.7773, 44.2562, 63.3135, 39.2929, 23.8872, 75.3651, 68.6517, 6.5044, 20.1349, 3.19185, 43.7163, 9.21238, 7.54149, 53.4388, 69.902, 99.9, 71.6383, 82.8874, 82.8314, 90.2156, 60.4963, 55.7917, 66.4666, 93.7426, 47.7014, 74.4245, 3.3344, 10.9358, 27.8028, 48.5167, 72.8611, 0.804015, 74.455, 83.8912, 26.5895, 3.6511, 21.9575, 20.063, 26.505, 83.5355, 93.7192, 7.00239, 54.4818, 84.0105, 72.2029, 15.5663, 27.3149, 78.499, 33.5704, 13.7192, 39.0149, 57.9133, 14.9824, 56.6921, 16.5191, 47.431, 58.9464, 36.8409, 29.2285, 38.4334, 70.4695, 85.8938, 4.60473, 27.3362, 50.345, 49.2085, 12.4552, 40.9776, 13.9681, 3.25816, 11.3622, 37.1044, 61.4925, 25.2853 };
    Distribution[] distributions2 = { new EmpiricalDist(observations2) };
    pwcfolfs[1] = new PiecewiseComplementaryFirstOrderLossFunction(distributions2, seed);
    int nbSamples = 1000;
    int partitions = 5;
    double[] bestMass = uniformPartitioning(pwcfolfs, partitions, nbSamples);
    pwcfolfs[0].plotPiecewiseLossFunction(0, 87, -1, bestMass, nbSamples, 0.1, true);
    pwcfolfs[1].plotPiecewiseLossFunction(0, 87, -1, bestMass, nbSamples, 0.1, false);
}
Also used : EmpiricalDist(umontreal.ssj.probdist.EmpiricalDist) Distribution(umontreal.ssj.probdist.Distribution) PiecewiseComplementaryFirstOrderLossFunction(milp.PiecewiseComplementaryFirstOrderLossFunction)

Aggregations

Distribution (umontreal.ssj.probdist.Distribution)59 PoissonDist (umontreal.ssj.probdist.PoissonDist)36 Function (java.util.function.Function)29 GetPmf (sdp.inventory.GetPmf)28 StateTransitionFunction (sdp.inventory.StateTransition.StateTransitionFunction)27 IntStream (java.util.stream.IntStream)26 ImmediateValueFunction (sdp.inventory.ImmediateValue.ImmediateValueFunction)24 Arrays (java.util.Arrays)22 CashState (sdp.cash.CashState)19 NormalDist (umontreal.ssj.probdist.NormalDist)18 DoubleStream (java.util.stream.DoubleStream)17 ArrayList (java.util.ArrayList)15 CashRecursion (sdp.cash.CashRecursion)15 State (sdp.inventory.State)15 OptDirection (sdp.cash.CashRecursion.OptDirection)13 Sampling (sdp.sampling.Sampling)12 Map (java.util.Map)11 TreeMap (java.util.TreeMap)11 CashSimulation (sdp.cash.CashSimulation)11 WriteToExcel (sdp.write.WriteToExcel)11