public void closureOneByOne(FcaMatrix matrix, FcaTree tree) { FcaObject nextObject = new FcaObject(); FcaTree node; do { do { nextObject = matrix.getElemById(tree.getNextId() + 1); if (nextObject != null) { FcaObjectSet q = new FcaObjectSet(); q = tree.getMainSet().clone(); q.closure(nextObject, matrix); FcaObjectSet dif =q.difference(tree.getMainSet()); if (dif.minObject() == nextObject) { node = new FcaTree(); node.setMainSet(q); listOfSets.Add(q); node.setNextId(q.maxObject().getId()); node.setParent(tree); tree.addDescendant(node); listOfNodes.Add(node); closureOneByOne(matrix, node); tree.setNextId(nextObject.getId()); } else { tree.setNextId(nextObject.getId()); } } } while (nextObject != null); if (tree.getParent() != null) tree = tree.getParent(); } while ((tree.getParent() != null) && (nextObject != null)); }
/// <summary> /// Список соседей в решетке /// </summary> /// <param name="A"> узел решетки</param> /// <param name="G"> универсальное множество, в котором содержается все понятия</param> /// <returns></returns> private List<FcaObjectSet> minimal(FcaObjectSet A, FcaObjectSet G, FcaMatrix matrix) { List<FcaObjectSet> resultSet = new List<FcaObjectSet>(); FcaObjectSet subtr = G.difference(A); // находим разниу между множествами List<FcaObject> iterableSet = subtr.getObjects(); foreach (FcaObject obj in iterableSet) { FcaObjectSet B = new FcaObjectSet(); B = A.clone(); B.closure(obj, matrix); resultSet.Add(B); } // найдем минимальные из порожденных множеств List<FcaObjectSet> minSet = new List<FcaObjectSet>(); if (resultSet.Count != 0) { int minCount = resultSet[0].count(); foreach (FcaObjectSet obj in resultSet) { if (obj.count() < minCount) { minSet.Clear(); minCount = obj.count(); minSet.Add(obj); } else if (obj.count() == minCount) { minSet.Add(obj); } } //foreach (FcaObjectSet obj in minSet) //{ // if ((AllSets == null) || (!AllSets.Contains(obj))) // AllSets.Add(obj); //} } return minSet; }