| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsforCampaignCalcElementTypePeriodUnderloadedEnd ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   const LibOpt_Scope scope | 
| ) const | 
| { | 
|   TextBody: | 
|   [* | 
|     campaignunderloadend_constname := typeof( MPCalcElementTypePeriodUnderloadedEndConstraint ); | 
|     scalefactor_PTQtyInCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignElementTypeEndVariable ), campaignunderloadend_constname ); | 
|     scalefactor_CampaignElementTypePeriodUnderloadedEnd_const := this.ScaleConstraintTerm( typeof( MPCampaignElementTypePeriodUnderloadedEndVariable ), campaignunderloadend_constname ); | 
|     scalefactor_DurationOfCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPDurationOfCampaignElementTypeEndVariable ), campaignunderloadend_constname ); | 
|      | 
|     traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp ) | 
|     { | 
|       traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet ) | 
|       { | 
|         constr := program.CalcElementTypePeriodUnderloadedEndConstraints().New( ocet, ocusp ); | 
|         // Sum ( max capacity usage per quantity * PTQty in Element Type end | 
|         traverse( ocet, OptCampaignOperationInElementType, ocoet ) | 
|         { | 
|           maxcap := ocoet.Operation().GetCapacityUsagePerQuantity( ocusp.UnitPeriod() ); | 
|           varcampaignptqtyend := program.PTQtyInCampaignElementTypeEndVariables().Get( ocoet, ocusp ); | 
|           constr.NewTerm( maxcap * scalefactor_PTQtyInCampaignElementTypeEnd_const, varcampaignptqtyend );  | 
|         } | 
|         // Add slack variable ElementTypePeriodUnderloadedEnd | 
|         varcampaignunderloadend := program.CampaignElementTypePeriodUnderloadedEndVariables().Get( ocet, ocusp ); | 
|         constr.NewTerm( 1.0 * scalefactor_CampaignElementTypePeriodUnderloadedEnd_const, varcampaignunderloadend ); | 
|          | 
|         // Subtract total available capactity * relative duration of element end type | 
|         totalcap := ocusp.UnitPeriod().GetTotalAvailableCapacity(); | 
|         duration := ocusp.UnitPeriod().Duration(); | 
|         factor := totalcap / duration.HoursAsReal(); | 
|          | 
|         varcampaigndurationend := program.DurationOfCampaignElementTypeEndVariables().Get( ocet, ocusp ); | 
|         constr.NewTerm( - factor * scalefactor_DurationOfCampaignElementTypeEnd_const, varcampaigndurationend ); | 
|       }  | 
|     } | 
|   *] | 
| } |