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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
Quintiq file version 2.0
#parent: #root
Method SetWeightsAndParams (
  Boolean issmartplan,
  StrategyMacroPlan strategymacroplan,
  LibOBT_RunTaskSetting setting
) as AlgorithmRun
{
  Description: 'Set active weights and optimizer parameters'
  TextBody:
  [*
    // Set the strategy
    algorithmrun := this.SynchronizeAlgorithmRun( issmartplan );
    algorithmrun.UpdateOptimizerSetting( strategymacroplan );
    
    // Set active value for non financial kpi
    traverse( strategymacroplan, KPIWeightMacroPlan, kpiweight, not kpiweight.KPIIsAccount() )
    {  
      name := kpiweight.KPIName();
      
      if( name = Translations::MP_GlobalParameters_KPIBlendingName() )
      {
        algorithmrun.BlendingWeight( kpiweight.Weight() );
        algorithmrun.BlendingLevel( kpiweight.Level() );
      } 
      else if( name = Translations::MP_GlobalParameters_KPICampaignName() )
      {
        algorithmrun.CampaignWeight( kpiweight.Weight() );
        algorithmrun.CampaignLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIFulfillmentName() )
      {
        algorithmrun.FulfillmentWeight( kpiweight.Weight() );
        algorithmrun.FulfillmentLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPILotSizeName() )
      {
        algorithmrun.LotSizeWeight( kpiweight.Weight() );
        algorithmrun.LotSizeLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIInventoryMixBalancing() )
      {
        algorithmrun.InventoryMixBalancingWeight( kpiweight.Weight() );
        algorithmrun.InventoryMixBalancingLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIMaximumInventoryLevelName() )
      {
        algorithmrun.MaximumInventoryLevelWeight( kpiweight.Weight() );
        algorithmrun.MaximumInventoryLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIMinimumInventoryLevelName() )
      {
        algorithmrun.MinimumInventoryLevelWeight( kpiweight.Weight() );
        algorithmrun.MinimumInventoryLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIMaximumSupplyName() )
      {
        algorithmrun.MaximumSupplyWeight( kpiweight.Weight() );
        algorithmrun.MaximumSupplyLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIMinimumSupplyName() )
      {
        algorithmrun.MinimumSupplyWeight( kpiweight.Weight() );
        algorithmrun.MinimumSupplyLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIMinimumUnitCapacityName() )
      {
        algorithmrun.MinimumUnitCapacityWeight( kpiweight.Weight() );
        algorithmrun.MinimumUnitCapacityLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIPostponementPenaltyName() )
      {
        algorithmrun.PostponementPenaltyWeight( kpiweight.Weight() );
        algorithmrun.PostponementPenaltyLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIProcessMaximumQuantity() )
      {
        algorithmrun.ProcessMaximumQuantityWeight( kpiweight.Weight() );
        algorithmrun.ProcessMaximumQuantityLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIProcessMinimumQuantity() )
      {
        algorithmrun.ProcessMinimumQuantityWeight( kpiweight.Weight() );
        algorithmrun.ProcessMinimumQuantityLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPISalesDemandPriorityName() )
      {
        algorithmrun.SalesDemandPriorityWeight( kpiweight.Weight() );
        algorithmrun.SalesDemandPriorityLevel( kpiweight.Level() );
      }
        else if( name = Translations::MP_GlobalParameters_KPIFulfillmentTargetName() )
      {
        algorithmrun.FulfillmentTargetWeight( kpiweight.Weight() );
        algorithmrun.FulfillmentTargetLevel( kpiweight.Level() ); 
      }
      else if( name = Translations::MP_GlobalParameters_KPIServiceLevelName() )
      {
        algorithmrun.ServiceLevelWeight( kpiweight.Weight() );
        algorithmrun.ServiceLevelLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIStockingPointCapacityName() )
      {
        algorithmrun.StockingPointCapacityWeight( kpiweight.Weight() );
        algorithmrun.StockingPointCapacityLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPISupplyTargetName() )
      {
        algorithmrun.SupplyTargetWeight( kpiweight.Weight() );
        algorithmrun.SupplyTargetLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPISafetyStock() )
      {
        algorithmrun.TargetInventoryLevelWeight( kpiweight.Weight() );
        algorithmrun.TargetInventoryLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIUnitCapacityName() )
      {
        algorithmrun.UnitCapacityWeight( kpiweight.Weight() );
        algorithmrun.UnitCapacityLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPICapacitySmoothing() ) 
      {
        algorithmrun.CapacitySmoothingWeight( kpiweight.Weight() ); 
        algorithmrun.CapacitySmoothingLevel( kpiweight.Level() ); 
      }
      else if( name = Translations::MP_GlobalParameters_KPITotalExpiredQuantity() ) 
      {
        algorithmrun.ExpiredQtyWeight( kpiweight.Weight() ); 
        algorithmrun.ExpiredQtyLevel( kpiweight.Level() ); 
      }
      else if( name = Translations::MP_GlobalParameters_KPICO2Emission() )
      {
        algorithmrun.CO2EmissionWeight( kpiweight.Weight() );
        algorithmrun.CO2EmissionLevel( kpiweight.Level() );
      }
      else if( name = Translations::MP_GlobalParameters_KPIShiftPatternChangesPenalty() )
      {
        algorithmrun.ShiftPatternChangesPenaltyWeight( kpiweight.Weight() );
        algorithmrun.ShiftPatternChangesPenaltyLevel( kpiweight.Level() );
      }
    }
    
    // Scaling factors used for the run
    algorithmrun.MassScalingFactor( strategymacroplan.MassScalingFactor() );
    algorithmrun.MonetaryScalingFactor( strategymacroplan.MonetaryScalingFactor() );
    algorithmrun.TimeScalingFactor( strategymacroplan.TimeScalingFactor() );
    algorithmrun.TimeAccountScalingFactor( strategymacroplan.TimeAccountScalingFactor() );
    algorithmrun.InventoryHoldingScalingFactor( strategymacroplan.InventoryHoldingScalingFactor() );
    
    hascostdriverlotactiveaccount := false;
    hasonetimecostdriveractive := false; 
    // Account kpis
    traverse( strategymacroplan, KPIWeightMacroPlan, kpiweight, kpiweight.KPIIsAccount() )
    {
      account := select( this, MacroPlan.Account_MP, a, a.Name() = kpiweight.KPIName() );
      
      if( not isnull( account ) )
      {
        account.UpdateOptimizerStrategy( kpiweight.Level(), kpiweight.Weight() );
    
        hascostdriverlotactiveaccount := hascostdriverlotactiveaccount 
                                         or ( account.IsCostDriverLot() 
                                              and account.Weight() > 0 
                                              and account.Level() > 0 
                                              and account.IsUsedByOptimizer() );
        hasonetimecostdriveractive := hasonetimecostdriveractive 
                                      or ( account.IsCostDriverOneTimeCost() 
                                           and account.Weight() > 0 
                                           and account.Level() > 0  
                                           and account.IsUsedByOptimizer() ); 
      }
    }
    
    algorithmrun.UseLotCost( hascostdriverlotactiveaccount );
    algorithmrun.UseOneTimeCost( hasonetimecostdriveractive ); 
    
    if ( not strategymacroplan.UseMetaOptimizer() ) // for the meta optimizer the update will happen at the start of each focus level 
    {
      this.UpdateGoalScaling( strategymacroplan, null(  StrategyLevelMacroPlan ) ); // not providing strategy level macroplan, so non level specific factors are used ( also for hidden level of meta)
    }
    
    AlgorithmRunLevel::CreateAlgorithmRunLevelsAndKPIResults( algorithmrun, strategymacroplan, setting );
               
    // Set the time and status
    this.MacroPlan().LastOptimizerRun( DateTime::ActualTime() );
    
    return algorithmrun;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}