| 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' } | 
| } |