public GraphAnalyzer(Graph graph, PatternMap patterns = null) { this.graph = graph; matrix = AdjacencyMatrix.FromGraph(graph); invariants = matrix.GetInvariantGroups(); KnownPatterns = patterns ?? new PatternMap(matrix); if (patterns != null) { KnownPatterns.ClearInstances(); } filterer = new PatternFilterer(KnownPatterns); selector = new PatternSelector(KnownPatterns); }
/// <summary> /// Группирует связные подграфы по инвариантам. /// </summary> internal InvariantMap GetInvariantGroups() { var cache = new MinorCache(this); var invariantMap = new InvariantMap(this); //Находим миноры размера 2 for (int i = 0; i < Vertices; i++) { for (int j = 0; j < Vertices; j++) { if (i == j) { continue; } int det = Matrix[i, i] * Matrix[j, j] - Matrix[i, j] * Matrix[j, i]; cache[i, j] = det; } } //Находим остальные миноры рекурсивно for (int n = 3; n <= Vertices; n++) { var minors = MinorsOfSize(n); foreach (var minor in minors) { int det = 0; for (int i = 0; i < minor.Length; i++) { int sign = i % 2 == 0 ? 1 : -1; int[] lesserMinor = minor.SkipIndex(i); det += this[minor[i], minor[0]] * cache[lesserMinor] * sign; } cache[minor] = det; if (MinorIsConnected(minor)) { invariantMap.Add(minor, det); } } } return(invariantMap); }
public Invariant(InvariantMap <X, CX, Y, CY> imap) => this._imap = imap;