haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
MethodOverride PostHandleResult (
  LibOpt_Task task,
  RealVector kpi_pre
)
{
  TextBody:
  [*
    runcontext := RunContextForCapacityPlanning::GetRunContextCapacityPlanning( task.Run() ); 
    if ( isnull( this.CurrentSubOptimizerLevel() )                                      // when done we make sure current ptr is null
         or ( runcontext.IsMetaIteration() and not this.IsBeyondFirstIteration() ) ) 
    {
      snapshot := this.LogKPI( task, Translations::LibOpt_SnapshotKPI_CommentPostHandleResult() );
      if( isnull( this.RollbackKPI() ) )
      {
        // Throw a warning if it has not been thrown before in this snapshot.
        if( not isnull( kpi_pre ) )
        {
          LibOpt_SnapshotWarning::Throw( task, Translations::LibOpt_Suboptimizer_NoRollbackKPI() );
        }
      }
      else
      {
        kpi_post := RealVector::Construct( snapshot.astype( SnapshotMacroPlannerOptimizer ).RollbackKPI() ); 
        change := construct(  RealVector ); 
        message := ''; 
        isaccepted := this.RollbackKPI().CurrentScoreIsAccepted( task, kpi_pre, &kpi_post, &change, this.FocusLevel(), message ); 
        
        should_rollback := not isaccepted; 
        
        // Store rollback KPI difference
        if( task.Run().HasSnapshots() and not this.IsFullPlanMetaPriorFocus() )
        {
          LibOpt_SnapshotSuboptimizer::Create( task.Run(), kpi_pre, kpi_post, this.RollbackKPI(), should_rollback );
        }
        
        if( should_rollback )
        {
          if( not isnull( snapshot ) )
          {
            snapshot.IsRolledBack( true );
          }
          rcm := RunContextMeta::GetRunContextMeta( this.Run() ); 
          if ( rcm.OptionStopOnRollback() ) 
          {
            this.Run().BreakpointEvent( relnew );
          }
          else
          {
            this.Rollback( kpi_pre, kpi_post, task );
          }
        }
      }
    }
    this.IsBeyondFirstIteration( true ); // used for meta optimizer to make the first iteration of each focus level void planning ( only record KPIs)
  *]
}