| Quintiq file version 2.0 | 
| #parent: #root | 
| Method GetIsImprovement () as Boolean | 
| { | 
|   Description: 'Checks whether this iteration was an improvement compared to the best iteration' | 
|   TextBody: | 
|   [* | 
|     // Martijn Nov-4-2016 (created) | 
|      | 
|     isimprovement := true; | 
|     previousbestiteration := select( this, DEPRECATED_InventoryOptimization.Iteration, iteration, iteration.IsBestIteration() ); | 
|      | 
|     if( not isnull( previousbestiteration ) ) | 
|     { | 
|       isbetter := false; | 
|       isworse := false; | 
|       bestiterationlevels := selectsortedset( previousbestiteration, IterationLevel, bestiterationlevel, | 
|                                               true, | 
|                                               bestiterationlevel.Level() ); | 
|      | 
|       // Traverse sequentially over the iteration levels and check whether the level of the current iteration is better or worse than that of the best iteration so far | 
|       // If it is better, accept this iteration, if it is worse, reject this iteration | 
|       traverse( bestiterationlevels, Elements, bestiterationlevel ) | 
|       { | 
|         // If we have not yet determined whether the iteration is better or worse | 
|         if( not isbetter and not isworse ) | 
|         { | 
|           algorithmlevel := select( this.DEPRECATED_InventoryOptimization().MacroPlan().GetLastAlgorithmRun(), AlgorithmRunLevel, arl, arl.Level() = bestiterationlevel.Level() ); | 
|           relativegoalslack := guard( algorithmlevel.RelativeGoalSlack(), 0.0 ); | 
|           prevbestexpectedkpi := bestiterationlevel.InventoryOptimizationExpectedTotalKPI(); | 
|           newiterationlevel := select( this, IterationLevel, itlevel, itlevel.Level() = bestiterationlevel.Level() ); | 
|           newexpectedkpi := guard( newiterationlevel.InventoryOptimizationExpectedTotalKPI(), prevbestexpectedkpi - 1.0 ); | 
|           // If the new expected total KPI value minus the relative goal slack is better | 
|           // than the previous best expected total KPI than the iteration was an improvement | 
|           factor := ifexpr( newexpectedkpi > 0, 1.0, -1.0 ); | 
|           if( newexpectedkpi * ( 1 - factor * relativegoalslack ) > prevbestexpectedkpi ) | 
|           { | 
|             isbetter := true; | 
|           } | 
|           // If the previous best expected total KPI value  is better | 
|           // than the new expected total KPI than the iteration was an improvement | 
|           else if( prevbestexpectedkpi > newexpectedkpi * ( 1 + factor * relativegoalslack ) ) | 
|           { | 
|             isworse := true; | 
|           } | 
|         } | 
|       } | 
|       isimprovement := isbetter; | 
|     } | 
|      | 
|     return isimprovement; | 
|   *] | 
| } |