Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method PlanFeedbackPIT ( 
 | 
  LibOpt_Scope scope, 
 | 
  RunContextForCapacityPlanning runcontext 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    pitcount := 0;  
 | 
    traverse( scope.GetPeriodInOptimizerRun(), Elements.UnitPeriod, up, not up.IsPeriodFrozen() )  
 | 
    { 
 | 
      validfeedbackpit := selectset( up, Feedback.astype( FeedbackProductInTrip ), fbpit, true, fbpit.GetIsValidFeedback() );  
 | 
      // create pit if needed 
 | 
      traverse( validfeedbackpit, Elements, fbpit )  
 | 
      { 
 | 
        created := false;  
 | 
        trip := fbpit.Trip();  
 | 
        if ( isnull( trip ) ) 
 | 
        { 
 | 
          laneleg := fbpit.LaneLeg();  
 | 
          if ( not isnull( laneleg ) )  
 | 
          { 
 | 
            trip := Trip::Create( laneleg, up.Period_MP() );  
 | 
            trip.CalcDeparture();  
 | 
            created := true;  
 | 
          } 
 | 
        } 
 | 
        departingpriortoscope := trip.Departure() < maxvalue( up.Unit().EndOfFrozen(), runcontext.FirstPeriod_MP().Start() );  
 | 
        if ( created and departingpriortoscope )  
 | 
        { 
 | 
          trip.Delete();  
 | 
        } 
 | 
        tripexists := not isnull( trip );  
 | 
        if ( tripexists and not departingpriortoscope )  
 | 
        { 
 | 
          pit := fbpit.ProductInTrip(); 
 | 
          if ( isnull( pit ) )  
 | 
          { 
 | 
            product := select( up.MacroPlan(), Product_MP, p, true, p.ID() = fbpit.ProductID() );  
 | 
            pit := trip.AddProduct( product, 0.0, false );     
 | 
          }  
 | 
          if ( guard( not pit.Trip() = trip, true ) )  
 | 
          { 
 | 
            info( 'Warning: cannot find trip for pit. Tripd id = ', pit.TripID(), 'product ID = ', pit.ProductID() );  
 | 
          } 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
          info( 'Warning: could not create trip for feedback with ID ', fbpit.ID(), 'Departing prior to scope = ', departingpriortoscope );  
 | 
        } 
 | 
      } 
 | 
       
 | 
      // propgate relations - used below 
 | 
      Transaction::Transaction().Propagate( relation( FeedbackProductInTrip, ProductInTrip ) );  
 | 
       
 | 
      pits := selectset( validfeedbackpit, Elements.ProductInTrip, pit, true, true ).Unique();  
 | 
      traverse( pits, Elements, pit, not pit.Trip().Departure() < maxvalue( up.Unit().EndOfFrozen(), runcontext.FirstPeriod_MP().Start() ) )  
 | 
      { 
 | 
        pit.HasUserQuantity( false );  
 | 
        feedbackqty := sum( pit, FeedbackProductInTrip, fb, true, fb.FeedbackQuantity() );  
 | 
        if ( pit.OptimizerQuantity() < feedbackqty )  
 | 
        { 
 | 
          pit.OptimizerQuantity( feedbackqty );  
 | 
          pitcount++;  
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    debuginfo(  'Planned feedback for #pit = ', pitcount ); 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |