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' } 
 | 
} 
 |