陈清红
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsGoalsForShiftPatterns (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope
) const
{
  Description: 'Init constraints goals for shift patterns'
  TextBody:
  [*
    if( runcontext.UseShiftOptimization() )
    {
      constname := typeof( MPTotalShiftPatternChangesConstraint );
      
      scalefactor_nrshiftchanges_const := this.ScaleConstraintTerm( typeof( MPNrShiftPatternChangesVariable ), constname );
      
      totalshiftchangesvariablesvalue := 0.0;
      
      spchangespenaltyconstr := program.TotalShiftPatternChangesPenaltyConstraints().New();
      spchangespenaltyconstr.NewTerm( -1.0, program.TotalShiftPatternChangesPenaltyVariables().Get() );
      
      traverse( scope.GetUnitInOptimizerRunConst(), Elements, unit, unit.GetUseShiftOptimization() )
      {
        spchangespenaltyconstr.NewTerm( 1.0 * scalefactor_nrshiftchanges_const, program.NrShiftPatternChangesVariables().Get( unit ) );
        
        // Number of shift pattern changes for the unit periods that are either in scope or directly follow a unit period in scope.
        coeff := counter( unit.GetUnitForShiftOptimization(), Elements.UnitPeriod.astype( UnitPeriodTime ), up,
                          up.IsInScopeForShiftOptimization( scope ) or guard( up.PreviousPlanningUnitPeriod().IsInScopeForShiftOptimization( scope ), false ),
                          guard( up.ShiftPattern() <> up.PreviousPlanningUnitPeriod().astype( UnitPeriodTime ).ShiftPattern(), false ) );
        totalshiftchangesvariablesvalue := totalshiftchangesvariablesvalue + coeff * scalefactor_nrshiftchanges_const;
      }
      
      // workaround because cannot write to attribute
      this.StoreValueInProgram( program, 'collect_values_model_MPTotalShiftPatternChangesPenaltyVariables', totalshiftchangesvariablesvalue );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}