List <int[]> FindCycleAccrossCut(CutFrontier inputCutFr, bool asyn) { if (inputCutFr.frontier.fromReg1ToReg2.Count < 1 || inputCutFr.frontier.fromReg2ToReg1.Count < 1) { return(null); } List <int[]> cycle = new List <int[]>(); if (asyn) { foreach (var point in inputCutFr.frontier.fromReg2ToReg1) { cycle.Add((int[])point.Clone()); var res = FindSoftAsyncCycle(point, ref cycle); if (res.Count > 0) { return(res); } } } foreach (var point in inputCutFr.frontier.fromReg1ToReg2) { var firstState = (int[])point.Clone(); var oldState = (int[])point.Clone(); var state = (int[])point.Clone(); cycle = new List <int[]>(); while (InRegion(state)) { cycle.Add((int[])state.Clone()); for (int i = 0; i < dim; i++) { state[i] = updateFunctions[i](new List <int>(oldState), oldState[i]); } oldState = (int[])state.Clone(); bool back = true; for (int i = 0; i < dim; i++) { if (state[i] != firstState[i]) { back = false; break; } } if (back) { return(cycle); } } if (cycle.Count > 0) { break; } } return(cycle); }
List <int[]> FindInstability(Region inputReg) { inputReg = Shrink(inputReg); if (ContainsSingleState(inputReg)) { return(null); } else { CutFrontier afterCut = Cut(inputReg, mode == Mode.ASYNC); List <int[]> res1 = FindInstability(afterCut.p1); if (res1 != null) { return(res1); } List <int[]> res2 = FindInstability(afterCut.p2); if (res2 != null) { return(res2); } return(FindCycleAccrossCut(afterCut, mode == Mode.ASYNC)); } }
CutFrontier Cut(Region p, bool asyn) { CutFrontier res = new CutFrontier(); res.p1 = new Region(); res.p1.lowPoint = (int[])p.lowPoint.Clone(); res.p2 = new Region(); res.p2.highPoint = (int[])p.highPoint.Clone(); int index = 0; for (int i = 0; i < dim; i++) { if (p.highPoint[i] - p.lowPoint[i] > p.highPoint[index] - p.lowPoint[index]) { index = i; } } int alpha = (p.highPoint[index] - p.lowPoint[index]) / 2; res.p1.highPoint = (int[])p.highPoint.Clone(); res.p1.highPoint[index] = alpha; res.p2.lowPoint = (int[])p.lowPoint.Clone(); res.p2.lowPoint[index] = alpha + 1; res.frontier = new Frontier(); res.frontier.fromReg1ToReg2 = new List <int[]>(); res.frontier.fromReg2ToReg1 = new List <int[]>(); int amount = 1; for (int i = 0; i < dim; i++) { if (i == index) { continue; } amount *= p.highPoint[i] - p.lowPoint[i] + 1; } var point = new int[dim]; for (int j = 0; j < amount; j++) { int count = j; for (int i = dim - 1; i >= 0; i--) { if (i == index) { point[i] = alpha; } point[i] = count % (res.p1.highPoint[i] - res.p1.lowPoint[i] + 1) + res.p1.lowPoint[i]; count = count / (res.p1.highPoint[i] - res.p1.lowPoint[i] + 1); } if (updateFunctions[index](new List <int>(point), point[index]) > alpha) { res.frontier.fromReg1ToReg2.Add((int[])point.Clone()); } point[index] = alpha + 1; if (updateFunctions[index](new List <int>(point), point[index]) < alpha + 1) { res.frontier.fromReg2ToReg1.Add((int[])point.Clone()); } } return(res); }