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
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' }
}