Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method Execute ( 
 | 
  AlgorithmRun algorithmrun, 
 | 
  ProductInStockingPointInPeriodPlannings pispipssmartplan, 
 | 
  LaneLegs lanelegsforoptimization, 
 | 
  Period_MPs periods, 
 | 
  Units units, 
 | 
  Boolean isusingselectedunits, 
 | 
  Process_MP process, 
 | 
  Number numberofperiodssmartplan, 
 | 
  Boolean isupstreamsmartplan, 
 | 
  Boolean ismiddleoutsmartplan, 
 | 
  OptimizerPuzzle optimizerpuzzle 
 | 
) as stream[JSON] 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // If the option is checked that only the demand of the selected pispips should be met 
 | 
    // Then the sales demand variables are frozen for all pispips that are not in pispipssmartplan 
 | 
    // Since we plan on base periods, we need to select the basepispips that are related to the smartplan pispips 
 | 
    allpispipssmartplan := construct( ProductInStockingPointInPeriodPlannings ); 
 | 
    traverse( pispipssmartplan, Elements, pispipsmartplan ) 
 | 
    { 
 | 
        allpispipssmartplan.Add( pispipsmartplan ); 
 | 
        // Also select the base pispips of all product leaves 
 | 
        leafpispipssmartplan := pispipsmartplan.GetPlanningLeavesOfProductDimension(); 
 | 
        allpispipssmartplan := allpispipssmartplan.Union( leafpispipssmartplan ); 
 | 
    } 
 | 
     
 | 
    run := this.CreateRun( this.DefaultScope() ); 
 | 
     
 | 
    run.StartScope().AddSmartPlanPISPIPsToScope( allpispipssmartplan );  
 | 
    run.StartScope().AddLaneLegsForOptimizationToScope( lanelegsforoptimization );  
 | 
    run.StartScope().AddPeriodsToScope( periods ); 
 | 
    optacccounts := selectset( this, Optimization.astype( Optimization ).MacroPlan.Account_MP, account, account.IsUsedByOptimizer() )  
 | 
    run.StartScope().AddOptimizerAccountsToScope( optacccounts );  
 | 
    run.StartScope().Add( optimizerpuzzle );  
 | 
     
 | 
    firstperiod := minselect(  periods, Elements, p, true, p.Start() );  
 | 
    lastperiod := maxselect(  periods, Elements, p, true, p.Start() );  
 | 
    context := RunContextForCapacityPlanning::Create( run, units, firstperiod, lastperiod );  
 | 
    context.Initialize( algorithmrun );  
 | 
    context.IsUsingSelectedUnits( isusingselectedunits ); // already set by algorithmrun - but will set here based on argument because algorithmrun will go 
 | 
    context.Process_MP( relset, process ); // process for smart plan  
 | 
    context.NumberOfPeriodsSmartPlan( numberofperiodssmartplan ); 
 | 
     
 | 
    this.CreateComponents( run ); 
 | 
     
 | 
    transformerup := select( run, Component.astype(  TransformerSmartPlanUpStream ), tup, true, true ); 
 | 
    prepostcomp := select(  run, Component.astype(  OptimizerPrePostProcessing ), p, true, true );  
 | 
    suboptdown := select(  run, Component.astype( CapacityPlanningSuboptimizer ), o, true, o.Name() = OptimizerSmartPlan::DownStreamSubOptimizerName() );  
 | 
     
 | 
    if ( not ismiddleoutsmartplan )  
 | 
    { 
 | 
      if ( isupstreamsmartplan )  
 | 
      { 
 | 
        prepostcomp.To( transformerup );   
 | 
      } 
 | 
      else  
 | 
      { 
 | 
        suboptdown.Next( relflush);     
 | 
      } 
 | 
    } 
 | 
     
 | 
    if ( context.IsSync() )  
 | 
    { 
 | 
      this.ConfigureForOneTransaction( run );  
 | 
    } 
 | 
     
 | 
    return run.Start(); 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |