| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsGoalsForCampaigns ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   const LibOpt_Scope scope | 
| ) const | 
| { | 
|   TextBody: | 
|   [* | 
|     totalcombislack_constname := typeof( MPTotalCampaignSequencingCombiSlackConstraint ); | 
|     scalefactor_totalcombislackVariables_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignSequencingCombiSlackVariable ), totalcombislack_constname ); | 
|     scalefactor_underselectioncombiVariables_const := this.ScaleConstraintTerm( typeof( MPUnderSelectionOfCampaignCombiVariable ), totalcombislack_constname ); | 
|     scalefactor_isselectedvar_const := this.ScaleConstraintTerm( typeof( MPIsCampaignCombiSelectedVariable ), totalcombislack_constname ); | 
|     scalefactor_ptqtyslack := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignSlackVariable ), totalcombislack_constname ); | 
|     scalefactor_incompatiblewithprevVariables_const := this.ScaleConstraintTerm( typeof( MPIsIncompatibleWithPrevOptSubUnitPeriodLastElementVariable ), totalcombislack_constname ); | 
|      | 
|     totalcampaign_constname := typeof( MPTotalCampaignConstraint ); | 
|     scalefactor_totalcampaign_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignVariable ), totalcampaign_constname ); | 
|     scalefactor_totalcampaignutil_const := this.ScaleConstraintTerm( typeof( MPTotalUnitPeriodCampaignUtilizationSlackVariable ), totalcampaign_constname ); | 
|     scalefactor_totalcampaignmaxqty_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMaxQtyOverVariable ), totalcampaign_constname ); | 
|     scalefactor_totalcampaignminqty_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMinQtyUnderVariable ), totalcampaign_constname ); | 
|     scalefactor_totalcampaignmindur_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMinDurationUnderVariable ), totalcampaign_constname ); | 
|     scalefactor_totalcampaignmaxdur_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMaxDurationOverVariable ), totalcampaign_constname ); | 
|      | 
|     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 
|     //Sum the penalties due to incompatible Campaigns/TransitionStages between 2 consecutive combi, and the penalties due to the under-selection for all combis. | 
|     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////     | 
|     totalcombislackctr := program.TotalCampaignSequencingCombiSlackConstraints().New(); | 
|     totalcombislackctr.RHSValue( 0.0 ); | 
|     totalcombislackctr.Sense( "=" ); | 
|     vartotalcombislack := program.TotalCampaignSequencingCombiSlackVariables().Get();  | 
|     totalcombislackctr.NewTerm( 1.0 * scalefactor_totalcombislackVariables_const, vartotalcombislack ); | 
|      | 
|     traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp ) | 
|     { | 
|       varunderselectioncombi := program.UnderSelectionOfCampaignCombiVariables().Get( ocusp ); | 
|       totalcombislackctr.NewTerm( -1.0 * scalefactor_underselectioncombiVariables_const, varunderselectioncombi ); | 
|       varincompatiblewithprev := program.IsIncompatibleWithPrevOptSubUnitPeriodLastElementVariables().Get( ocusp ); | 
|       totalcombislackctr.NewTerm( -1.0 * scalefactor_incompatiblewithprevVariables_const, varincompatiblewithprev ); | 
|      | 
|       traverse( ocusp, OptCampaignCombiActive, combi, combi.NrSequenceViolationsInternal() > 0 ) | 
|       {  | 
|         varisselected := program.IsCampaignCombiSelectedVariables().Get( combi ); | 
|         totalcombislackctr.NewTerm( -1.0 * combi.NrSequenceViolationsInternal() * scalefactor_isselectedvar_const, varisselected );   | 
|       } | 
|     }     | 
|      | 
|     traverse( scope.GetOperationInOptimizerRunConst(), Elements, operation, | 
|               operation.OperationInCampaignType( relsize ) > 0  | 
|               or operation.OperationInTransitionType( relsize ) > 0 ) | 
|     { | 
|       // Only select those periods that are relevant for this operation for the optimizer run | 
|       periods := this.GetPeriodsForOperation( scope, operation ); | 
|      | 
|       traverse( periods, Elements, period, | 
|                 period.GetIsInCampaignTypeHorizonUnit( operation.Unit() ) ) | 
|       { | 
|         varslack := program.PTQtyInCampaignSlackVariables().Find(  operation, period );   | 
|         if ( not isnull( varslack ) )  | 
|         { | 
|           totalcombislackctr.NewTerm( -1.0 * scalefactor_ptqtyslack, varslack );  | 
|         } | 
|       } | 
|     } | 
|      | 
|     this.InitConstraintsGoalsForCampaignLimitations( program, scope ) | 
|      | 
|     totalcampaignconst := program.TotalCampaignConstraints().New(); | 
|     totalcampaignconst.RHSValue( 0.0 ); | 
|     totalcampaignconst.NewTerm( -1.0 * scalefactor_totalcampaign_const, program.TotalCampaignVariables().Get() ); | 
|     totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignUtilizationPenaltyWeight() * scalefactor_totalcampaignutil_const, program.TotalUnitPeriodCampaignUtilizationSlackVariables().Get() ); | 
|     totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignmaxqty_const , program.TotalCampaignMaxQtyOverVariables().Get() ); | 
|     totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignminqty_const, program.TotalCampaignMinQtyUnderVariables().Get() ); | 
|     totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignmindur_const, program.TotalCampaignMinDurationUnderVariables().Get() ); | 
|     totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignmaxdur_const, program.TotalCampaignMaxDurationOverVariables().Get() ); | 
|     //totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignCombiSlackWeight() * scalefactor_totalcombislack_const , vartotalcombislack ); | 
|   *] | 
| } |