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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForHigherLevelSalesDemands (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  Description: 'Sum of disaggregatedsalesdemandinperiod should not exceed aggregatedsalesdemandinperiod'
  TextBody:
  [*
    linkedaggregatedsalesdemandconstrname := typeof( MPLinkedAggregatedSalesDemandConstraint );
    scalefactor_disaggregatedsalesdemandqty_const := this.ScaleConstraintTerm( typeof( MPDisaggregatedSalesDemandQtyVariable ) , linkedaggregatedsalesdemandconstrname );
    scalefactor_rhs_const := this.ScaleConstraintRHS( linkedaggregatedsalesdemandconstrname, 1.0 );
    
    // Aggregated sales demands for higher product level
    traverse( scope.GetAggregatedSalesDemandInPeriodInRunConst(), Elements, asdip )
    {               
        // Constraint: Sum of disaggregated sdips should equal or smaller than Aggregated Demand Quantity
        // DelayedAggregatedSalesDemandQty( period ) <= AggregatedSalesDemandInPeriod.Quantity ∀ AggregatedSalesDemandInPeriod
        constaggregated := program.LinkedAggregatedSalesDemandConstraints().New( asdip );
        constaggregated.Sense( '<=' );
        constaggregated.RHSValue( scalefactor_rhs_const * asdip.GetQuantityForOptimizer( scope ) );
    
        // Traverse the children ( Disaggregated Sales demands )
        traverse ( asdip, 
                   DisaggregatedSalesDemandInPeriod, 
                   dasdip, 
                   not dasdip.IsPostponed() ) // note we only define DisaggregatedSalesDemandQtyVariables for unpostponed dasdip
        {
          if( scope.Contains( dasdip.AsPlanningBaseSalesDemandInPeriod().PISPIPInOptimizerRun() ) )
          {
            constaggregated.NewTerm( 1.0 * scalefactor_disaggregatedsalesdemandqty_const, program.DisaggregatedSalesDemandQtyVariables().Get( dasdip ) ); 
          }
          else
          {
            oldrhs := this.GetConstraintRHS( constaggregated, scalefactor_rhs_const );
            newrhs := oldrhs - dasdip.FulfilledQuantity();
            constaggregated.RHSValue( scalefactor_rhs_const * newrhs );
          }
        } // traverse disaggregated
        
        this.SetRHSNonNegative( constaggregated ); 
    } // traverse AggregatedSalesDemandInPeriod
  *]
  InterfaceProperties { Accessibility: 'Module' }
}