| Quintiq file version 2.0 | 
| #parent: #root | 
| Method GetSSGForTuning () as SolverSettingGroup | 
| { | 
|   Description: 'Select the SSG that should be tried on this strategylevel in the next tuning run' | 
|   TextBody: | 
|   [* | 
|     // Martijn Apr-11-2016 (created) | 
|     solversettinggroup := this.SolverSettingGroup(); | 
|      | 
|     // If there is at least one SolverSettingGroup that has not been tested on this strategy level | 
|     if( exists( this, SSGInStrategyLevel, ssginsl, not ssginsl.IsTested() ) ) | 
|     // select the first SolverSettingGroup that is not tested in alphabetical order | 
|     { | 
|       solversettinggroup := guard( minselect( this, SSGInStrategyLevel, ssginsl,           // Select the SSGInStrategyLevel for which | 
|                                               not ssginsl.IsTested(),                      // The solver setting group has not been tested on the strategy level | 
|                                               ssginsl.SolverSettingGroupName()             // select the first in alphabetical order | 
|                                             ).SolverSettingGroup(),                        // Select the SSG of this SSGInStrategyLevel | 
|                                    null( SolverSettingGroup ) ); | 
|     } | 
|     // if the combination of the best settings on eahc level have not yet been tested for this strategy | 
|     else if( not this.Strategy().HasTestedBestSSG() ) | 
|     { | 
|       // Select the solversettingroup with the shortest last duration on this level | 
|       solversettinggroup := guard( minselect( this, SSGInStrategyLevel, ssginsl, true, ssginsl.LastDuration() ).SolverSettingGroup(), | 
|                                    null( SolverSettingGroup ) ); | 
|       // If this is the last strategy level, set the HasTestedBestSSG of the strategy to true | 
|       if( not exists( this, Next.KPIWeight, kpiweight, kpiweight.Weight() > 0 and kpiweight.Level() > 0 ) ) | 
|       { | 
|         this.Strategy().HasTestedBestSSG( true ); | 
|       } | 
|     } | 
|     else if( this.IsActiveTuningLevel() ) | 
|     { | 
|       // Select the solver setting group with the oldest last tuning run on this level. If equal, select the one with the shortest duration. | 
|       solversettinggroup := guard( minselect( this, SSGInStrategyLevel, ssginsl, | 
|                                               true, | 
|                                               ssginsl.DateLastTuningRun(),           // Select the solversettinggroup with the oldest last tuning run | 
|                                               ssginsl.LastDuration()                 // If equal, select the one with the shortest duration | 
|                                             ).SolverSettingGroup(),                  // Select the SSG of this SSGInSL | 
|                                    null( SolverSettingGroup ) ); | 
|     } | 
|     // Otherwise select the solversettinggroup that is currently the default | 
|     else | 
|     { | 
|       solversettinggroup := guard( this.SolverSettingGroup(), null( SolverSettingGroup ) ); | 
|     } | 
|      | 
|     return solversettinggroup; | 
|   *] | 
| } |