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