yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
51
52
53
54
55
56
57
58
59
Quintiq file version 2.0
#parent: #root
Method PruneProductInTrips (
  MacroPlan macroplan,
  LibOpt_Task task
)
{
  TextBody:
  [*
    totalnrpit := 0; 
    pruned := 0; 
    
    traverse( macroplan, 
              Unit.Lane.LaneLeg.Trip.ProductInTrip, 
              pit, 
              pit.Quantity() = 0 
              and not pit.HasUserQuantity() 
              and not pit.HasFeedback() ) 
    {
      totalnrpit++; 
      dest_pispip := pit.ArrivalPISPIP();
      if ( dest_pispip.IsPruningCandidate() ) // determined by looking if there is local demand ( sales, inventory ) at the pispip or in the future
      {
        startdate := dest_pispip.Start().Date(); 
        hasoutgoingtrip := exists( dest_pispip, AsDeparturePISPIP, prtrip, true, true ); 
        hasoperation := exists( dest_pispip, 
                                ProductInStockingPoint_MP.OperationInput.Routing, 
                                r, 
                                true, 
                                r.Start() <= startdate
                                and r.End() >= startdate
                                and r.IsEnabled() ); 
      
                                                                                                              
        departurepispip := pit.DeparturePISPIP(); 
        departurehasmax := guard( departurepispip.InventorySpecification().HasMaxLevel(), false ) 
                           or ( departurepispip.StockingPointInPeriod().MaxCapacity() > 0 and not departurepispip.StockingPointInPeriod().StockingPoint_MP().IsPlannedInfinite() ); 
          
        arrivalhasnostorage := guard( dest_pispip.InventorySpecification().HasMaxLevel() and dest_pispip.MaxInventoryLevel() = 0, false ) 
                               or ( dest_pispip.StockingPointInPeriod().MaxCapacity() = 0 and not dest_pispip.StockingPointInPeriod().StockingPoint_MP().IsPlannedInfinite() );      
        arrivalhasstorage := not arrivalhasnostorage;                          
        if ( not hasoperation          
             and not hasoutgoingtrip ) 
        {
          if ( arrivalhasnostorage // in this case we know for sure we can prune the product in trip
               or ( arrivalhasstorage and not departurehasmax ) ) // otherwise, also prune in case it can feasibly be left at the departure
          {
            pruned++; 
            pit.Delete(); 
          }
        }        
      } // end if 'IsPruningCandidate'
    } // end traverse pit
    
    msg := 'Total product in trips:' + [String] totalnrpit + ' Pruned:' + [String] pruned + ' Remaining = ' + [String] (totalnrpit - pruned);  
    debuginfo(  msg );
    task.Log( msg );
  *]
}