Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CompleteForSmallPuzzle ( 
 | 
  LibOpt_Task task, 
 | 
  RunContextForCapacityPlanning runcontext, 
 | 
  LibOpt_Scope outscope 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    threshold_when_to_complete := 0.75; // at 95% of all pit or pto's we just add the rest  
 | 
    macroplan := this.Optimization().astype( Optimization ).MacroPlan();  
 | 
     
 | 
    nrpispipsinscope := outscope.GetPISPIPInOptimizerRun().Size();  
 | 
    if ( nrpispipsinscope = runcontext.NumberOfPISPIPPlanningGlobal() )  
 | 
    { 
 | 
      pto := outscope.GetPeriodTaskOperationInOptimizerRun();  
 | 
      nrptoglobal := sum( macroplan, Unit.Operation, op, true, op.PeriodTaskOperation( relsize ) );  
 | 
      if ( pto.Size() < nrptoglobal and pto.Size() >= threshold_when_to_complete * nrptoglobal )  
 | 
      { 
 | 
        debuginfo(  'Completing operation for small puzzle. Adding # period task:', nrptoglobal - pto.Size() );   
 | 
        traverse( macroplan, Unit, unit, unit.IsInOptimizerPuzzle() )  
 | 
        { 
 | 
          traverse( unit, Operation.PeriodTaskOperation, periodtaskop, periodtaskop.UnitPeriod().Period_MP().IsInOptimizerPuzzle() and  
 | 
                    PeriodTaskOperation::GetIsValidPeriodTask( periodtaskop.Operation(), periodtaskop.UnitPeriod().Period_MP() ) )  
 | 
          { 
 | 
            outscope.Add( periodtaskop );  
 | 
          } 
 | 
        } 
 | 
      } 
 | 
       
 | 
      pit := outscope.GetProductInTripInOptimizerRun();  
 | 
      nrpitglobal := sum(  macroplan, Unit.Lane.LaneLeg.Trip, trip, trip.GetIsValidNonFrozenTrip(), trip.ProductInTrip( relsize ) );  
 | 
      if ( pit.Size() < nrpitglobal and pit.Size() >= threshold_when_to_complete * nrpitglobal )  
 | 
      { 
 | 
        debuginfo(  'Completing product in trips for small puzzle. Adding # pit:', nrpitglobal - pit.Size() );  
 | 
        traverse( macroplan, Unit, unit, unit.IsInOptimizerPuzzle() )  
 | 
        { 
 | 
          departurecutoff := maxvalue(  unit.EndOfFrozen(), runcontext.FirstPeriod_MP().Start() );  
 | 
          traverse( unit,  
 | 
                    Lane.LaneLeg.Trip.ProductInTrip,  
 | 
                    prodintrip,  
 | 
                    prodintrip.Trip().GetIsValidNonFrozenTrip()  
 | 
                    and prodintrip.IsInOptimizerPuzzle() 
 | 
                    and prodintrip.Trip().Departure() >=  departurecutoff )  
 | 
          { 
 | 
            outscope.Add( prodintrip );  
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |