yanweiyuan3
2023-09-26 96376f881d2511382f1063242206cff71781ea0b
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
60
61
Quintiq file version 2.0
#parent: #root
Method CapacityPlanningAlgorithmHandleFeasibleOperationDependentDemandInputGroup (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  PeriodTaskOperation periodtaskoperation,
  const RunContextForCapacityPlanning runcontext
)
{
  Description: 'Assign the optimal quantity from optimizer for dependent demand in input group.'
  TextBody:
  [*
    // Dependent demand of input group fulfillment
    ptperiod := periodtaskoperation.UnitPeriod().Period_MP();
    operation := periodtaskoperation.Operation();
    getfromperiodtask := this.GetPeriodsFromPeriodTaskOperation(); 
    traverse( periodtaskoperation, 
              DependentDemandInputGroup, 
              dd, 
              dd.HasRegularProductForOptimizer() or dd.OperationInput().GetIsProductInOptimizerRun( runcontext.IsPostProcessing() ) )
    {
      fulfilledqty := 0.0; 
      
      if( operation.HasLeadTime() )     // Get the dependent demands that is located at different period from the period of period task.
      {
        // compute dependent demand periods
        pispipperiods := construct( Period_MPs, constcontent ); 
        if ( getfromperiodtask ) // in case we are able to get from period tasks, below method refinds periodtask for (operation, ptperiod) i.e. periodtaskoperation and then output dep.demand periods
        {
          traverse( periodtaskoperation, DependentDemand.ProductInStockingPointInPeriodPlanningLeaf.Period_MP, ddperiod ) 
          {
            pispipperiods.Add( ddperiod ); 
          }
        }
        else
        {
          CapacityPlanningSuboptimizer::GetOperationDependentDemandPeriods( ptperiod, operation, &pispipperiods, getfromperiodtask );
        }
        
        fulfilledqty := sum( pispipperiods, Elements, pispipperiod,
                             this.GetOptimalValue( program.PartialOperationDemandQtyVariables().Get( dd.OperationInput(), pispipperiod, ptperiod ) ) );
        if ( runcontext.IsMetaIteration() and operation.IsBlending() ) // no filtering for numerical sensitive blending operation in meta optimizer
        {                     
          fulfilledqty := sum( pispipperiods, Elements, pispipperiod,
                               this.GetOptimalValueUnfiltered( program.PartialOperationDemandQtyVariables().Get( dd.OperationInput(), pispipperiod, ptperiod ) ) );    
        }                     
      }
      else
      { 
        // note that in case there is no lead time then the set of dependent demand periods just equals the singleton set {ptperiod}
        fulfilledqty := this.GetOptimalValue( program.OperationDemandQtyVariables().Get( dd.OperationInput(), ptperiod ) );
        if( runcontext.IsMetaIteration() and operation.IsBlending() ) // no filtering for numerical sensitive blending operation in meta optimizer
        {
          fulfilledqty := this.GetOptimalValueUnfiltered( program.OperationDemandQtyVariables().Get( dd.OperationInput(), ptperiod ) );
        }
      }
      
      dd.OptimizerFulfilledQuantity( fulfilledqty );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}