```! Infinite period newsvendor problem with lost sales, setup cost, and lead time = 0.!(Lost_sales0.lng). Solved by formulating as a Markov decision problem; ! Keywords: Markov decision process, inventory, lost sales; SETS: INVL; ! Possible inventory levels; DD: PD; ! Possible demands & probability; ! Our decisions can only raise inventory; DTRAN(INVL,INVL)|&1 #LE# &2: CD,X; ! Nature's decisions can only lower inventory; PTRAN(INVL,INVL)|&1 #GE# &2: CP,PR; ! X(i,ir) = joint probability of entering period in state i and ordering enough to move to state ir. PR(ir,s)= conditional probability of nature moving the state to s, given that we had moved the state to ir. CD(i,ir)= cost of making decision ir when state is i, CP(ir,s)= expected cost when nature moves state to s given state ir PD(d) = probability demand is d-1, for d = 1, 2, ...; ENDSETSDATA: V = 18; ! Revenue per unit sold; P = 2; ! Explicit shortage penalty on each lost sale; H = .7; ! Holding cost/unit per period; C = 3; ! Purchase cost per unit; K = 1; ! Fixed order cost; ! Demand distribution. Lowest corresponds to 0 demand; DD = D0 D1 D2 D3 D4; PD = .01 .90 .02 .03 .04; INVL = I0..I9; ! Possible inventory levels. Lowest corresponds to 0 inventory; ENDDATA !--------------------------------------------------; ! The sequence of events each period is: 1) Begin period with inventory level i, 2) we order enough to raise inventory to ir, 3) Demand occurs with unsatisfied demand lost, 4) Revenue, shortage penalties and holding charges are assessed; CALC: ! Compute costs of our decisions; @FOR(DTRAN(i,ir) : CD(i,ir) = K*(i #LT# ir) + C*(ir-i)); ! Compute conditional probabilities and expected costs of nature's probabilistic moves. Note, indexing starts at 1, so index 1 corresponds to inventory or demand = 0. Not out of stock case; @FOR(PTRAN(ir,s) | s #gt# 1: PR(ir,s) = @SUM(DD(i)| i-1 #eq# (ir-s): PD(i)); CP(ir,s) = H *(s-1) - V*(ir-s); ); ! Out of stock case; @FOR(PTRAN(ir,s) | s #eq# 1: PR(ir,s) = @SUM(DD(i)|i #ge# ir: PD(i)); ); @FOR(PTRAN(ir,s) | s #eq# 1 #and# PR(ir,s) #gt# 0: CP(ir,s) = P*@SUM(DD(i)|i #ge# ir: PD(i)*(i-ir))/PR(ir,s) - V*(ir-1); ); @FOR(PTRAN(ir,s) | s #eq# 1 #and# PR(ir,s) #eq# 0: CP(ir,s) = 0; ); ENDCALC ! Decision variables: X(i,ir) = probability inventory level is s and we order enough to bring it up to t, i.e., order t-s. Typically, for each s, there will only be one t such that X(i,ir) > 0; !Minimize the average cost per period; MIN=@SUM(DTRAN(i,ir): CD(i,ir)*X(i,ir)) +@SUM(DTRAN(i,ir): @SUM(PTRAN(ir,s): CP(ir,s)* X(i,ir)*PR(ir,s))); !The probabilities must sum to 1; @SUM( DTRAN(i,ir): X(i,ir)) = 1; !Rate at which we exit state i = rate of entry to i; @FOR( INVL(i): @SUM( DTRAN(i,ir): X(i,ir))= @SUM( DTRAN(j,jr): @SUM(PTRAN(jr,i):X(j,jr)*PR(jr,i))); ); ```