| Quintiq file version 2.0 | 
| #parent: #root | 
| FunctionOverride CalcEstimate | 
| { | 
|   TextBody: | 
|   [* | 
|     // edz1 Sep-12-2016 (created) | 
|      | 
|     servicelevels := selectset( this, InventorySpecification.InventorySpecificationInServiceLevel.ServiceLevelBase, servicelevel, true ); | 
|     deviationfromtarget := 0.0; | 
|      | 
|     // The estimate of the move is equal to the deviation from target of the related service levels | 
|     traverse( servicelevels, Elements, servicelevel ) | 
|     { | 
|       // Select the best iteration service level related to this service level | 
|       prevbestitsl := select( servicelevel, IterationServiceLevel, itsl, itsl.Iteration().IsBestIteration() ); | 
|       // Calculate the deviation from target | 
|       target := servicelevel.TargetPercentage(); | 
|       deviationfromtarget := deviationfromtarget + ( target - guard( prevbestitsl.AchievedServiceLevel(), 0.0 ) ); | 
|     } | 
|      | 
|     if( not this.IsIncrease() ) | 
|     { | 
|       deviationfromtarget := - deviationfromtarget; | 
|     } | 
|      | 
|     // We use the factor to calculate the average deviation from target over all the service levels impacted by this move  | 
|     // If there is more than 1 service level, then we also multiply the factor by 1.5 | 
|     // Otherwise the estimate for this move would always be worse than for a move linking to only one of the service levels | 
|     factor := 1.0 | 
|     numberofservicelevels := servicelevels.Size(); | 
|     if( numberofservicelevels > 1 ) | 
|     { | 
|       factor := pow( [Real]numberofservicelevels, 1/2 ) / numberofservicelevels; | 
|     } | 
|      | 
|     value := factor * deviationfromtarget; | 
|      | 
|     // In reality the move will be too small to reach the target service level | 
|     value := 0.5 * value; | 
|      | 
|     // Reduce the estimate if the last X times that this move was tried it did not find an improvement | 
|     value := this.GetCorrectionEstimateForPreviousFailures() * value; | 
|      | 
|     this.Estimate( value ); | 
|   *] | 
| } |