private List <int[]> CalcVertexIndex(int vertex, List <int> vertices, int[][] graphNumeration) { List <int[]> alts = new List <int[]>(); var localDirection = new T(); int v_0 = vertices[0]; while (localDirection.Valid()) { var offset = localDirection.GetNextOffset(); var alternative = new int[offset.Count()]; for (int i = 0; i < alternative.Count(); ++i) { alternative[i] = graphNumeration[v_0][i] + offset[i]; } int altCount = 0; if (!NumerationHelper.IndexExists(alternative, graphNumeration)) { foreach (var v in vertices) { if (NumerationHelper.CompareVertex(graphNumeration[v], alternative, alternative.Count()) >= 0) { ++altCount; } } if (altCount == vertices.Count()) { alts.Add(alternative); } } } return(alts.Count() == 0 ? null : alts); }
public virtual Error TryToNumerate(int[][] graphNumeration) { if (!direction.Valid()) { return(Error.IMPOSSIBLE_NUM); } var vertices = GetNumeratedAdjVertices(graphNumeration); if (vertices.Count == 0) { return(Error.NEED_MORE_DATA); } if (vertices.Count() > 1) { var alts = CalcVertexIndex(vertex, vertices, graphNumeration); if (alts != null) { foreach (var alternative in alts) { if (!ContainsAlternative(alternative)) { graphNumeration[vertex] = alternative; alternatives.Add(alternative); return(Error.OK); } } } return(Error.IMPOSSIBLE_NUM); } int[] index = null; bool newIndexFound = false; if (graphNumeration[vertices[0]] != null) { while (!newIndexFound && direction.Valid()) { var offset = direction.GetNextOffset(); index = new int[offset.Count()]; for (int i = 0; i < offset.Count(); ++i) { index[i] = graphNumeration[vertices[0]][i] + offset[i]; } newIndexFound = !NumerationHelper.IndexExists(index, graphNumeration); if (newIndexFound) { graphNumeration[vertex] = index; if (!ContainsAlternative(index)) { alternatives.Add(index); } } } } return(newIndexFound ? Error.OK : Error.IMPOSSIBLE_NUM); }