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
Quintiq file version 2.0
#parent: #root
StaticMethod GetRollbackKPIDiff (LibOpt_Task task, LibOpt_DatasetCopyConditional datasetcopy) as owning RealVector
{
  Description:
  [*
    Returns the difference between the pre handle result Rollback KPI and the post handle result Rollback KPI of this component (or the next component that uses `LibOpt_SnapshotKPIs`) as a `RealVector`.
    This difference is calculated as: `diff := KPIposthandleresult - KPIprehandleresult`.
    Therefore, the returned `RealVector` will contain a negative value if the Rollback KPI decreased this iteration. Note that a negative value corresponds to an improvement if we are minimizing the Rollback KPI.
  *]
  TextBody:
  [*
    snapshotcomponent := task.SnapshotComponent();
    snapshotKPIprehandleresult := LibOpt_SnapshotKPI::GetSnapshotKPIDownstreamComponent( snapshotcomponent, true );
    snapshotKPIposthandleresult := LibOpt_SnapshotKPI::GetSnapshotKPIDownstreamComponent( snapshotcomponent, false );
    
    diff := null( RealVector, owning );
    // It is sufficient to check if snapshotKPIposthandleresult is null. If snapshotKPIprehandleresult is null, then snapshotKPIposthandleresult will also always be null.
    if( not isnull( snapshotKPIposthandleresult ) ) 
    {
      KPIprehandleresult := snapshotKPIprehandleresult.RollbackKPI();
      KPIposthandleresult := snapshotKPIposthandleresult.RollbackKPI();
      
      diff := RealVector::Construct( KPIposthandleresult ) - RealVector::Construct( KPIprehandleresult );  
    }
    else
    {
      // No snapshotKPIposthandleresult has been found on this component or on any descendant component that uses SnapshotKPIs.
      // Show a warning in the Snapshot form to indicate this to the AE.
      replannablesnapshot := select( task,
                                     SnapshotComponent.Children.astype( LibOpt_SnapshotReplannableCopyDataset ),
                                     snapshot,
                                     snapshot.ComponentPositionName() = datasetcopy.ComponentPositionName()
                                     );
      if( not isnull( replannablesnapshot ) )
      {    
        LibOpt_SnapshotWarning::Throw( task.Run(),
                                       replannablesnapshot,
                                       Translations::LibOpt_DatasetCopyOnRollbackSize_NoPostHandleResult() ); 
      }
      else
      {
        LibOpt_SnapshotWarning::Throw( task, 
                                       Translations::LibOpt_DatasetCopyOnRollbackSize_NoPostHandleResult() ); 
      }  
    }
    
    return &diff;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}