admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
48
49
50
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' }
}