yanyuan
2023-11-10 143ef74e2eeee697ac8fda3d9032a790fbb4e146
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
Quintiq file version 2.0
#parent: #root
Method AddTermsToServiceLevelConstraints (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  MPConstraint constr,
  const ServiceLevelBase sl,
  Real scalefactor_salesdemandqty_constfromsd,
  Real scalefactor_rhs_constr,
  output Real rhsfromtarget_o,
  const LibOpt_Scope scope
) const as Number
{
  Description: 'Add the sales demand term to the service level from sales demand constraints'
  TextBody:
  [*
    // Only define the constraints if the sd needs to be planned and is on a pispip that is part of this optimizer run
    constantterm := 0.0; 
    addedvariableterms := 0; 
    traverse( sl.GetSalesDemandInPeriodsConst(), Elements, sd,
              sd.NeedsToBePlanned()
              and sd.IsWithinThresholdQuantity() )
    {
      uomconversion := sd.DefaultUOMConversionFactor();
    
      inscope := guard( scope.Contains( sd.AsPlanningBaseSalesDemandInPeriod().PISPIPInOptimizerRun() ) , false ); 
    
      if ( inscope ) 
      {   
        if( sd.istype( LeafSalesDemandInPeriod ) )
        {
            constr.NewTerm( -uomconversion * scalefactor_salesdemandqty_constfromsd, program.SalesDemandQtyVariables().Get( sd.astype( LeafSalesDemandInPeriod ) ) );
        }
        else if( sd.istype( DisaggregatedSalesDemandInPeriod ) )
        {
            constr.NewTerm( -uomconversion * scalefactor_salesdemandqty_constfromsd, program.DisaggregatedSalesDemandQtyVariables().Get( sd.astype( DisaggregatedSalesDemandInPeriod ) ) );
        }
        addedvariableterms++; 
      }
      else
      {
        constantterm := constantterm + sd.FulfilledQuantityInDefaultUOM(); 
      }
      // For the rhs of the target constraint of the fulfillment target constraint we need to sum over all sales demand quantities
      rhsfromtarget_o := rhsfromtarget_o + sd.QuantityInDefaultUOM(); // note note used for current constraint 'constr' - just to collect total sales demand qty
    }
    
    newrhs := this.GetConstraintRHS( constr, scalefactor_rhs_constr ) + constantterm; // variable is added on the right, so we *add* constantterm to the RHS
    constr.RHSValue( newrhs * scalefactor_rhs_constr );
    return addedvariableterms;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}