public FcaTree() { descendants = new List<FcaTree>(); parent = null; mainSet = new FcaObjectSet(); nextId = -1; listOfNodes = new List<FcaTree>(); listOfSets = new List<FcaObjectSet>(); }
private void button1_Click(object sender, EventArgs e) { FcaMatrix matrix = new FcaMatrix(); FileScanner fscan = new FileScanner(); String[] processingFiles = Directory.GetFiles(txtSourceDir.Text); matrix = fscan.processFiles(processingFiles); FcaTree tree = new FcaTree(); tree.closureOneByOne(matrix,tree); FcaObjectSet lattice = new FcaObjectSet(); lattice.buildLattice(tree, matrix); fscan.RefactorHierarchy(lattice); }
public FcaTree findInList(FcaObjectSet set) { FcaTree tr = new FcaTree(); foreach (FcaTree t in listOfNodes) { if (t.getMainSet().Equals(set)) { tr = t; break; } } //while ((tree.parent != null) && (!flag)) //{ // foreach (FcaTree node in tree.descendants) // { // FcaObjectSet s = node.getMainSet(); // int l = set.count(); // int i; // bool t = true; // for (i = 0; (i < l) && (t); i++) // { // if (!node.getMainSet().getObjects().Contains(set.getObjects()[i])) // t = false; // } // if ((i == l) && (t)) // { // flag = true; // tree = node; // } // //else // //{ // // tree = node; // // break; // //} // } //} return tr; }
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)); }
private int VisitedContains(FcaObjectSet obj) { int i; int l = Visited.Count; for (i = 0; i < l; i++) { if (Visited[i].Equals(obj)) return i; } return -1; }
/// <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; }
private int AllSetsContains(FcaObjectSet obj) { int i; int l = AllSets.Count; for (i = 0; i < l; i++) { if (AllSets[i].Equals(obj)) return i; } return -1; }
private void addVisited(FcaObjectSet obj) { if (VisitedContains(obj) == -1) Visited.Add(obj); }
private void addASupr(FcaObjectSet obj) { int i = -1; int l = ASupr.Count; for (int j = 0; j < l; j++) { if (ASupr[j].Equals(obj)) { i = j; break; } } if (i == -1) ASupr.Add(obj); }
private void addAllSets(FcaObjectSet obj) { if (!AllSets.Contains(obj)) AllSets.Add(obj); }
public void Remove(FcaObjectSet obj) { List<FcaObjectSet> list = AllSets.ToList<FcaObjectSet>(); foreach (FcaObjectSet s in list) { if (this.equalLists(s.getObjects(), obj.getObjects())) { AllSets.Remove(s); } } }
public bool Equals(FcaObjectSet set) { List<FcaObject> list1 = set.getObjects(); List<FcaObject> listMain = this.getObjects(); bool flag = true; int len = listMain.Count; if (len == list1.Count) { int i; for (i = 0; (i < len) && flag; i++) { if (!listMain.Contains(list1[i])) flag = false; } //if ((i >= len) && flag) // flag = true; } else { flag = false; } return flag; }
/// <summary> /// Разность множеств. /// </summary> /// <param name="set">вычитаемое множество</param> /// <returns>результат вычитания</returns> public FcaObjectSet difference(FcaObjectSet set) { FcaObjectSet difSet = new FcaObjectSet(); List<FcaObject> objs = set.getObjects(); foreach (FcaObject elem in this.objects) { if (set.findElemById(elem.getId()) == -1) difSet.addObject(elem); } return difSet; }
/// <summary> /// Клонирует множество. /// </summary> /// <returns>Клон исходного множества.</returns> public FcaObjectSet clone() { FcaObjectSet newSet = new FcaObjectSet(); foreach(FcaObject elem in this.objects) newSet.addObject(elem); return newSet; }
public void buildLattice(FcaTree tree, FcaMatrix matrix) { FcaObjectSet A = new FcaObjectSet(); FcaObjectSet G = matrix.UltimateSet(); List<FcaObjectSet> sup = minimal(A, G, matrix); // множесво всех возможных соседей в решетке head = A; AllSets = tree.returnListOfSets(tree); int i = AllSetsContains(G); if (i == -1) { addAllSets(G); i = AllSetsContains(G); } tail = AllSets[i]; foreach (FcaObjectSet obj in sup) { i = AllSetsContains(obj); FcaObjectSet existObject = AllSets[i]; A.addASupr(existObject); existObject.addAInf(A); addVisited(existObject); } // найти связь между 1 и 123. while (Visited.Count != 0) { List<FcaObjectSet> list = Visited.ToList<FcaObjectSet>(); foreach (FcaObjectSet s in list) { sup = minimal(s, G, matrix); // множесво всех возможных соседей в решетке Visited.Remove(s); foreach (FcaObjectSet obj in sup) { i = AllSetsContains(obj); if (i == -1) { addAllSets(obj); i = AllSetsContains(obj); } FcaObjectSet existObject = AllSets[i]; s.addASupr(existObject); existObject.addAInf(s); addVisited(existObject); } } } foreach (FcaObjectSet set in AllSets) { FcaObjectSet check = new FcaObjectSet(); foreach (FcaObjectSet l in set.AInf) { foreach (FcaObject o in l.getObjects()) { check.addObject(o); } } if (!set.Equals(check)) { i = AllSetsContains(set); set.addAInf(tree.findInList(set).getParent().getMainSet()); } } }
private void addAInf(FcaObjectSet obj) { int i = -1; int l = AInf.Count; for (int j = 0; j < l; j++) { if (AInf[j].Equals(obj)) { i = j; break; } } if (i == -1) AInf.Add(obj); }
public FcaObjectSet UltimateSet() { FcaObjectSet set = new FcaObjectSet(); foreach (FcaObject obj in objects) { set.addObject(obj); } return set; }
public void setMainSet(FcaObjectSet q) { this.mainSet = q; }