陈清红
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
Quintiq file version 2.0
#parent: #root
Method AddTermsToInventorySpecificationConstraint (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  MPConstraint constr,
  const ProductInStockingPointInPeriodPlanning pispip,
  Real specificationindays,
  const LibOpt_Scope scope,
  Real scalefactor_demandfulfillmentinpispip_constr,
  Real scalefactor_rhs_constr
) const
{
  Description: 'Updates the terms/RHS of the input inventory specification constraint'
  TextBody:
  [*
    // If the input pispip is a leaf pispip, we only need to add terms related to this product
    activepispips := construct( ProductInStockingPointInPeriodPlannings, constcontent );
    if( pispip.IsLeafPlanning() )
    {
      activepispips.Add( pispip )
    }
    // If the input pispip is not a leaf pispip, we need to add terms for all of its leaf products
    else
    {
      traverse( pispip.GetLeavesOfProductDimensionConst(), Elements.astype( ProductInStockingPointInPeriodPlanning ), activepispip,
                  not activepispip.ProductInStockingPoint_MP().IsNegativeInventoryAllowed() )
      {
        activepispips.Add( activepispip );
      }
    }
    
    delta_term_forRHS := 0.0; 
    traverse( activepispips, Elements, activepispip )
    {
      relevantpispips := activepispip.GetNextPlanningPISPIPsForOpt( specificationindays );
      remainingdays_o := specificationindays;
    
      
      traverse( relevantpispips, Elements, nextpispip )
      {
        ratio := nextpispip.GetPISPIPRatioForSpecificationInDays( remainingdays_o );
      
        // If the next pispip is part of this optimizer run, add a term to the constraint, otherwise update the RHS
        if( scope.Contains( nextpispip.PISPIPInOptimizerRun() ) )
        {
          // Term: ratio * DemandFulfillmentInPISPIP variable
          // UoM:  [-]   *         [PISP]
          constr.NewTerm( -ratio * scalefactor_demandfulfillmentinpispip_constr, program.DemandFulfillmentInPISPIPVariables().Get( nextpispip ) );
        }
        else
        {
          delta_term_forRHS := delta_term_forRHS + (ratio * nextpispip.FulfilledDemandQuantity()); 
        }
      }
    }
    newrhs := this.GetConstraintRHS( constr, scalefactor_rhs_constr ) + delta_term_forRHS; 
    constr.RHSValue( newrhs * scalefactor_rhs_constr );
  *]
  InterfaceProperties { Accessibility: 'Module' }
}