Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method AddClosureTripsOperations ( 
 | 
  output LibOpt_Scope out_scope 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    addedopperiods := 0;  
 | 
     
 | 
    /* 
 | 
    wopuld need correction because in case of lead time period will be different for the input pispips 
 | 
    traverse(  out_scope.GetPISPIPInOptimizerRun(), Elements, pispip )  
 | 
    { 
 | 
      traverse( pispip, ProductInStockingPoint_MP.OperationOutput.Operation, op, op.IsEnabled() )  
 | 
      { 
 | 
        if ( not out_scope.Contains( op.OperationInOptimizerRun() ) ) 
 | 
        { 
 | 
          inputpispips := selectset(  op,  
 | 
                                      OperationInput.ProductInStockingPoint_MP.ProductInStockingPointInPeriodPlanning,  
 | 
                                      inppispip,  
 | 
                                      true,  
 | 
                                      inppispip.Period_MP() = pispip.Period_MP() );  
 | 
                                       
 | 
          outputpispips := selectset( op,  
 | 
                                      OperationOutput.ProductInStockingPoint_MP.ProductInStockingPointInPeriodPlanning,  
 | 
                                      outpispip,  
 | 
                                      true,  
 | 
                                      outpispip.Period_MP() = pispip.Period_MP() );  
 | 
                                                                                       
 | 
          if ( forall( inputpispips,  
 | 
                       Elements, inppispip,   
 | 
                       out_scope.Contains( inppispip.PISPIPInOptimizerRun() ) )   
 | 
               and  
 | 
               forall( outputpispips,  
 | 
                       Elements, outpispip,   
 | 
                       out_scope.Contains( outpispip.PISPIPInOptimizerRun() )  ) ) 
 | 
          {  
 | 
            out_scope.Add( op );  
 | 
       
 | 
            // Add the units to which those operations belong to unitsforoptimization 
 | 
            unit := op.Unit(); 
 | 
            out_scope.Add(  unit );  
 | 
            period := pispip.Period_MP();  
 | 
     
 | 
            // Add the related unit periods to unitperiodsforoptimization 
 | 
            unitperiod := UnitPeriod::FindUnitPeriodTypeIndex( unit.ID(), period.Start(), period.End() ); 
 | 
            if( not unitperiod.IsPeriodFrozen() ) 
 | 
            { 
 | 
              out_scope.Add(  unitperiod );  
 | 
            }   
 | 
       
 | 
            // Create/Select the related periodtaskoperation and add it to PTOperationsForOptimization 
 | 
            periodtaskoperation := PeriodTaskOperation::FindPeriodTaskOperationTypeIndex( period.Start() , op.ID() ); 
 | 
         
 | 
            if( isnull( periodtaskoperation ) ) 
 | 
            { 
 | 
              periodtaskoperation := PeriodTaskOperation::Create( op, unitperiod, 0.0, false ); 
 | 
              // I think this transaction propagate is necessary, we need to get the dependent demand from the newly created periodtask 
 | 
              Transaction::Transaction().Propagate( relation( PeriodTaskOperation, DependentDemand ) ) 
 | 
         
 | 
            } 
 | 
              out_scope.Add( periodtaskoperation );    
 | 
            } 
 | 
            addedopperiods++;  
 | 
         }      
 | 
      } 
 | 
    } 
 | 
    */ 
 | 
     
 | 
    addedpit := 0;  
 | 
    traverse(  out_scope.GetPISPIPInOptimizerRun(), Elements, pispip )  
 | 
    { 
 | 
      traverse(  pispip, astype( ProductInStockingPointInPeriodPlanningLeaf ).AsArrivalPISPIP, pit )  
 | 
      { 
 | 
        if ( out_scope.Contains( pit.Trip().TripInOptimizerRun() ) 
 | 
             and out_scope.Contains( pit.DeparturePISPIP().PISPIPInOptimizerRun() )  
 | 
             and not out_scope.Contains( pit.ProductInTripInOptimizerRun() ) ) 
 | 
        { 
 | 
          out_scope.Add( pit );  
 | 
          addedpit++   
 | 
        } 
 | 
      }         
 | 
    } 
 | 
    debuginfo( 'Closure added (op, period):', addedopperiods, ' added pit:', addedpit ); 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |