| Quintiq file version 2.0 | 
| #parent: #root | 
| Method SetPISPIPRoutings ( | 
|   ProductInStockingPointInPeriods pispips, | 
|   Operation process, | 
|   LibOpt_Scope scope, | 
|   RunContextForCapacityPlanning runcontext | 
| ) | 
| { | 
|   Description: 'Set the relation to the routings of the given PISPIPs which are used for smart plan 1 step upstream.' | 
|   TextBody: | 
|   [* | 
|     // tomvdh Nov-17-2016 (created) | 
|     traverse(  pispips, Elements, pispip ) | 
|     {   | 
|       period := pispip.Period_MP(); | 
|       // Traverse over the operations that produce this product as an output | 
|       // If this product is a byproduct, we do not want to add its operations, unless they only produce byproduct. | 
|       // This is to avoid adding products to the smart plan that are only related to the smart plan input pispips because they are produced together with the same byproduct | 
|       traverse( pispip, ProductInStockingPoint_MP.OperationOutput.Operation, operation, | 
|                 ifexpr( runcontext.IsSmartPlanForPeriodTask(), isnull( process ) or process.RoutingForPlanningMatrix() = operation.RoutingStep().Routing(), true ) //Only check this for period task smart plan. When an operation is specified, only set the routing of that operation. | 
|                 and operation.GetIsAvailableForOptimization()                                // The operation must be available | 
|                 and PeriodTaskOperation::GetIsValidPeriodTask( operation, period )       // The resulting period task must be valid | 
|                 and ( not pispip.ProductInStockingPoint_MP().Product_MP().IsByProduct()  // This product is not a byproduct | 
|                       or forall( operation, OperationOutput.ProductInStockingPoint_MP.Product_MP, product, product.IsByProduct() ) ) )  // or all outputs are byproducts | 
|       { | 
|         scope.Add( operation.RoutingStep().Routing().RoutingOfSmartPlanPISPIPSInOptimizerRun( relnew ) );  | 
|       } | 
|     } | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |