lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
Method InitializeOptimizerRun (
  Boolean issmartplan,
  Boolean issmartplanforperiodtask,
  Boolean hastotalsupplyuser,
  Real totalsupplyuser,
  ProductInStockingPointInPeriodPlannings smartplanpispips,
  Boolean isupstreamsmartplan,
  Boolean ismiddleoutsmartplan,
  Boolean isonlyplanonestepupstream,
  Boolean ispostprocessing,
  Boolean isforcenoautoscaling,
  Strategy strategy,
  Boolean isoverridemanualplanning,
  Period_MP periodstart,
  Period_MP periodend,
  Boolean isinventoryoptimizationrun,
  Boolean isusingselectedunits,
  Units units,
  Process_MP process,
  OptimizerPuzzle optimizerpuzzle
) as AlgorithmRun
{
  Description: 'Copy the setting from scenario manager and run the optimizer asynchronous. Make selection meta or regular based on attribute.'
  TextBody:
  [*
    //copy strategy setting to globalparameter
    if ( not isnull( strategy ) ) // calling with null( Strategy ) means re-using existing StrategyMacroPlan
    {
      this.DuplicateStrategySettings( strategy, false ); 
      if ( not isnull( strategy.ScenarioManager() ) ) // for LibOpt_BT we use a workaround of creating some dummy strategy so we can query for KPIs stored on the snapshots 
      {
        strategy.ScenarioManager().ActiveStrategy( relset, strategy );
      }
    }
    
    // Change lastUsedOptimizer OptimizerPuzzle
    if( not isnull( optimizerpuzzle ) )
    { 
      optimizerpuzzle.ChangeLastUsedOptimizerPuzzle();
    }
    
    // Clean up data, remove the redundant data in the dataset.
    this.RemoveUnusedInstancesBeforeOptimizerRun();
    
    runsync := this.GlobalParameters_MP().RunSmartPlanSynchronously() and issmartplan; 
    // Set the optimizer status to running
    if ( not runsync ) 
    {
      runningsync := true; 
      sm := Util::GetScenarioManagerStream(); 
      sm->UpdateScenarioOptimizerStatus( this.MDSID(), 
                                         Translations::MP_GlobalParameters_GetOptimizerRunningStatus(), 
                                         ifexpr( runningsync, '', Translations::MP_GlobalParameters_GetOptimizerRunningLevel(1, counter( strategy, StrategyLevel, strategyLevel, strategyLevel.KPIWeight( relsize ) > 0 ) ) ), //When running synchronously, it is not possible to update the levels running.
                                         "" );
    }
    
    // Update the algorithm parameters
    this.GetAlgorithmParameter().Update( issmartplan,
                                         issmartplanforperiodtask, 
                                         hastotalsupplyuser,
                                         totalsupplyuser,
                                         isupstreamsmartplan,
                                         ismiddleoutsmartplan,
                                         isonlyplanonestepupstream,
                                         ispostprocessing,
                                         isforcenoautoscaling,
                                         isoverridemanualplanning,
                                         isinventoryoptimizationrun,
                                         isusingselectedunits, 
                                         runsync );
                                                   
    // Set the optimizer settings and parameters
    algrun := this.UpdateParameters( smartplanpispips,
                                     this.StrategyMacroPlan(),
                                     periodstart, 
                                     periodend );
    
    
    if ( isnull( periodstart ) or isnull( periodend ) )
    {
      AlgorithmRun::GetLastOptimizationHorizon( algrun, this, periodstart, periodend );
    }
    return algrun;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}