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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Quintiq file version 2.0
#parent: #root
Method UpdateScalingFactors (
  MacroPlan macroplan
)
{
  Description: 'Updates the scaling factors based on the results of the automatic scaling algorithm'
  TextBody:
  [*
    // Select the active strategy
    strategy := macroplan.StrategyMacroPlan().GetStrategy( this ); 
    
    // Update the scaling factors
    if( not isnull( strategy ) )
    {
      if ( macroplan.StrategyMacroPlan().UseMetaOptimizer() ) 
      {
        // for the meta optimizer we compute level specific scaling factor
        traverse( macroplan, StrategyMacroPlan.StrategyLevelMacroPlan, slm ) 
        {
         samplesuggestion := macroplan.Optimization().AlgorithmScaling().GetMajoritySuggestionForMetaIteration( slm.Level() ); 
          
          if ( not isnull( samplesuggestion ) ) 
          {
            slm.MetaScalingFactorInventoryHolding( samplesuggestion.ScalingFactorInventoryHolding() ); 
            slm.MetaScalingFactorMass( samplesuggestion.ScalingFactorMass() ); 
            slm.MetaScalingFactorMonetary( samplesuggestion.ScalingFactorMonetary() ); 
            slm.MetaScalingFactorTime( samplesuggestion.ScalingFactorTime() ); 
            slm.MetaScalingFactorTimeAccount( samplesuggestion.ScalingFactorTimeAccount() ); 
            slm.MetaLastAutoScalingRun( DateTime::ActualTime() ); 
          
            if ( macroplan.StrategyMacroPlan().MetaOptimizerRunFullPlanPriorToFocus()           // if we run the full plan optimizer prior to focus level
                 and macroplan.StrategyMacroPlan().MetaOptimizerFirstLevelHasOverride()         // put those scaling factors at the global level 
                 and macroplan.StrategyMacroPlan().MetaOptimizerFirstLevel() = slm.Level() + 1 ) 
            {
              strategy.InventoryHoldingScalingFactor( slm.MetaScalingFactorInventoryHolding() ); 
              strategy.MassScalingFactor( slm.MetaScalingFactorMass() ); 
              strategy.MonetaryScalingFactor( slm.MetaScalingFactorMonetary() ); 
              strategy.TimeScalingFactor( slm.MetaScalingFactorTime() ); 
              strategy.TimeAccountScalingFactor( slm.MetaScalingFactorTimeAccount() );
              strategy.LastAutoScalingRun( slm.MetaLastAutoScalingRun() );  
              
              // also update on mp copy 
              macroplan.StrategyMacroPlan().LastAutoScalingRun( strategy.LastAutoScalingRun() ); 
              macroplan.StrategyMacroPlan().MassScalingFactor( strategy.MassScalingFactor() ); 
              macroplan.StrategyMacroPlan().MonetaryScalingFactor( strategy.MonetaryScalingFactor() ); 
              macroplan.StrategyMacroPlan().TimeScalingFactor( strategy.TimeScalingFactor() ); 
              macroplan.StrategyMacroPlan().TimeAccountScalingFactor( strategy.TimeAccountScalingFactor() ); 
              macroplan.StrategyMacroPlan().InventoryHoldingScalingFactor( strategy.InventoryHoldingScalingFactor() ); 
            }
            else
            {
              slevel := select(  strategy, StrategyLevel, lvl, true, lvl.Level() = slm.Level() ); 
              
              slevel.MetaScalingFactorInventoryHolding( slm.MetaScalingFactorInventoryHolding() ); 
              slevel.MetaScalingFactorMass( slm.MetaScalingFactorMass() ); 
              slevel.MetaScalingFactorMonetary( slm.MetaScalingFactorMonetary() ); 
              slevel.MetaScalingFactorTime( slm.MetaScalingFactorTime() ); 
              slevel.MetaScalingFactorTimeAccount( slm.MetaScalingFactorTimeAccount() );
              slevel.MetaLastAutoScalingRun( slm.MetaLastAutoScalingRun() );  
            }
          }
        }
      }
      else
      {
        run := macroplan.GetLastAlgorithmRun();
        strategy.MassScalingFactor( guard( select( run, ScalingType_Lib, st, st.Name() = Optimization::ScalingTypeNameMass() ).SuggestedScalingFactor(),
                                           strategy.MassScalingFactor() ));
        strategy.MonetaryScalingFactor( guard( select( run, ScalingType_Lib, st, st.Name() = Optimization::ScalingTypeNameMonetary() ).SuggestedScalingFactor(),
                                               strategy.MonetaryScalingFactor() ));
        strategy.TimeScalingFactor( guard( select( run, ScalingType_Lib, st, st.Name() = Optimization::ScalingTypeNameTime() ).SuggestedScalingFactor(),
                                           strategy.TimeScalingFactor() ));
        strategy.TimeAccountScalingFactor( guard( select( run, ScalingType_Lib, st, st.Name() = Optimization::ScalingTypeNameTimeAccount() ).SuggestedScalingFactor(),
                                                  strategy.TimeAccountScalingFactor() ));
        strategy.InventoryHoldingScalingFactor( guard( select( run, ScalingType_Lib, st, st.Name() = Optimization::ScalingTypeNameInventoryHolding() ).SuggestedScalingFactor(),
                                                       strategy.InventoryHoldingScalingFactor() ));
        
        // Update the date when the autoscaling was last run for macroplan strategy
        strategy.LastAutoScalingRun( DateTime::ActualTime() );
        
        // also update on mp copy 
        macroplan.StrategyMacroPlan().LastAutoScalingRun( strategy.LastAutoScalingRun() ); 
        macroplan.StrategyMacroPlan().MassScalingFactor( strategy.MassScalingFactor() ); 
        macroplan.StrategyMacroPlan().MonetaryScalingFactor( strategy.MonetaryScalingFactor() ); 
        macroplan.StrategyMacroPlan().TimeScalingFactor( strategy.TimeScalingFactor() ); 
        macroplan.StrategyMacroPlan().TimeAccountScalingFactor( strategy.TimeAccountScalingFactor() ); 
        macroplan.StrategyMacroPlan().InventoryHoldingScalingFactor( strategy.InventoryHoldingScalingFactor() ); 
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}