| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsForShiftPatterns ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   const RunContextForCapacityPlanning runcontext, | 
|   const LibOpt_Scope scope | 
| ) const | 
| { | 
|   Description: 'Initialize constraints for shift pattern optimization' | 
|   TextBody: | 
|   [* | 
|     if( runcontext.UseShiftOptimization() ) | 
|     { | 
|       constname1 := typeof( MPFirstPeriodStartOfPlanningConstraint ); | 
|       constname2 := typeof( MPFirstPeriodShiftOnUnitConstraint ); | 
|       constname3 := typeof( MPFirstPeriodShiftNotUsedConstraint ); | 
|       constname4 := typeof( MPFirstPeriodShiftAlreadyUsedConstraint ); | 
|        | 
|       scalefactor_spisused_const1 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsUsedVariable ), constname1 ); | 
|       scalefactor_spisfirst_const1 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsFirstVariable ), constname1 ); | 
|       scalefactor_spisused_const2 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsUsedVariable ), constname2 ); | 
|       scalefactor_spisfirst_const2 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsFirstVariable ), constname2 ); | 
|       scalefactor_spisused_const3 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsUsedVariable ), constname3 ); | 
|       scalefactor_spisfirst_const3 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsFirstVariable ), constname3 ); | 
|       scalefactor_spisfirst_const4 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsFirstVariable ), constname4 ); | 
|       scalefactor_spisused_const4 := this.ScaleConstraintTerm( typeof( MPShiftPatternIsUsedVariable ), constname4 ); | 
|        | 
|       scalefactor_rhs_const2 := this.ScaleConstraintRHS( constname2, 1.0 ); | 
|       scalefactor_rhs_const3 := this.ScaleConstraintRHS( constname3, 1.0 ); | 
|       scalefactor_rhs_const4 := this.ScaleConstraintRHS( constname4, 1.0 ); | 
|        | 
|       constnamemin := typeof( MPMinShiftPatternDurationConstraint ); | 
|       scalefactor_spisused_constmin := this.ScaleConstraintTerm( typeof( MPShiftPatternIsUsedVariable ), constnamemin ); | 
|       scalefactor_spisfirst_constmin := this.ScaleConstraintTerm( typeof( MPShiftPatternIsFirstVariable ), constnamemin ); | 
|       scalefactor_mindurationslack_constmin := this.ScaleConstraintTerm( typeof( MPShiftPatternDurationSlackVariable ), constnamemin ); | 
|      | 
|       scalefactor_rhs_minimumdurationconstr := this.ScaleConstraintRHS( constnamemin, 1.0 ); | 
|      | 
|       constnameone := typeof( MPOneShiftPatternPerUnitPeriodConstraint ); | 
|       scalefactor_spisused_constone := this.ScaleConstraintTerm( typeof( MPShiftPatternIsUsedVariable ), constnameone ); | 
|       scalefactor_rhs_constone := this.ScaleConstraintRHS( constnameone, 1.0 ); | 
|      | 
|       traverse( scope.GetUnitInOptimizerRunConst(), Elements, parentunit, parentunit.GetUseShiftOptimization() ) | 
|       { | 
|         this.InitConstraintsForShiftPatternTotalChanges( program, scope, parentunit ); | 
|          | 
|         traverse( parentunit.GetUnitForShiftOptimization(), Elements, unit ) | 
|         { | 
|           // Get every shift pattern allowed on a unit. | 
|           traverse( unit, UnitShiftPatternAllowed.ShiftPattern, sp ) | 
|           { | 
|             traverse( unit, UnitPeriod.astype(UnitPeriodTime), up, up.IsInScopeForShiftOptimization( scope ) ) | 
|             { | 
|               this.InitConstraintsForShiftPatternFirstPeriod( program,  | 
|                                                               scope,  | 
|                                                               up,  | 
|                                                               sp,  | 
|                                                               scalefactor_spisused_const1, | 
|                                                               scalefactor_spisfirst_const1, | 
|                                                               scalefactor_spisused_const2,  | 
|                                                               scalefactor_spisfirst_const2,  | 
|                                                               scalefactor_spisused_const3,  | 
|                                                               scalefactor_spisfirst_const3,  | 
|                                                               scalefactor_spisfirst_const4,  | 
|                                                               scalefactor_spisused_const4,  | 
|                                                               scalefactor_rhs_const2,  | 
|                                                               scalefactor_rhs_const3,  | 
|                                                               scalefactor_rhs_const4 );  | 
|               this.InitConstraintsForShiftPatternMinDuration( program,  | 
|                                                               scope,  | 
|                                                               up,  | 
|                                                               sp,  | 
|                                                               scalefactor_spisused_constmin,  | 
|                                                               scalefactor_spisfirst_constmin,  | 
|                                                               scalefactor_mindurationslack_constmin,  | 
|                                                               scalefactor_rhs_minimumdurationconstr );  | 
|                | 
|               // Create constraints for unit periods not in scope that directly follow a unit period in scope. | 
|               nextup := up.NextPlanningUnitPeriod(); | 
|               if( not isnull( nextup ) and not nextup.IsInScopeForShiftOptimization( scope ) ) | 
|               { | 
|                 this.InitConstraintsForShiftPatternFirstPeriod( program,  | 
|                                                                 scope,  | 
|                                                                 nextup.astype( UnitPeriodTime ),  | 
|                                                                 sp,  | 
|                                                                 scalefactor_spisused_const1, | 
|                                                                 scalefactor_spisfirst_const1, | 
|                                                                 scalefactor_spisused_const2,  | 
|                                                                 scalefactor_spisfirst_const2,  | 
|                                                                 scalefactor_spisused_const3,  | 
|                                                                 scalefactor_spisfirst_const3,  | 
|                                                                 scalefactor_spisfirst_const4,  | 
|                                                                 scalefactor_spisused_const4,  | 
|                                                                 scalefactor_rhs_const2,  | 
|                                                                 scalefactor_rhs_const3,  | 
|                                                                 scalefactor_rhs_const4 );  | 
|                 this.InitConstraintsForShiftPatternMinDuration( program,  | 
|                                                                 scope,  | 
|                                                                 nextup.astype( UnitPeriodTime ),  | 
|                                                                 sp,  | 
|                                                                 scalefactor_spisused_constmin,  | 
|                                                                 scalefactor_spisfirst_constmin,  | 
|                                                                 scalefactor_mindurationslack_constmin,  | 
|                                                                 scalefactor_rhs_minimumdurationconstr );  | 
|               } | 
|             } | 
|           } | 
|            | 
|           traverse( unit, UnitPeriod.astype(UnitPeriodTime), up, up.IsInScopeForShiftOptimization( scope ) ) | 
|           { | 
|             this.InitConstraintsForShiftPatternOnePerPeriod( program,  | 
|                                                              up,  | 
|                                                              scalefactor_spisused_constone,  | 
|                                                              scalefactor_rhs_constone );  | 
|              | 
|             // Create minimum duration constraints for unit periods not in scope that precede a unit period in scope. | 
|             if( guard( not up.PreviousPlanningUnitPeriod().IsInScopeForShiftOptimization( scope ), false ) ) | 
|             { | 
|               this.InitConstraintsForShiftPatternMinDurationOutsideScope( program,  | 
|                                                                           scope,  | 
|                                                                           up,  | 
|                                                                           scalefactor_spisused_constmin,  | 
|                                                                           scalefactor_spisfirst_constmin,  | 
|                                                                           scalefactor_mindurationslack_constmin,  | 
|                                                                           scalefactor_rhs_minimumdurationconstr );  | 
|             } | 
|           } | 
|         } | 
|       } | 
|     } | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |