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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
  *]
}