yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Quintiq file version 2.0
#parent: #root
Method RunInventoryOptimization (
  Duration timelimitinventoryoptimization,
  Boolean issingleiteration,
  Boolean isselectbestiteration,
  Boolean iscleanupolditerations,
  Boolean isresetsimulations,
  Number numberofsimulations,
  Number numberofperiodsinwindow,
  Strategy strategy,
  Boolean overwritemanual
)
{
  Description: 'Runs the inventory optimization algorithm'
  TextBody:
  [*
    // We run the inventory optimization from the start of the planning horizon over the next X periods.
    // After each optimizer run, both the start and end period move by 1.
    // Once the end period is equal to the end of the horizon, the window will start to shrink.
    periodstart := this.StartOfPlanningPeriod();
    periodend := this.DEPRECATED_InventoryOptimization().GetPeriodEndInventoryOptimization( periodstart );
      
    // Inventory optimization does not use smart plan
    issmartplan := false;
    issmartplanforperiodtask := false; 
    hastotalsupplyuser := false;
    totalsupplyuser := 0.0;
    smartplanpispip := null( ProductInStockingPointInPeriodPlannings );
    isupstreamsmartplan := false;
    ismiddleoutsmartplan := false;
    isonlyplanonestepupstream := false;
    
    
    // This is an inventory optimization run
    isinventoryoptimization := true;
    
    // Save the settings of the inventory optimization
    algorithm := this.DEPRECATED_InventoryOptimization();
    algorithm.StartInventoryOptimization( DateTime::ActualTime() );
    algorithm.TimeLimitInventoryOptimization( timelimitinventoryoptimization );
    algorithm.NumberOfSimulations( numberofsimulations );
    algorithm.NumberOfPeriodsWindowInventoryOptimization( numberofperiodsinwindow );
    algorithm.IsStopInventoryOptimization( false );
    algorithm.IsRunningInventoryOptimization( true );
    algorithm.IsSelectBestIteration( isselectbestiteration );
    
    // Clean up the old iterations if that option is selected
    if( iscleanupolditerations )
    {
      olditerations := selectset( algorithm, Iteration, iteration, true );
      Iteration::Delete( olditerations );
    }
    // Otherwise make sure all old iterations are marked as not being part of the last run
    else
    {
      traverse( algorithm, Iteration, iteration, iteration.IsPartOfLastRun() )
      {
        iteration.IsPartOfLastRun( false );
      }
    }
    
    
    
    // Create a new iteration
    iteration := Iteration::Create( this.DEPRECATED_InventoryOptimization(), strategy.MaxActiveLevel() );
    iteration.Start( algorithm.StartInventoryOptimization() );
    iteration.IsStopAfterThisIteration( issingleiteration );
    iteration.IsEvaluation( issingleiteration );
    
    // If no previous iteration has been selected, select the current iteration
    if( not exists( this, DEPRECATED_InventoryOptimization.Iteration, olditeration, olditeration.IsSelected() ) )
    {
      iteration.IsSelected( true );
    }
    
    // If the simulations should be reset
    // Then we should generate new demand realizations
    // So all existing sales demand realization should be deleted
    if( isresetsimulations )
    {
      traverse( this, SalesDemand.SimulationSalesDemand, simsalesdemand )
      {
        SimulationSalesDemand::Delete( simsalesdemand );
      }
    }
    
        
    // Generate the moves
    algorithm.GenerateMoves();
    
    // Inventory optimization will not do postprocessing
    ispostprocessing := false;
    
    // No autoscaling during inventory optimization
    isforcenoautoscaling := true;
    
    this.RunOptimizer( issmartplan,
                       issmartplanforperiodtask, 
                       hastotalsupplyuser,
                       totalsupplyuser,
                       smartplanpispip,
                       isupstreamsmartplan,
                       ismiddleoutsmartplan,
                       isonlyplanonestepupstream,
                       ispostprocessing,
                       isforcenoautoscaling,
                       strategy,
                       overwritemanual,
                       periodstart, periodend,
                       isinventoryoptimization, false, null( Units ), 
                       null( Process_MP ), 
                       this.OptimizerPuzzleWorld() );
  *]
}