Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method RemoveUnusedTripsAfterOptimizerRun ( 
 | 
  LibOpt_Scope scope 
 | 
) 
 | 
{ 
 | 
  Description: 'Remove the unused trips and product in trips after running optimizer, to reduce memory consumption' 
 | 
  TextBody: 
 | 
  [* 
 | 
    tripsInOptimizerScope := construct( Trips ); 
 | 
    unusedpits := construct( ProductInTrips ); 
 | 
    nrofunusedtrip :=0; 
 | 
     
 | 
    macroplan := this.Optimization().astype( Optimization ).MacroPlan();  
 | 
    this.GetUnusedPIT( scope, &unusedpits, nrofunusedtrip ); 
 | 
     
 | 
    // remove tiny cplex quantities 
 | 
    traverse( unusedpits, Elements, pit )  
 | 
    { 
 | 
      pit.OptimizerQuantity( 0.0 );  
 | 
    } 
 | 
     
 | 
     
 | 
    alltripsinrun := selectset( scope.GetPeriodInOptimizerRun(), Elements.UnitPeriod.PeriodTask_MP.astype( PeriodTaskLaneLeg ).Trip, trip, true, true ); 
 | 
    totaltripinrun := alltripsinrun.Size();  
 | 
     
 | 
    usedpercentage := guard( ( ( totaltripinrun - nrofunusedtrip )/ totaltripinrun * 100 ), 0 ); 
 | 
     
 | 
    minpercentage := macroplan.GlobalParameters_MP().MinToKeepTripInUsedPercentage(); 
 | 
     
 | 
    debuginfo(  'trips in run = ', totaltripinrun, 'used % = ', usedpercentage, 'unused pits = ', unusedpits.Size() );  
 | 
    // delete if use percentage < minimum percentage 
 | 
    if ( usedpercentage <  minpercentage ) 
 | 
    { 
 | 
      // Delete the productintrips that were part of the optimizer run, that have an optimizer quantity of 0, 
 | 
      // that are not manual planning and that do not have feedback 
 | 
      ProductInTrip::Delete( unusedpits ); 
 | 
     
 | 
      tripsInOptimizerScope := selectset( alltripsinrun, Elements, trip,  
 | 
                                          trip.ProductInTrip( relsize ) = 0 ); 
 | 
    }                                       
 | 
     
 | 
    tripsOutOfScope := selectset( macroplan, Unit.Lane.LaneLeg.Trip, trip,  
 | 
                                    not ( trip.HasValidArrival() and trip.HasValidDeparture() ) ); 
 | 
     
 | 
    tripsToDelete := tripsInOptimizerScope.Union( tripsOutOfScope ).Unique(); 
 | 
    Trip::Delete( tripsToDelete ); 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |