| 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; | 
|   *] | 
| } |