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
Quintiq file version 2.0
#parent: #root
Method DelayedInitialization (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  LibOpt_Task task,
  const RunContextForCapacityPlanning runcontext,
  Boolean isfeasible
)
{
  TextBody:
  [*
    if ( isfeasible ) // we omit not needed processing in the handle infeasible for performance
    {
      this.RestoreSetCPLEXBoundFlags( program, runcontext ); // need flags on objects (for const-ness written to program)
      this.StorePITVarProperties( program, task.Scope() );
      this.StoreSalesVarProperties( program, task.Scope() );
      
      this.ResetManualQuanties(  this.GetRunContext(), task.Scope() ); // resetting manual plan if user has selected override manual quantities
    }
    
    // logged values for snapshots 
    this.LoggedNrPTQtyCampaignSlackVar( [Number] guard( program.RetrieveReal( CapacityPlanningSuboptimizer::LoggedNrPTQtyCampaignSlackVarName() ), 0 ) ); 
    
    this.MacroPlan().GetLastAlgorithmRun().NumberOfThreads( program.Threads() ); // record what is used
    
    // workaround. Was stored on program because init needs to be const
    nextlevel := this.CurrentSubOptimizerLevel().LevelNumber(); 
    algorithmrunlevel := this.MacroPlan().GetLastAlgorithmRun().GetAlgorithmRunLevel( nextlevel ); 
    if ( not isnull( algorithmrunlevel ) ) 
    {
      actualtime := DateTime::ConstructMinutes( this.BaseForActualTime(), program.RetrieveReal( 'ActivateGoals_actualtime' ) ); 
      algorithmrunlevel.Update( actualtime, algorithmrunlevel.End(), false, 0.0, 0.0, 0.0, program.Optimal() );
    }
    if ( this.IsAutoScalingEnabled() ) // need to do init in the handle feasible or handle infeasible because init is const. We do it at the very first return to a handle method
    {
      this.InitForScaling( program ); 
    }
    
    if ( not this.InOneTransaction() ) 
    {
      task.Log( 'Duration init var+goal = ' + [String] program.RetrieveReal( 'duration_init_vargoals' ) ); 
      start_init_reactive := program.RetrieveReal( 'start_init_reactive' ); 
      end_init_reactive := program.RetrieveReal( 'end_init_reactive' ); 
      duration_init_reactive := (end_init_reactive - start_init_reactive )/OS::PrecisionCounterFrequency(); 
      
      timetoclonemsg := program.RetrieveString(  'timetoclone_msg' );
      task.Log( timetoclonemsg ); 
      timeforA := program.RetrieveReal( 'type_A_constraints' ); 
      timeforB := program.RetrieveReal( 'type_B_constraints' ); 
      timeforC := program.RetrieveReal( 'type_C_constraints' ); 
      this.InitTimeThreadA( timeforA ); // written to snapshot later
      this.InitTimeThreadB( timeforB ); 
      this.InitTimeThreadC( timeforC ); 
      
      cumultimeA := timeforA; 
      cumultimeB := timeforB; 
      cumultimeC := timeforC; 
      snapshot := task.Run().LastSnapshot(); 
      collected := 0; 
      snapshots := construct(  SnapshotMacroPlannerOptimizers ); 
      while ( not isnull( snapshot ) and collected < 5 ) 
      {
        if ( snapshot.istype( SnapshotMacroPlannerOptimizer ) ) 
        {
          snapshots.Add( snapshot.astype( SnapshotMacroPlannerOptimizer ) ); 
          collected++; 
        }  
        snapshot := snapshot.PreviousOnRun(); 
      }
    
      cumultimeA := cumultimeA + sum ( snapshots, Elements, s, true, s.InitTimeThreadA() ); 
      cumultimeB := cumultimeB + sum ( snapshots, Elements, s, true, s.InitTimeThreadB() ); 
      cumultimeC := cumultimeC + sum ( snapshots, Elements, s, true, s.InitTimeThreadC() ); 
     
      task.Log( 'Duration type A init constraints = ' + [String] timeforA + ' = cumul -> ' + [String] cumultimeA ); 
      task.Log( 'Duration type B init constraints = ' + [String] timeforB + ' = cumul -> ' + [String] cumultimeB ); 
      task.Log( 'Duration type C init constraints = ' + [String] timeforC + ' = cumul -> ' + [String] cumultimeC ); 
      task.Log( program.RetrieveString( 'MergeDuration' ) ); 
      task.Log( 'Duration init reactive = ' + [String] duration_init_reactive ); 
      this.AdjustWorkLoad( task, cumultimeA, cumultimeB, cumultimeC ); 
      msg := 'Adjusting thread parameters to' 
              + [String] this.ThreadAParameter() 
              + ', ' 
              + [String] this.ThreadBParameter() 
              + 'ratios:' 
              + [String] (this.ThreadAParameter() / 1000) 
              + ', ' 
              + [String] ((this.ThreadBParameter() - this.ThreadAParameter()) / 1000 )
              + ', '
              + [String] ((1000 - this.ThreadBParameter()) / 1000); 
      task.Log( msg ); 
    
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}