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
Quintiq file version 2.0
#parent: #root
Method CleanUpTransportCapacity
{
  Description: 'Find sets of equivalent transport capacities in consecutive periods and remove all but the first one'
  TextBody:
  [*
    // Clean up transport capacity
    // Get a sorted set of all transport capacities of this unit
    sortedtcs := selectsortedset( this, TransportCapacity, tc, 
                                  true, 
                                  tc.Start() );
    
    head := null( TransportCapacity );
    
    // Traverse the sorted set of transport capacities
    traverse( sortedtcs, Elements, tc )
    {
      // Check if there's any transport capacity is selected, if there's none, set the current transport capacity as selected
      if( isnull( head ) )
      {
        head := tc;
      }
    
      // Get the index of the selected transport capacity in the sorted set
      headpos := sortedtcs.Find( head );
      // Get the next transport capacity after the selected transport capacity in the sorted set
      nexttc := guard( sortedtcs.Element( headpos + 1 ), null( TransportCapacity ) );
    
      // Check if there's any next transport capacity
      if( not isnull( nexttc ) )
      {
        // Check if the next transport capacity has the same data as the selected one
        // If the data is the same, remove the next transport capacity from the sorted set and dataset
        if( head.HasSameData( nexttc ) )
        {
          sortedtcs.Remove( nexttc );
          nexttc.Delete();
        }
        // Else, set the next transport capacity as the selected one
        else
        {
          head := nexttc;
        }
      }
    
    }
  *]
}