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
Quintiq file version 2.0
#parent: #root
Method GetHasCycle (
  ProductInStockingPointInPeriod targetpispip,
  output Process_MPs processes_o,
  Number currentdepth,
  Number maxdepth
) remote as Boolean
{
  Description:
  [*
    Return false if there are a set of processes form a cycle for this pispip, and returns the paths (processes) which form the cycle.
    Used to check pegging circularity
  *]
  TextBody:
  [*
    // soh yee Aug-14-2014 (created)
    
    foundtarget := false;
    currentdepth := currentdepth + 1;
    
    // Start with the dependent demands of all the new supplies. If the targetpispip is found again when performing the depth first search,
    // it means that a cycle is found
    if( currentdepth <= maxdepth )
    {
      traverse( this, NewSupply.PeriodTask_MP.DependentDemand, dd,
                not foundtarget           // Stop the search once a cycle is found, or the foundtarget Boolean will be resetted
                and not dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Product_MP().IsByProduct() )
      {
        pispip := dd.ProductInStockingPointInPeriodPlanningLeaf();
    
        foundtarget := pispip = targetpispip
                       or pispip.GetHasCycle( targetpispip, processes_o, currentdepth, maxdepth );
    
        // Save the period task if a cycle is found for the search branch
        if( foundtarget )
        {
          processes_o.Add( dd.PeriodTask_MP().Process_MP() );
        }
      }
    }
    
    return foundtarget;
  *]
}