| Quintiq file version 2.0 | 
| #parent: #root | 
| MethodOverride GetAnchorPISPIPs ( | 
|   LibOpt_Scope scope, | 
|   RunContextForCapacityPlanning runcontext, | 
|   RunContextMeta runcontextmeta | 
| ) as owning ProductInStockingPointInPeriodPlannings | 
| { | 
|   TextBody: | 
|   [* | 
|     mp := runcontext.FirstPeriod_MP().MacroPlan();  | 
|      | 
|     start := runcontext.FirstPeriod_MP().Start();  | 
|     end := runcontext.LastPeriod_MP().Start();  | 
|      | 
|     randomproduct := minselect( mp,  | 
|                                 Product_MP,  | 
|                                 p,  | 
|                                 p.IsInOptimizerPuzzle()  | 
|                                 and p.IsLeaf()  | 
|                                 and p.ProductInStockingPoint_MP( relsize ) > 0,  | 
|                                 Real::Random() );  | 
|     randompisp := minselect(  randomproduct,  | 
|                               ProductInStockingPoint_MP,  | 
|                               pisp, | 
|                               pisp.IsInOptimizerPuzzle()  | 
|                               and pisp.IsLeaf()  | 
|                               and pisp.ProductInStockingPointInPeriodPlanning(relsize ) > 0, Real::Random() );  | 
|     candidates := selectset( randompisp,  | 
|                              ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ),  | 
|                              p,  | 
|                              start <= p.Start()  | 
|                              and p.Start() <= end               | 
|                              );   | 
|      | 
|     if ( candidates.Size() = 0 ) // in very exceptional case above faster selection can lead to randompisp without leaf pispips. Next is failsafe | 
|     { | 
|       candidates := selectset( mp,  | 
|                                Product_MP.ProductInStockingPoint_MP.ProductInStockingPointInPeriodPlanning.astype(  ProductInStockingPointInPeriodPlanningLeaf ),  | 
|                                p,  | 
|                                p.ProductInStockingPoint_MP().IsInOptimizerPuzzle()  | 
|                                and start <= p.Start()  | 
|                                and p.Start() <= end );  | 
|     } | 
|     anchor := construct( ProductInStockingPointInPeriodPlanningLeafs );  | 
|     anchor.Add(  candidates.Element(  Number::Random( 0, candidates.Size()-1) ) );  | 
|     this.SetDescriptionAnchor( anchor );  | 
|     return &anchor; | 
|   *] | 
| } |