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
Quintiq file version 2.0
#parent: #root
Method UpdateParameters (ProductInStockingPointInPeriodPlannings smartplanpispips, StrategyMacroPlan strategymacroplan, Period_MP periodstart, 
  Period_MP periodend, LibOBT_RunTaskSetting benchmarksetting) as AlgorithmRun
{
  TextBody:
  [*
    // Martijn Apr-6-2016 (created)
    // The automatic scaling algorithm should not be run on the autotuning copy
    // Set the optimizer settings and parameters
    param := this.Algorithm_Parameter();
    issmartplan := param.IsSmartPlan();
    tempalgorithmrun := this.Optimization().SetWeightsAndParams( issmartplan, strategymacroplan, benchmarksetting ); 
    
    // Update planning horizon of optimizer
    tempalgorithmrun.UpdatePlanningTime( periodstart, periodend );
    
    // Martijn: We need this Transaction.Propagate to make sure we select the latest algorithm run that was just created in SetWeightsAndParams.
    Transaction::Transaction().Propagate();
    
    // The next algorithmrun is created in SetWeightsAndParams, so we need to call that method before we can set parameters of the lastrun
    lastrun := tempalgorithmrun; 
    
    lastrun.UpdateParameters( periodstart, 
                              periodend,
                              this.ResourceManager_MP().MaxThreadForOptimization()
                            );
    
    if( param.IsInventoryOptimizationRun() )
    {
    // If this is an inventory optimization run and the last iteration has reached the specified number of simulations
    // then create a new iteration 
      algorithm := this.DEPRECATED_InventoryOptimization(); 
      if( guard( algorithm.LastIteration().LastSimulation().SimulationNumber() >= algorithm.NumberOfSimulations(), false ) )
      {
        // Create a new iteration
        iteration := Iteration::Create( algorithm, guard( tempalgorithmrun.LastLevel().Level(), 5 ) ); 
        // We need to update the move estimates and quantities before we can select the best move
        Transaction::Transaction().Propagate( attribute( Move, Estimate ) );
        Transaction::Transaction().Propagate( attribute( Move, Quantity ) );
        currentmove := algorithm.SelectMoveForInventoryOptimization();
        
        // If all moves have been tried, reset their status and select the most promising move
        if( isnull( currentmove ) )
        {
          traverse( algorithm, Move, move )
          {
            move.HasBeenTried( false );
          }  
          currentmove := algorithm.SelectMoveForInventoryOptimization();
        }
        // If the current move is still null, there is no available move to execute
        if( not isnull( currentmove ) )
        {
          currentmove.Iteration( relset, iteration );
          currentmove.QuantityForUndo( currentmove.Quantity() );
          isundo := false;
          currentmove.ExecuteMove( isundo );
        }  
      }
    }
    
    return tempalgorithmrun;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}