! Model of a 3 level, PLant -> DC -> customer supply chain;
! Keywords: @IN, @INSERT, Set generation, Supply chain;
SETS:
 plant: pcap;
 dc;
 cust: cdem;
 pxd( plant, dc): pdcost, pdship;
 dxc( dc, cust): dccost, dcship;
! Supplemental sets;
 pxdxc( plant, dc, cust): pdcvol;
 pxc( plant, cust): pcvol;
ENDSETS
DATA: ! The plants and their capacities; plant, pcap = A 9 B 8 ; ! The Distribution Centers; dc = X, Y, Z ; ! Customers and their demands; cust, cdem = C1 3 C2 5 C3 4 C4 2 ; ! Cost/unit of shipping from a plant to a DC; pxd, pdcost= A X 1 A Y 2 B Y 1 B Z 2 ; ! Cost/unit of shipping from a DC to a customer; dxc, dccost= X C1 5 X C2 8 Y C1 9 Y C2 6 Y C3 7 Z C2 8 Z C3 7 Z C4 4 ; ENDDATA SUBMODEL supplychain: ! Minimize the cost of plant to DC shipments plus cost of DC to customer shipments; min = costpd + costdc; costpd = @SUM( pxd( p, d): pdcost( p, d) * pdship( p, d)); costdc = @SUM( dxc( d, c): dccost( d, c) * dcship( d, c)); ! Plant capacity constraints; @FOR( plant( p): pcap( p) >= @SUM( pxd( p, d): pdship( p, d)); ); ! Flow balance at each DC; @FOR( dc( d): @SUM( pxd( p, d): pdship( p, d)) = @SUM( dxc( d, c): dcship( d, c)); ); ! Demand constraint at each customer; @FOR( cust( c): @SUM( dxc( d, c): dcship( d, c)) = cdem( c); ); ! Add constraints to force consistency between.. ; ! the pdcvol variables.. ; ! and the pdship variables; @FOR( pxd( p, d): pdship( p, d) = @SUM( pxdxc( p, d, c): pdcvol( p, d, c)); ); ! and the dcship variables; @FOR( dxc( d, c): dcship( d, c) = @SUM( pxdxc( p, d,c): pdcvol( p, d, c)); ); ! and the pcvol variables; @FOR( pxc( p, c): pcvol( p, c) = @SUM( pxdxc( p, d, c): pdcvol( p, d, c)); ); ENDSUBMODEL
CALC: ! Construct the supplemental sets; ! Element ( p, d, c) is in pxdxc only if the path p->d->c exists; @for( pxd( p, d): ! Can ship from p to d; @for( dxc( d, c): ! Can ship from d to c; @insert( pxdxc, p, d, c); ! Put it in the set; ); ); ! Element ( p, c) is in pxc only if there is some path from p to c; @FOR( plant( p): @FOR( cust( c): ! If there is some DC d such that p->d exists and d->c exists, then add ( p, c) to set pxc; @IFC( @SUM( pxd( p, d): @IN( pxd, p, d) #and# @IN( dxc, d, c)) #ge# 1: @INsert( pxc, p, c); ); ); ); @SOLVE( supplychain); @WRITE( ' Solution report', @NEWLINE(1)); @WRITE( ' Total cost= ', costpd + costdc, @NEWLINE( 1)); @WRITE( ' Inbound costs= ', costpd,', Outbound costs= ', costdc, @NEWLINE(1)); @WRITE( ' Plant DC Shipped', @NEWLINE(1)); @FOR( pxd( p, d) | pdship( p, d) #GT# 0: @WRITE( @FORMAT( plant( p),'9s'),' ',@FORMAT( dc( d),'9s'), @FORMAT( pdship( p, d),'9.2f'), @NEWLINE(1)); ); @WRITE( @NEWLINE(1),' DC Cust Shipped', @NEWLINE(1)); @FOR( dxc( d, c) | dcship( d, c) #GT# 0: @WRITE( @FORMAT( dc( d),'9s'),' ',@FORMAT( cust( c),'9s'), @FORMAT( dcship( d, c),'9.2f'), @NEWLINE(1)); ); @WRITE( @NEWLINE(1),' Plant Cust Volume', @NEWLINE( 1)); @FOR( pxc( p, c): @WRITE( @FORMAT( plant( p),'9s'),' ',@FORMAT( cust( c),'9s'), ' ', @FORMAT( pcvol( p, c), '9.2f'), @NEWLINE(1)); ); @WRITE( @NEWLINE(1),' Plant DC Cust Volume', @NEWLINE( 1)); @FOR( pxdxc( p, d, c): @WRITE( @FORMAT( plant( p),'9s'),' ', @FORMAT( dc( d), '9s'),' ', @FORMAT( cust( c),'9s'), ' ', @FORMAT( pdcvol( p, d, c), '9.2f'), @NEWLINE(1)); ); ENDCALC