! Q,r inventory model( EOQRMODL);
! Keywords: Inventory, EOQ model, Lead times, Q-R model, Safety stock;
! Find the order quantity, Q,
 and re-order point, R, for a product with...;
 DATA:
  D  = 10045;  ! Mean demand/period;
  SDD=  4388;   ! S.D. in demand/period;
  L  =   1.1;   ! Lead time in periods;
  SDL= 0.46152; ! S.D. in lead time in periods;
  K  = 300; ! Fixed order cost, regardless of order size;
  P  = 121; ! Penalty cost/unit unsatisfied demand;
  H  = 7.3; ! Holding cost/unit/period;
  HP = 7.3; ! Holding cost/period on pipeline inventory.
             If we do not pay until delivery, then 
             typically HP < H;
  CM = 81;  ! Purchase cost/unit;
  TC = 4;   ! Transport cost per unit;
 ENDDATA

!-------------------------------------------;
! The Q,R inventory model;
! Variables:
    R = reorder point. Place an order when
        physical inventory + pipeline inventory drops to R.
    Q = amount to order at an order point;
  ! A standard definition is:
      safety stock = R - L*D;

 MLD = L * D;  ! Mean lead time demand;

! s.d. in lead time demand;
  SLD=(SDD * SDD * L + D * D * SDL * SDL)^.5;

! Expected cost/ period is ECOST;
 MIN = ECOST;
  ECOST = COSTORD + COSTCYC + COSTSFT + COSTPEN + COSTPIPE + COSTPURCH + COSTRANS;
  COSTORD = ( K * D/ Q); ! The fixed order cost contribution;
  COSTCYC = H * Q/2;     ! Holding cost on "cycle" inventory;
  COSTSFT = H*( R - MLD + BR); ! Holding cost of safety stock;
  COSTPEN = P * D * BR/ Q;! Shortage cost penalties;
  COSTPIPE = HP * MLD;    ! Cost of inventory in the order pipeline;
  COSTPURCH = D * CM;     ! Purchase cost;
  COSTRANS = TC * D;      ! Transport cost;

!Expected amount short/cycle.  @PSL() is
  the standard Normal linear loss function;
 BR = SLD * @PSL( Z);

!@PSN()is the standard Normal left tail prob.;
 @PSN( Z) =  P * D /( P * D + H * Q);

 R = MLD + SLD * Z;     ! Reorder point;
! It is nice to know the safety stock;
  SSTOCK = R - MLD;
  @FREE( SSTOCK);
! The following are all to help solve it faster;
 Q >= (2*K*D/H)^.5;
 @BND( - 3, Z, 3);
 @FREE( ECOST);   @FREE( R); 
 @FREE( COSTORD); @FREE( COSTCYC);
 @FREE( COSTSFT); @FREE( COSTPEN);
 @FREE( Z);       @FREE( BR);