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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Quintiq file version 2.0
#parent: #root
MethodOverride SetOptimizerInputSmartPlan (
  ProductInStockingPointInPeriodPlanningLeaf pispip,
  Boolean isusingselectedunits,
  Units units,
  Number depth,
  LibOpt_Scope scope,
  RunContextForCapacityPlanning runcontext
) as Boolean
{
  TextBody:
  [*
    // Recursive methods that selects all required instances for the upstream smart plan optimizer run
    // If this pispip is already part of this optimizer run, then we do not need to consider it again
    
    // unused argument: explorerecursive
    
    hasbeenvisited := pispip.TransformerSmartPlanUpStreamWhenVisitedUp() = this; 
    this.Visit( pispip ); 
    isinrun := scope.Contains(  pispip.PISPIPInOptimizerRun() ); 
    
    if ( this.Debug() ) 
    {
      debuginfo( depth, ' ', pispip.ProductInStockingPoint_MP().StockingPointID(), 
                 pispip.ProductInStockingPoint_MP().ProductID(), 
                 pispip.Start(), 
                 'in run =', isinrun ); 
    }
    
    if( not hasbeenvisited )
    {
      if ( not isinrun ) 
      {
        scope.Add( pispip );
      }
    
      ptforrecursive := this.GetPeriodTasksToSearch( pispip, scope, runcontext, units, isusingselectedunits, depth ); 
    
      traverse( ptforrecursive, Elements, pt ) 
      {
        newpispips := selectset(  pt, DependentDemand.ProductInStockingPointInPeriodPlanningLeaf, newpispip, true, true ); 
        if ( not runcontext.IsMetaIteration() or forall( newpispips, Elements, newpispip, true, not newpispip.IsPeriodFrozen() ) )
        {
          scope.Add( pt );
          if ( pt.NewSupply( relsize ) > 1 ) 
          {
            traverse( pt, NewSupply.ProductInStockingPointInPeriodPlanningLeaf, p )
            {
              this.SidePISPIP( relinsert, p ); // we add these to scope after recursive procedure is done so that if whe happen to hit an output product during this we still explore it
            }
          }
          
          traverse( newpispips, Elements, newpispip )
          {
            if( runcontext.IsMetaIteration() or newpispip.GetProductIsIncludedInOptimizerRun( runcontext.IsPostProcessing() ) ) 
            {
              this.SetOptimizerInputSmartPlan( newpispip, isusingselectedunits, units, depth + 1, scope, runcontext );
            }
          }
        }
      }
      
      // Recursively search trips /  product in trips 
      pit_to_search := this.GetProductInTripsToSearch( pispip, scope, runcontext, units, isusingselectedunits, depth );  
      
      traverse( pit_to_search, Elements, productintrip )
      { 
        newpispip := productintrip.DependentDemand().ProductInStockingPointInPeriodPlanningLeaf(); 
        if ( not runcontext.IsMetaIteration() or not newpispip.IsPeriodFrozen() ) 
        {
          scope.Add( productintrip ); // note units, unitperiods, trip we add all the way at the end ( LibOpt_Scope.CompleteForPTO_PIT) 
          this.SetOptimizerInputSmartPlan( newpispip, isusingselectedunits, units, depth + 1, scope, runcontext );
        }
      }
    } // endif not in run
    
    return true;
  *]
}