| 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 ); | 
|   *] | 
| } |