| Quintiq file version 2.0 | 
| #parent: #root | 
| Method Execute ( | 
|   AlgorithmRun algorithmrun, | 
|   Period_MPs periods, | 
|   Units units, | 
|   OptimizerPuzzle optimizerpuzzle | 
| ) as stream[JSON] | 
| { | 
|   TextBody: | 
|   [* | 
|     mp := this.Optimization().astype( Optimization ).MacroPlan();  | 
|      | 
|     periodstart := minselect(  periods, Elements, p, true, p.Start() );  | 
|     periodend := maxselect(  periods, Elements, p, true, p.Start() );  | 
|      | 
|     run := LibOpt_Run::Create( this );  | 
|      | 
|     this.CreateRunWithContexts( algorithmrun, run, units, periodstart, periodend );  | 
|      | 
|     outscope := LibOpt_Scope::Create( run );  | 
|     this.SubscribeRunToKPIs( run ); | 
|     traverse( this.DefaultScope(), Elements, se, not se.istype( OptimizerPuzzleInOptimizerRun ) and not se.istype( PeriodInOptimizerRun ) )  | 
|     { | 
|       outscope.Add( se );  | 
|     } | 
|     traverse( periods, Elements, p )  | 
|     { | 
|       outscope.Add( p );  | 
|     } | 
|      | 
|     outscope.Add( optimizerpuzzle );  | 
|      | 
|     run.SetStartScope( outscope );  | 
|      | 
|     rcm := select( run, RunContext.astype( RunContextMeta ), rc, true, true );  | 
|      | 
|     // save used settings to active settings, so we save the last used when the user kicks off a run  | 
|     this.ActiveSettings().astype( OptimizerMetaSettings ).SaveLastUsedSettings( rcm, optimizerpuzzle.Name(), mp.StrategyMacroPlan().Name(), periodstart.StartDate(), periodend.StartDate() );  | 
|      | 
|     this.CreateComponents( run );  | 
|     strm := run.Start(); | 
|     strm->| this->MyFinalize(); | 
|     return strm; | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |