haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Quintiq file version 2.0
#parent: #root
Method RemoveUnusedTripsAfterSmartPlan (
  LibOpt_Task task
)
{
  Description: 'Remove the unused trips and product in trips after running optimizer, to reduce memory consumption'
  TextBody:
  [*
    if ( not isnull( task.TaskContext() ) )
    {
      tripsInOptimizerScope := construct( Trips );
      unusedpits := construct( ProductInTrips );
      nrofunusedtrip :=0;
      
      macroplan := this.Optimization().astype( Optimization ).MacroPlan(); 
      taskcontext := task.TaskContext().astype( TaskContextSmartPlan ); 
      taskcontext.GetUnusedPIT( &unusedpits, nrofunusedtrip );
      
      alltripsinrun := selectset( taskcontext, ProductInTrip.Trip, trip, true, true );
      totaltripinrun := alltripsinrun.Size(); 
      
      usedpercentage := guard( ( ( totaltripinrun - nrofunusedtrip )/ totaltripinrun * 100 ), 0 );
      
      minpercentage := macroplan.GlobalParameters_MP().MinToKeepTripInUsedPercentage();
      
      debuginfo(  'total trips in run = ', totaltripinrun, 'used % = ', usedpercentage, 'unused pit=', 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' }
}