chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForOperationDependentDemands_Add (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope,
  const OperationInput input,
  const Period_MP period,
  constcontent Period_MPs pispipperiods,
  Boolean usingproportialleadtimelogic,
  Real scalefactor_partialoperationdemandqty_constddpartial,
  Real scaling,
  Real coef_relduration_partialcase
) const
{
  Description: 'Initialize constraints for dependent demands for operations which does not have an input group'
  TextBody:
  [*
    // dependent demand quantity of input products = pt quantity * factor * relative duration.
    // relative duration = 1 if there is no pre-processing.
    // 0 < relative duration <= 1 if there is pre-processing.
    
    //input: operation 
    // period = pt period 
    
    operation := input.Operation(); 
    
    // The dependent demand has to takes relative duration of the pispip period (the bucket it belongs) and the pt period into account.
    
    // To get the period of period tasks from dependent demands, it can be treated as "new supplies" of dependent demands.
    // Please read the optimizer solution design for more information.
    endofpt := period.End();      // dummy value - not used if not proportional
    startofpt := period.Start();  // dummy value - not used if not proportional
    if ( usingproportialleadtimelogic )
    { 
      endofpt := Process_MP::GetDependentDemandEndOperationLeadTime( period, operation.LeadTime() ); 
      startofpt := Process_MP::GetOperationStart( period, endofpt );
    }
    
    traverse( pispipperiods, Elements, ptperiod )
    {
      // constddpartial constraint UoM: input PISP
      constddpartial := program.PartialOperationDependentDemandQtyConstraints().New( input, ptperiod, period );
      constddpartial.Sense( '=' );
      // using default 0.0 RHS for constddpartial 
      // Term UoM: input PISP
      constddpartial.NewTerm( -1.0 * scalefactor_partialoperationdemandqty_constddpartial * scaling, program.PartialOperationDemandQtyVariables().Get( input, ptperiod, period ) );
    
      // If the leadtime logic is not proportional, then the relative duration is 1
      // Otherwise, calculate the relative duration
      relativeduration := 1.0;
      if( usingproportialleadtimelogic )
      {
        start := Process_MP::GetNewSupplyStart( startofpt, ptperiod );
        end := Process_MP::GetNewSupplyEnd( endofpt, ptperiod );
        relativeduration := Process_MP::GetRelativeDuration( start, end, period);
      }
    
      // Term: dependentdemandqty * PTQty variable
      // UoM:  [Unit to input PISP] *   [Unit]
      constddpartial.NewTerm( coef_relduration_partialcase * relativeduration,  // relative duration applied multiplicatively in order to equal PeriodTaskOperation::GetDependentDemandQuantity( 1.0, input, relativeduration ).
                              program.PTQtyVariables().Get( operation, period ) );
    } //end traverse
  *]
  InterfaceProperties { Accessibility: 'Module' }
}