yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
  *]
}