haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsGoalsForDriverChangeover (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  Description: 'Init constraints goals for account depends on time, applicable to unit period time'
  TextBody:
  [*
    // Mathematical variable names
    driverchangeover_varname := typeof( MPDriverChangeoverVariable );
    unitperiodnroftoolchange_varname := typeof( MPUnitPeriodNrOfToolChangeVariable );
    // Constraint names
    tconstname := typeof( MPDriverChangeoverConstraint );
    // scaling factor calculations
    scalefactor_driver_tconst := this.ScaleConstraintTerm( driverchangeover_varname, tconstname );
    scalefactor_unitperiodtime_tconst := this.ScaleConstraintTerm( unitperiodnroftoolchange_varname, tconstname );
    
    scalefactor_rhs_tconst := this.ScaleConstraintRHS( tconstname, 1.0 );
    
    driver := select( this, MacroPlan.AccountCostDriver, driver, driver.Name() = Translations::MP_AccountAssignmentCostDriverChangeover() );
    traverse( scope.GetAccountsInOptimizerRunConst(), Elements, account, account.HasChangeOverAssignment() )
    {
    
      // tconst constraint UoM: Monetary
      tconst := program.DriverChangeoverConstraints().New( account, driver );
      tconst.Sense( '=' );
      tconst.RHSValue( 0.0 * scalefactor_rhs_tconst );
      // Term UoM: Monetary
      tconst.NewTerm( 1.0 * scalefactor_driver_tconst, program.DriverChangeoverVariables().Get( account, driver ) );
    
      traverse( account, AccountAssignment, aa, aa.AccountCostDriver() = driver and aa.AccountCost( relsize ) > 0  )
      {
        traverse( aa, astype( UnitAccount ).UnitAccountInPeriodForChangeover.UnitPeriod, up,
                  scope.Contains( up.UnitPeriodInOptimizerRun() ) )
        {
          varUnitPeriodNrOfToolChange := program.UnitPeriodNrOfToolChangeVariables().Find( up );
          
          if( not isnull( varUnitPeriodNrOfToolChange ) )
          {
            cost := up.astype( UnitPeriodTime ).GetBaseCostPerChangeover( aa.astype( UnitAccount ) );
            // Term:    -cost * UnitPeriodNrOfToolChange variable
            // UoM: [Monetary/Unit] *    [-]    *    [Unit]
            tconst.NewTerm( -cost * scalefactor_unitperiodtime_tconst, varUnitPeriodNrOfToolChange );
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}