Quintiq file version 2.0 
 | 
#parent: #root 
 | 
FunctionOverride CalcEstimate 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Select the MoveStep related to the source and destination that has last been tried 
 | 
    lastmovestepsource := maxselect( this, SourceInventorySpecification.MoveStep, movestep, true, guard( movestep.Iteration().IterationNumber(), 0 ) ); 
 | 
    lastmovestepdestination := maxselect( this, DestinationInventorySpecification.MoveStep, movestep, true, guard( movestep.Iteration().IterationNumber(), 0 ) ); 
 | 
     
 | 
    // Calculate the expected benefit of the swap move 
 | 
    estimate := this.Quantity() * ( guard( lastmovestepdestination.BenefitPerQtyLatestAttempt(), 0.0 ) - guard( lastmovestepsource.BenefitPerQtyLatestAttempt(), 0.0 ) ) 
 | 
     
 | 
    // If there is no quantity at the source, then the swap move does not make sense so we give it a negative estimate 
 | 
    if( this.SourceInventorySpecification().TargetInQuantity_DELETED_Nov19() <= 0 ) 
 | 
    { 
 | 
      estimate := -10; 
 | 
    } 
 | 
     
 | 
    // Reduce the estimate if the last X times that this move was tried it did not find an improvement 
 | 
    estimate := this.GetCorrectionEstimateForPreviousFailures() * estimate; 
 | 
     
 | 
    this.Estimate( estimate ); 
 | 
  *] 
 | 
} 
 |