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
Quintiq file version 2.0
#parent: #root
MethodOverride Operation (
  LibOpt_Task task
) as stream[JSON]
{
  TextBody:
  [*
    debuginfo(  'Pre processing' ); 
    runcontext := RunContextForCapacityPlanning::GetRunContextCapacityPlanning( task.Run() ); 
    
    this.ClearSalesDemandBelowThreshold( task ); 
    this.CreateSupportData( task, runcontext ); // trips, product in trips, periodtaskoperation ( in case of meta ). combis in case of campaign optimization
    
    if ( runcontext.IsMetaIteration() ) 
    {
      rcm := RunContextMeta::GetRunContextMeta( task.Run() ); 
      
      mp := this.Optimization().astype( Optimization ).MacroPlan(); 
      eis := mp.OptimizerMetaEIS(); 
      eis.FocusLevelForEIS( -1 ); // triggers EIS in the 1st operation of meta selector, because levels start at 0
      eis.BaseForTried( rcm.OptionBaseForTried() ); 
      eis.BaseForTriedAsFriend( rcm.OptionBaseForTriedAsFried() ); 
      eis.BaseForPeriodDecay( rcm.OptionStartBaseForPeriodDecay() ); // slowly move towards 1 
      eis.BaseForDecayNrTimeInScope( rcm.OptionBaseForDecayNrTimeInScope() ); 
      OptimizerMeta::ResetIsTried( selectset( mp, PlanningPeriod, p, true, true ) ); 
      Transaction::Transaction().Propagate(); // compute estimated improvements scores after above changes
        
      opt := mp.Optimization(); 
      gp := mp.GlobalParameters_MP(); 
      opstart := runcontext.FirstPeriod_MP().StartDate();  
      optend := runcontext.LastPeriod_MP().EndDate(); 
      
      if ( not isnull( opt.AlgorithmScaling() ) )
      {
        opt.AlgorithmScaling().ScaleFactorsSuggestedForLevel( relflush );
      }
        
      mp.Optimization().PruneProductInTrips( mp, task ); // remove product in trips meta optimizer detects as useless
      
      changed := false; 
      gp.StartOfKPIHorizonForMetaRollback( gp.StartOfKPIHorizon() ); 
      gp.EndOfKPIHorizonForMetaRollback( gp.EndOfKPIHorizon() ); 
      if ( gp.GetStartOfKPIHorizon() > opstart ) 
      {
        gp.StartOfKPIHorizonForMetaRollback( opstart ); 
        changed := true; 
      }
      if ( gp.GetEndOfKPIHorizon() < optend ) 
      {
        gp.EndOfKPIHorizonForMetaRollback( optend ); 
        changed := true; 
      }
      if ( changed ) 
      {
        Transaction::Transaction().Propagate( attribute( Period_MP, IsWithinKPIHorizon ) );
      }
      
      this.SetFeedBackQuantities( eis.MacroPlan(), runcontext, task.Scope() ); 
      runcontext.SetPeriodTaskOperationUser( runcontext.HasOverwrittenManualPlanning(), task.Scope(), true );      // for meta optimizer we want to set it once
      runcontext.SetProductInTripManualQuantity( runcontext.HasOverwrittenManualPlanning(), task.Scope(), true );  // and not each iteration based on scope
    }
    this.Optimization().astype( Optimization ).MacroPlan().SetServiceLevelBaseIDs();
    this.SetMaxPostponementPeriodForPISPs(); 
    
    this.StoreInitialInventoryViolations( runcontext ); 
    
    return this.Continue( task, task.Scope() );
  *]
}