hongji.li
2023-11-07 1a1ba3ad5ed9e4380185aa1ccad20204a0e5f115
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
Quintiq file version 2.0
#parent: #root
Method UpdateSnapshotComponent (
  JSON json
)
{
  Description: 'Replace the `SnapshotComponent` with the deserialized `SnapshotComponent` from the `JSON`.'
  TextBody:
  [*
    snapshot_deserialize := LibOpt_Snapshot::Deserialize( json, this.Run() );
    
    // Delete current snapshot
    if( not isnull( this.SnapshotComponent() ) )
    {
      // Decrease the NrTimesCalled, for deleting the snapshots
      descendants := this.SnapshotComponent().Descendants();
      descendants.Add( this.SnapshotComponent() );
      traverse( descendants, Elements.astype( LibOpt_SnapshotComponent ), snapshot )
      {
        snapshot.Component().NrTimesCalled( snapshot.Component().NrTimesCalled() - 1 );
      }
      traverse( descendants, Elements.astype( LibOpt_SnapshotSuboptimizer ), snapshot, snapshot.IsRollback()
                                                                                       and not isnull( snapshot.Suboptimizer() ) )
      {
        snapshot.Suboptimizer().NrOfRollbacks( snapshot.Suboptimizer().NrOfRollbacks() - 1 );
      }
      this.SnapshotComponent().Delete();
    }
    
    snapshot_parent := guard( this.Parent().SnapshotComponent(), null( LibOpt_SnapshotComponent ) );
    snapshot_deserialize.Parent( relset, snapshot_parent );
    this.SnapshotComponent( relset, snapshot_deserialize.astype( LibOpt_SnapshotComponent ) );
    
    // Increase the NrTimesCalled, for adding new snapshots
    descendants := snapshot_deserialize.Descendants();
    descendants.Add( this.SnapshotComponent() );
    traverse( descendants, Elements.astype( LibOpt_SnapshotComponent ), snapshot )
    {
      snapshot.Component().NrTimesCalled( snapshot.Component().NrTimesCalled() + 1 );
    }
    //traverse suboptimizers to update NrOfRollbacks
    traverse( descendants, Elements.astype( LibOpt_SnapshotSuboptimizer ), snapshot )
    {
      if( snapshot.IsRollback() and this.Component().istype( LibOpt_Suboptimizer ) )
      {
        subOpt := this.Component().astype( LibOpt_Suboptimizer );
        subOpt.NrOfRollbacks( subOpt.NrOfRollbacks() + 1 );
        subOpt.SnapshotSuboptimizer( relinsert, snapshot );
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}