Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method AddClosureForSPIP ( 
 | 
  TransformerSmartPlan tranformersmartplan, 
 | 
  LibOpt_Scope scope, 
 | 
  RunContextForCapacityPlanning runcontext 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // >> begin compute relation to last SPIP in scope 
 | 
    traverse( runcontext.FirstPeriod_MP().MacroPlan(), StockingPoint_MP, sp )  
 | 
    { 
 | 
      sp.MetaOptimizerLastSPIP( relflush );  
 | 
    } 
 | 
     
 | 
    stockingpoints := construct( StockingPoint_MPs );  
 | 
    traverse( scope.GetStockingPointInPeriodInOptimizerRun(), Elements, spip, not spip.StockingPoint_MP().IsPlannedInfinite() )  
 | 
    { 
 | 
      sp := spip.StockingPoint_MP();  
 | 
      start := spip.Start();  
 | 
      if ( isnull( sp.MetaOptimizerLastSPIP() ) )   
 | 
      { 
 | 
        stockingpoints.Add( sp );  
 | 
        sp.MetaOptimizerLastSPIP( relset, spip ); 
 | 
      }  
 | 
      else if ( start > sp.MetaOptimizerLastSPIP().Start() )  
 | 
      { 
 | 
        sp.MetaOptimizerLastSPIP( relset, spip );  
 | 
      }   
 | 
    } 
 | 
    // << end compute relation to last SPIP in scope 
 | 
     
 | 
    traverse( stockingpoints, Elements.MetaOptimizerLastSPIP, spip )  
 | 
    { 
 | 
      traverse( spip,  
 | 
                ProductInStockingPointInPeriod.astype( ProductInStockingPointInPeriodPlanning ),  
 | 
                pispip,  
 | 
                scope.Contains( pispip.ProductInStockingPoint_MP().PISPInOptimizerRun() ) 
 | 
                and ( isnull(  pispip.PISPIPInOptimizerRun() ) 
 | 
                      or not scope.Contains(  pispip.PISPIPInOptimizerRun() ) ) ) // those pispips adjacent to spip not in scope for which we know there is some other pispip in scope. Since spip is latest period we also know 
 | 
      {                                                                           // this pispip has period < spip 
 | 
        pispiptoadd := pispip;  
 | 
        repeat  // keep adding and go back period until we hit the pispip in scope  
 | 
        { 
 | 
          scope.Add( pispiptoadd ); 
 | 
          pispiptoadd := pispiptoadd.PreviousPlanningPISPIP();  
 | 
        } 
 | 
        until ( scope.Contains( pispiptoadd.PISPIPInOptimizerRun() ) ) 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |