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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Quintiq file version 2.0
#parent: #root
Method CapacityPlanningAlgorithmInitVariables (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const constcontent PeriodTaskOperations userperiodtasks,
  const constcontent ProductInTrips userproductintrips,
  const constcontent ProductInStockingPointInPeriodPlannings pispipssmartplan,
  const LibOpt_Scope scope,
  const constcontent ProductInStockingPointInPeriodPlannings pispipsinrun,
  constcontent ProductInStockingPointInPeriodPlanningLeafs leafpispipsinrun,
  const constcontent ProductInStockingPoint_MPs pispsinrun,
  const constcontent ProductInTrips pitinrun
) const
{
  TextBody:
  [*
    runcontext := this.GetRunContextConst(); 
    if( not runcontext.IsInventoryOptimizationRun() )
    {
      progress( 'Init variables', DateTime::ActualTime());
      info( 'Init variables', DateTime::ActualTime());
    }
    
    this.RegisterTypes( program );
    
    computenvar := this.MacroPlan().Optimization().DebugMode(); 
    nvars := ifexpr( computenvar, counter( program, Variables, v, true, true ), 0 ); 
    oldnvars := nvars; 
    if ( computenvar ) 
    {
      debuginfo(  'start vars:', nvars ); 
    }
    // Create variables for KPI total value
    this.InitVariablesForKPITotalValue( program, runcontext, scope );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' this.InitVariablesForKPITotalValue( program, runcontext, scope );', nvars-oldnvars );  
      oldnvars := nvars; 
    }
    // create variables for supply
    this.InitVariablesForOperationPeriodTask( program, userperiodtasks, scope );
    if ( computenvar )
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' periodtask related vars:', nvars-oldnvars );  
      oldnvars := nvars; 
    }
    
    this.InitVariablesForTrip( program, userproductintrips, scope, pitinrun );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' trip related vars;', nvars-oldnvars);  
      oldnvars := nvars; 
    }
    
    // create variables for sales demands
    this.InitVariablesForSalesDemands( program, scope )
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' sales demand vars:', nvars-oldnvars );  
      oldnvars := nvars; 
    }
    
    // create variable for pispip
    this.InitVariablesForPISPIP( program, pispipssmartplan, scope, pispipsinrun, leafpispipsinrun, pispsinrun );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' pispips vars:', nvars-oldnvars);  
      oldnvars := nvars; 
    }
    
    // create variable for stocking point inventory
    this.InitVariablesForStockingPointInventory( program, runcontext, scope );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' sp vars:', nvars-oldnvars );  
      oldnvars := nvars; 
    }
    
    // create variable for unit period quantity
    this.InitVariablesForUnitPeriods( program, scope );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' unit period vars:', nvars-oldnvars );  
      oldnvars := nvars; 
    }
    
    // create variable for supply specification
    this.InitVariablesForSupplySpecification( program, scope );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' supply spec:', nvars-oldnvars );  
      oldnvars := nvars; 
    } 
    
    //Generate variables related to campaigns if campaignoptimization is enabled
    this.InitVariablesForCampaignCombiSelection( program, runcontext, scope ); 
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' campaign related vars:', nvars-oldnvars );  
      oldnvars := nvars; 
    }
    
    // create variables for shift patterns
    this.InitVariablesForShiftPatterns( program, runcontext, scope );
    if ( computenvar ) 
    {
      nvars := counter( program, Variables, v, true, true ); 
      debuginfo( ' shift pattern vars:', nvars-oldnvars );  
      oldnvars := nvars; 
    } 
    
    //Also add the total number of vars when in debugmode
    if ( computenvar ) 
    {
      debuginfo( 'Total variables:', nvars ); 
    }
    
    if ( this.IsPriorLevelsFixed() )  
    {
      this.FixDecisionVariablesToCurrentPlanBasedOnLevel( program, runcontext, scope ); 
    }
    
    // In the inventory optimization, we need to obtain the KPIs of each simulation at the end of the simulation
    // Therefore, we rerun the optimizer over the full horizon with the decisions frozen
    if( runcontext.IsFrozenRun() )
    
    {
      debuginfo(  'Freezing decision variables. CurrentLevel = ', this.CurrentSubOptimizerLevel().LevelNumber() ); 
      unfreeze := false; 
      this.Debug_FreezeDecisionVariables( program, runcontext.FirstPeriod_MP(), runcontext.LastPeriod_MP(), scope, unfreeze ); 
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}