| 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() ); | 
|   *] | 
| } |