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
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' }
}