陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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' }
}