Quintiq file version 2.0 
 | 
#parent: #root 
 | 
MethodOverride GetAnchorPISPIPs ( 
 | 
  LibOpt_Scope scope, 
 | 
  RunContextForCapacityPlanning runcontext, 
 | 
  RunContextMeta runcontextmeta 
 | 
) as owning ProductInStockingPointInPeriodPlannings 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    pispips := construct( ProductInStockingPointInPeriodPlanningLeafs );  
 | 
    runcontext := this.GetRunContextCapacityPlanning();  
 | 
    runcontextmeta := this.GetRunContextMeta();  
 | 
    mp := runcontext.FirstPeriod_MP().MacroPlan();  
 | 
     
 | 
    anchor := null( StockingPointInPeriod );  
 | 
     
 | 
    candidates := LinkProbabilityStockingPointInPeriod::GetCandidates( scope );  
 | 
    candidatesvector := selectvalues( candidates, Elements, c, true, c.EstimatedImprovementScore() );  
 | 
    maxindex := candidatesvector.Size() - 1;  
 | 
    i := SelectorMeta::GetRandomIndex( candidatesvector );  
 | 
    comment := '';  
 | 
    if ( i <= maxindex )  
 | 
    { 
 | 
      anchor := candidates.Element(  i );  
 | 
    }  
 | 
    else 
 | 
    { 
 | 
      anchor := this.GetRandomSPIP( mp, scope ); // failsafe 
 | 
      comment := 'R ';  
 | 
    } 
 | 
     
 | 
    pispipleafs := selectset(  anchor, LeafPlanningPISPIPs, p, true, p.InventoryLevelEnd() > 0 );  
 | 
    pispipleafsovermax := selectset(  pispipleafs, Elements, p, true, not p.IsValidPlannedMaxInventoryLevel() );  
 | 
    pispip := null(  ProductInStockingPointInPeriodPlanningLeaf );  
 | 
    if ( Real::Random(0.0, 1.0 ) > 0.5 or pispipleafsovermax.Size() = 0 )  
 | 
    { 
 | 
      pispip := guard( pispipleafs.Element( Number::Random( 0, pispipleafs.Size() - 1 ) ), null( ProductInStockingPointInPeriodPlanningLeaf ) );  
 | 
    } 
 | 
    else 
 | 
    { 
 | 
      pispip := guard( pispipleafsovermax.Element( Number::Random( 0, pispipleafsovermax.Size() - 1 ) ), null( ProductInStockingPointInPeriodPlanningLeaf ) );  
 | 
    } 
 | 
     
 | 
    if ( isnull( pispip ) )  
 | 
    { 
 | 
      pispip := select(  anchor, LeafPlanningPISPIPs, p, true, true );  
 | 
      
 | 
    } 
 | 
    pispips.Add( pispip );  
 | 
     
 | 
    if ( not isnull( anchor ) )  
 | 
    { 
 | 
      debuginfo( 'anchor spip = ', anchor.StockingPointID(), anchor.Start() );  
 | 
      comment := comment + guard( pispip.ProductInStockingPoint_MP().StockingPointID() + pispip.ProductInStockingPoint_MP().ProductID() + [String] pispip.Start(), '-' )  
 | 
                 + 'eis=' + [String]anchor.EstimatedImprovementScore() + 'tried=' + [String]anchor.MetaOptimizerTried();  
 | 
      this.SetDescriptionAnchor( anchor,comment );  
 | 
      anchor.MetaOptimizerTried( anchor.MetaOptimizerTried() + 1 );  
 | 
    } 
 | 
     
 | 
     
 | 
    return &pispips; 
 | 
  *] 
 | 
} 
 |