陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForOperationDependentDemandInPeriod (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope
) const
{
  Description:
  [*
    A constraint to calculate the dependent demand quantity of an input per bucket.
    Specially for dependent demand belonging to operation with pre-processing duration.
  *]
  TextBody:
  [*
    // dependent demand quantity per bucket = sum of all dependent demands that fall at that bucket
    // Specially for dependent demand belonging to operation with pre-processing duration.
    
    constddperiodname := typeof( MPOperationDependentDemandPeriodQtyConstraint );
    
    scalefactor_operationdemandqty_constddperiod := this.ScaleConstraintTerm( typeof( MPOperationDemandQtyVariable ), constddperiodname );
    scalefactor_partialoperationdemandqty_constddperiod := this.ScaleConstraintTerm( typeof( MPPartialOperationDemandQtyVariable ), constddperiodname );
    
    scalefactor_rhs_constddperiod := this.ScaleConstraintRHS( constddperiodname, 1.0 );
    
    traverse( scope.GetOperationInOptimizerRunConst(), Elements, operation, operation.HasLeadTime() )
    {
      // Only select the input where the product is included.
      traverse( operation, OperationInput, input, input.HasRegularProductforOptimizer() or input.GetIsProductInOptimizerRun( runcontext.IsPostProcessing() ) )
      {
        if ( this.GetPeriodsFromPeriodTaskOperation() ) 
        {
          traverse( operation, PeriodTaskOperationInScope, pto ) // these are the period GetPeriodsForOperation( scope, operation ) would supple
          {
            ptperiod := pto.UnitPeriod().Period_MP(); 
            
            traverse( pto, DependentDemand.ProductInStockingPointInPeriodPlanningLeaf.Period_MP, ddperiod ) 
            {
              this.InitConstraintsForOperationDependentDemandInPeriod_AddConstraint( program,
                                                                                     ptperiod, 
                                                                                     ddperiod, 
                                                                                     input, 
                                                                                     scalefactor_operationdemandqty_constddperiod, 
                                                                                     scalefactor_partialoperationdemandqty_constddperiod, 
                                                                                     scalefactor_rhs_constddperiod ); 
            }    
          }
        }
        else
        {
          periods := this.GetPeriodsForOperation( scope, operation );
      
          // Need to select all relevant periods. These are the periods in which the operation can run and their dependent demand periods
          traverse( periods, Elements, ptperiod )
          {
            ddperiods := construct( Period_MPs, constcontent );
            CapacityPlanningSuboptimizer::GetOperationDependentDemandPeriods( ptperiod, operation, &ddperiods, this.GetPeriodsFromPeriodTaskOperation() );
      
            traverse( ddperiods, Elements, ddperiod )
            {     
              this.InitConstraintsForOperationDependentDemandInPeriod_AddConstraint( program,
                                                                                   ptperiod, 
                                                                                   ddperiod , 
                                                                                   input, 
                                                                                   scalefactor_operationdemandqty_constddperiod, 
                                                                                   scalefactor_partialoperationdemandqty_constddperiod, 
                                                                                   scalefactor_rhs_constddperiod ); 
            }
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}