hongji.li
2023-11-07 1a1ba3ad5ed9e4380185aa1ccad20204a0e5f115
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForShiftPatternTotalChanges (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope,
  const Unit unit
) const
{
  Description: 'Represents the number of times a shift pattern is changed on a unit.'
  TextBody:
  [*
    constname := typeof( MPTotalShiftPatternChangesConstraint );
    
    scalefactor_nrshiftchanges_const := this.ScaleConstraintTerm( typeof( MPNrShiftPatternChangesVariable ), constname );
    scalefactor_spisfirst_const := this.ScaleConstraintTerm( typeof( MPShiftPatternIsFirstVariable ), constname );
    
    // Constraint: total number of shift pattern changes
    totalspchangesconstr := program.TotalShiftPatternChangesConstraints().New( unit );
    totalspchangesconstr.Sense( "=" );
    totalspchangesconstr.RHSValue( 0.0 );
    
    totalspchangesconstr.NewTerm( 1.0 * scalefactor_nrshiftchanges_const, program.NrShiftPatternChangesVariables().Get( unit ) );
    
    // Traverse leaf units (of capacity type Time)
    traverse( unit.GetUnitForShiftOptimization(), Elements, childunit )
    {
      traverse( childunit, UnitShiftPatternAllowed.ShiftPattern, sp )
      {
        traverse( childunit, UnitPeriod.astype(UnitPeriodTime), up, up.IsInScopeForShiftOptimization( scope ) )
        {
          totalspchangesconstr.NewTerm( -1.0 * scalefactor_spisfirst_const, program.ShiftPatternIsFirstVariables().Get( sp, up ) );
          
          // Also include variables representing periods not in scope that directly follow unit periods in scope.
          nextup := guard( up.NextPlanningUnitPeriod().astype( UnitPeriodTime ), null( UnitPeriodTime ) );
          if( not isnull( nextup ) and not nextup.IsInScopeForShiftOptimization( scope ) )
          {
            totalspchangesconstr.NewTerm( -1.0 * scalefactor_spisfirst_const, program.ShiftPatternIsFirstVariables().Get( sp, nextup ) );
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}