chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 downstream smart plan optimizer run
    // If this pispip is already part of this optimizer run, then we do not need to consider it again
    
    alreadyvisited_in_downstreamsearch := pispip.TransformerSmartPlanDownStreamWhenVisited() = this; 
    done_because_exceeded_size := ifexpr(  this.CheckMaxNeighborhoodSize(), scope.EstimatedNrPISPIPs() > this.MaxPISPIPSNeighborhood(), false ); 
    stop_because_loop_protection := depth > 1000; 
    if ( stop_because_loop_protection ) 
    {
      info(  'loop in downstream search'); 
    }
    
    if ( this.Debug() ) 
    {
      debuginfo( depth, ' ',  pispip.ProductInStockingPoint_MP().StockingPointID(), 
                 pispip.ProductInStockingPoint_MP().ProductID(), 
                 pispip.Start(), 
                 'already visited downstream=', alreadyvisited_in_downstreamsearch, 
                 'in scope=', scope.Contains( pispip.PISPIPInOptimizerRun() ), 
                 'dd=', pispip.DependentDemandFulfilledQuantity(), 
                 'ddnontrp=', pispip.DependentDemandNonTripFulfilledQuantity() ); 
    }
    
    this.Visit( pispip ); 
    
    if ( not alreadyvisited_in_downstreamsearch and not scope.Contains( pispip.PISPIPInOptimizerRun() ) )
    {
      scope.Add( pispip );
    }
    if( not stop_because_loop_protection
        and not alreadyvisited_in_downstreamsearch )
    {  
      if ( not done_because_exceeded_size ) 
      {
        ptforrecursive := this.GetPeriodTasksToSearch( pispip, scope, runcontext, units, isusingselectedunits, depth );         
    
        traverse( ptforrecursive, Elements, periodtaskoperation ) 
        {
          scope.Add( periodtaskoperation );  // note units, unitperiods, operation we add all the way at the end ( LibOpt_Scope.CompleteForPTO_PIT)   
        
          traverse( periodtaskoperation, DependentDemand.ProductInStockingPointInPeriodPlanningLeaf, p ) 
          {
            if ( not scope.Contains( p.PISPIPInOptimizerRun() ) )
            {
              scope.Add( p );  
            }
          }
    
          traverse( periodtaskoperation, NewSupply.ProductInStockingPointInPeriodPlanningLeaf, newpispip ) 
          { 
            // If this new pispip is not part of the optimizer run
            if( newpispip.HasRegularProductForOptimizer() or newpispip.GetProductIsIncludedInOptimizerRun( runcontext.IsPostProcessing() ) )
            {
              this.SetOptimizerInputSmartPlan( newpispip, isusingselectedunits, units, depth + 1, scope, runcontext );
            }
          }
        }
    
        pit_to_search := this.GetProductInTripsToSearch( pispip, scope, runcontext, units, isusingselectedunits, depth ); 
    
        // Add the trips to the optimizer run
        traverse( pit_to_search, Elements, productintrip )
        {  
          // Add the related productintrip to productintripsforoptimization
          newpispip := guard( productintrip.NewSupply().ProductInStockingPointInPeriodPlanningLeaf(), null( ProductInStockingPointInPeriodPlanningLeaf ) ); 
          if ( not isnull( newpispip )
               and not newpispip.IsPeriodFrozen() ) 
          {
            scope.Add(  productintrip ); // note units, unitperiods, trip we add all the way at the end ( LibOpt_Scope.CompleteForPTO_PIT) 
            departurepispip := productintrip.DeparturePISPIP(); 
            scope.Add( departurepispip ); // must add departure to scope, arrival is explored below (and added that way)
    
            this.SetOptimizerInputSmartPlan( newpispip, isusingselectedunits, units, depth + 1, scope, runcontext );
          }
          else
          {
            debuginfo( 'Suspicious - output pispip of pit null', 'Origin=', 
                       pispip.ProductInStockingPoint_MP().Name(), 
                       pispip.Start(), 'pit = ', 
                       productintrip.ProductID(), 
                       productintrip.Trip().LaneLeg().OriginStockingPointID(), 
                       '->', 
                       productintrip.Trip().LaneLeg().DestinationStockingPointID() ); 
          }
        } //end traverse pit_to_search
      } // end if not done because size exceeded
    } // end if explore recursive, etc.
    
    return true;
  *]
}