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