Lindo Systems

MODEL:
! Data for this model is read from MRP.LDT;
SETS:
! The set of parts;
 PART/ @FILE( 'MRP.LDT')/ : LT;
 ! LT(i) = Lead time to produce part i;

! The set of time periods;
 TIME / @FILE( 'MRP.LDT')/;

! A relationship called USES between pairs of parts;
 USES( PART, PART) / @FILE( 'MRP.LDT') / : NEEDS;
 ! Parent part i needs NEEDS(i, j) units of
   child part j;

! For each part and time period we're interested in;
 PXT( PART, TIME): ED, TD;
 ! ED(i, j) = External demand for part i at time j;
 ! TD(i, j) = Total demand for part i at time j;
ENDSETS

! Set NP = no. of time periods in the problem;
 NP = @SIZE( TIME);

! For each part P and period T, the total demand =
  external demand + demand generated by parents
  one lead time in the future;
 @FOR( PXT( P, T) | T + LT( P) #LE# NP :
  TD( P, T) = ED( P, T + LT( P)) + 
   @SUM( USES( P2, P): TD( P2, T + LT( P)) * 
    NEEDS( P2, P));
 );

DATA:
! Get number of parts needed in each parent child
  relation;
 NEEDS = @FILE( 'MRP.LDT');

! Get the lead times from the file;
 LT  = @FILE( 'MRP.LDT');

! Get the external demands over time for each part;
 ED  = @FILE( 'MRP.LDT');

ENDDATA
END