| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsForShiftPatternMinDurationOutsideScope ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   const LibOpt_Scope scope, | 
|   const UnitPeriodTime up, | 
|   Real scalefactor_spisused_const, | 
|   Real scalefactor_spisfirst_const, | 
|   Real scalefactor_mindurationslack_const, | 
|   Real scalefactor_rhs_minimumdurationconstr | 
| ) const | 
| { | 
|   Description: 'Finds the first unit period prior to the optimizer scope (going backwards) where the shift pattern changes, and creates minimum duration constraints for it.' | 
|   TextBody: | 
|   [* | 
|     previous := up.PreviousPlanningUnitPeriod(); | 
|     if( not isnull( previous ) ) | 
|     { | 
|       startingperiod := previous.astype( UnitPeriodTime ); | 
|       previousperiod := guard( startingperiod.PreviousPlanningUnitPeriod().astype( UnitPeriodTime ), null( UnitPeriodTime ) ); | 
|        | 
|       // Search the earliest unit period prior to the optimizer scope (going backwards) where the shift pattern changes. | 
|       while( not isnull( previousperiod ) | 
|              and previousperiod.ShiftPattern() = startingperiod.ShiftPattern() | 
|              and previousperiod.Start() > (up.Start() - previousperiod.ShiftPattern().MinimumDuration()) | 
|              and not previousperiod.IsInScopeForShiftOptimization( scope ) ) | 
|       { | 
|         startingperiod := previousperiod; | 
|         previousperiod := previousperiod.PreviousPlanningUnitPeriod().astype( UnitPeriodTime ); | 
|       } | 
|        | 
|       // If the period found above has a change of shift pattern and is preceded by a unit period not in scope, | 
|       // then create the minimum duration constraints for it. | 
|       if( guard( not previousperiod.IsInScopeForShiftOptimization( scope ), true )  | 
|           and guard( startingperiod.ShiftPattern() <> previousperiod.ShiftPattern(), true ) ) | 
|       { | 
|         traverse( startingperiod, Unit.UnitShiftPatternAllowed.ShiftPattern, sp )                | 
|         { | 
|           this.InitConstraintsForShiftPatternMinDuration( program,  | 
|                                                           scope,  | 
|                                                           startingperiod,  | 
|                                                           sp,  | 
|                                                           scalefactor_spisused_const,  | 
|                                                           scalefactor_spisfirst_const,  | 
|                                                           scalefactor_mindurationslack_const,  | 
|                                                           scalefactor_rhs_minimumdurationconstr );  | 
|         } | 
|       } | 
|     } | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |