| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsForCampaignMaxQtyWithin ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   const LibOpt_Scope scope | 
| ) const | 
| { | 
|   TextBody: | 
|   [* | 
|     maxqtywithin_constname := typeof( MPMaxCampaignElementTypeQtyWithinConstraint ); | 
|     scalefactor_PTQtyWithin_const := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignElementTypeMidVariable ), maxqtywithin_constname ); | 
|     scalefactor_PTQtyEnd_const := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignElementTypeEndVariable ), maxqtywithin_constname ); | 
|     scalefactor_NrOfElementsWithin_const := this.ScaleConstraintTerm( typeof( MPNrOfCampaignElementWithinUnitSubPeriodVariable ), maxqtywithin_constname ); | 
|     scalefactor_IsLastElementType_const := this.ScaleConstraintTerm( typeof( MPIsLastCampaignElementTypeVariable ), maxqtywithin_constname ); | 
|     scalefactor_MaxElementTypeQtyOverMid_const := this.ScaleConstraintTerm( typeof( MPMaxCampaignElementTypeQtyOverWithinVariable ), maxqtywithin_constname ); | 
|      | 
|      | 
|     traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp ) | 
|     { | 
|       //Only do this for campaign / transitions that have a MaxQuantity (and thus, MaxQuantity is finite) | 
|       traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet, ocet.MaxQuantity().IsFinite() ) | 
|       { | 
|         constr := program.MaxCampaignElementTypeQtyWithinConstraints().New( ocet, ocusp ); | 
|         constr.RHSValue( 0.0 ); | 
|          | 
|         traverse( ocet, OptCampaignOperationInElementType, oiet ) | 
|         { | 
|           ptqyvar := program.PTQtyInCampaignElementTypeMidVariables().Get( oiet, ocusp ); | 
|           constr.NewTerm( 1.0 * scalefactor_PTQtyWithin_const, ptqyvar ); | 
|         }   | 
|          | 
|         //If this is a transition, we want these constraints to be hard ones | 
|         if( not ocet.istype( OptCampaignTransitionType ) ) | 
|         { | 
|           constr.NewTerm( -1.0 * scalefactor_MaxElementTypeQtyOverMid_const, program.MaxCampaignElementTypeQtyOverWithinVariables().Get( ocet, ocusp ) ); | 
|         } | 
|         constr.NewTerm( -ocet.MaxQuantity() * scalefactor_NrOfElementsWithin_const, program.NrOfCampaignElementWithinUnitSubPeriodVariables().Get( ocet, ocusp ) ); | 
|       } | 
|     } | 
|      | 
|      | 
|     traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp, isnull( ocusp.NextSubPeriod() ) ) | 
|     { | 
|       //Only do this for campaign / transitions that have a MaxQuantity (and thus, MaxQuantity is finite) | 
|       traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet, ocet.MaxQuantity().IsFinite() ) | 
|       { | 
|         constr := program.MaxCampaignElementTypeQtyWithinLastConstraints().New( ocet, ocusp ); | 
|         constr.RHSValue( 0.0 ); | 
|         constr.Sense( '<=' );  | 
|          | 
|         //If this is a transition, we want these constraints to be hard ones | 
|         if( not ocet.istype( OptCampaignTransitionType ) ) | 
|         { | 
|           constr.NewTerm( -1.0 * scalefactor_MaxElementTypeQtyOverMid_const, program.MaxCampaignElementTypeQtyOverWithinLastVariables().Get( ocet, ocusp ) );  | 
|         } | 
|          | 
|         //add one more term for the last ocusp in horizon | 
|         constr.NewTerm( - ocet.MaxQuantity() * scalefactor_IsLastElementType_const, program.IsLastCampaignElementTypeVariables().Get( ocet, ocusp ) ) | 
|         traverse( ocet, OptCampaignOperationInElementType, oiet ) | 
|         { | 
|           ptqyvar := program.PTQtyInCampaignElementTypeEndVariables().Get( oiet, ocusp ); | 
|           constr.NewTerm( 1.0 * scalefactor_PTQtyEnd_const, ptqyvar ); | 
|         }   | 
|       } | 
|     } | 
|   *] | 
| } |