yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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' }
}