from scm_optimization.model import StationaryOptModel
import plotly
import pacal
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import itertools
import pandas as pd

inv_pos_max = 30
t_max = 15
n_max = 5

rv_0 = pacal.ConstDistr(0)
rv_5_5 = pacal.DiscreteDistr([5], [1])
rv_3_7 = pacal.DiscreteDistr([3, 7], [0.5, 0.5])
rv_1_9 = pacal.DiscreteDistr([1, 9], [0.5, 0.5])
rv_0_10 = pacal.DiscreteDistr([0, 10], [0.5, 0.5])

rv_10_10 = pacal.DiscreteDistr([10], [1])
rv_8_12 = pacal.DiscreteDistr([8, 12], [0.5, 0.5])
rv_6_14 = pacal.DiscreteDistr([6, 14], [0.5, 0.5])
rv_4_16 = pacal.DiscreteDistr([4, 16], [0.5, 0.5])
rv_2_18 = pacal.DiscreteDistr([2, 18], [0.5, 0.5])
rv_0_20 = pacal.DiscreteDistr([0, 20], [0.5, 0.5])

test_cases = {
    "E[Demand] 10": rv_10_10,
    "E[Demand] 8, 12": rv_8_12,
    "E[Demand] 6, 14": rv_6_14,
    "E[Demand] 4, 16": rv_4_16,
    "E[Demand] 2, 18": rv_2_18,
    #for item_id in ["47320", "56931", "1686", "129636", "83532", "38262"]:
    #for item_id in ["21920", "38197", "82099"]:
    for item_id in ["47320", "1686", "21920", "38197", "82099"]:
        #for b in [1000, 10000]:
        for b in [100]:
            for lt in [0, 1]:
                #for lt in [1]:
                config = ns_model.ModelConfig(
                    gamma=1,
                    lead_time=lt,
                    holding_cost=1,
                    backlogging_cost=b,
                    setup_cost=0,
                    unit_price=0,
                    usage_model=PoissonUsageModel(scale=1),
                    elective_info_state_rv=pacal.ConstDistr(0),
                    emergency_info_state_rv=emergency_info_rvs[item_id],
                    horizon=28,
                    label="ns_impl_full_value_{}".format(item_id),
                    label_index=0)

                results = []
                start = datetime.now()
                duration = 0

                model_args = (config.params["gamma"],
                              config.params["lead_time"],
                              config.params["ns_info_state_rvs"],
                              config.params["holding_cost"],
                              config.params["backlogging_cost"],
                              config.params["setup_cost"],