Exemple #1
0
def construct_nvmc():
    from msppy.msp import MSLP
    nvmc = MSLP(T=3, sense=-1, bound=100)
    nvmc.add_MC_uncertainty(Markov_states=[[[0]], [[4], [6]], [[4], [6]]],
                            transition_matrix=[[[1]], [[0.5, 0.5]],
                                               [[0.3, 0.7], [0.7, 0.3]]])
    for t in range(3):
        m = nvmc[t]
        buy_now, buy_past = m.addStateVar(name='bought', obj=-1.0)
        if t != 0:
            sold = m.addVar(name='sold', obj=2)
            unsatisfied = m.addVar(name='unsatisfied')
            recycled = m.addVar(name='recycled', obj=0.5)
            m.addConstr(sold + unsatisfied == 0,
                        uncertainty_dependent={'rhs': 0})
            m.addConstr(sold + recycled == buy_past)
    return nvmc
Exemple #2
0
from msppy.msp import MSLP
from msppy.solver import Extensive,SDDP
import gurobipy
T = 4
PurchasePrice = [5.0, 8.0]
Demand = [[10.0, 15.0], [12.0, 20.0], [8.0, 20.0]]
RetailPrice = 7.0

newsVendor = MSLP(T=T, sense=1, bound=-1000)
newsVendor.add_MC_uncertainty(
    Markov_states = [
        [[5.0]],
        [[5.0]],
        [[5.0],[8.0]],
        [[5.0],[8.0]]
    ],
    transition_matrix = [
        [[1]],
        [[1]],
        [[0.6,0.4]],
        [[0.3,0.7],[0.3,0.7]]
    ]
)
for t in range(T):
    m = newsVendor[t]
    now, past = m.addStateVar(ub=100, name="stock")
    if t > 0:
        buy = m.addVar(name="buy", uncertainty_dependent=0)
        sell = m.addVar(name="sell", obj=- RetailPrice)
        m.addConstr(now == past + buy - sell)
        random = m.addVar(lb=-gurobipy.GRB.INFINITY, ub=gurobipy.GRB.INFINITY, name="demand")
        m.addConstr(random == 20, uncertainty={'rhs': Demand[t-1]})