/** Use example for DGraph and DAGraph classes * */ public static void ExampleDGraph() { try { String name = "DGraph"; // create the directory to save files File f = new File(outputDir + name); f.mkdir(); // create the Readme file name = name + File.separator + name; BufferedWriter file = new BufferedWriter(new FileWriter(outputDir + name + "Readme.txt")); String log = "EXAMPLE FOR DGRAPH AND DAGRAPH CLASSES\n"; log += "--------------------------------------\n"; System.out.println(log); file.write(log); // randomly generates a directed graph of 5 nodes DGraph G = DGraph.random(10); String nameGraph = name + ".dot"; G.save(outputDir + nameGraph); log = "-> Randomly generated DGraph saved in " + nameGraph + "\n"; System.out.println(log + G.toString()); file.write(log); // compute the complementary graph G.complementary(); String nameComp = name + "Complementary.dot"; G.save(outputDir + nameComp); log = "-> Complementary graph saved in " + nameComp + "\n "; System.out.println(log + G.toString()); // check if the dgraph is acyclic log = "-> DGraph acyclic? " + G.isAcyclic() + "\n"; System.out.println(log); file.write(log); // computes and print the transitive closure of the dgraph G.transitiveClosure(); String nameTransClosure = name + "TransitiveClosure.dot"; G.save(outputDir + nameTransClosure); log = "-> Transitive closure saved in " + nameTransClosure + "\n"; System.out.println(log + G.toString()); file.write(log); // computes and print a depth first search in the directed graph ArrayList[] S = G.depthFirstSearch(); log = "-> Depth first search (first visited nodes): " + S[0] + "\n"; log += "Depth first search (last visited nodes): " + S[1] + "\n"; System.out.println(log); file.write(log); // computes and print the directed acyclic graph whose nodes // are strongly connected components of the directed graph DAGraph CC = G.getStronglyConnectedComponent(); String nameCC = name + "ConnectedComponents.dot"; CC.save(outputDir + nameCC); log = "-> Strongly connected components saved in " + nameCC + "\n"; System.out.println(log + CC.toString()); file.write(log); // verify that the dagraph is acyclic log = nameCC + " acyclic? " + CC.isAcyclic() + "\n"; System.out.println(log); file.write(log); // computes and print the sugbraph of the dgraph induces by 5 first nodes TreeSet<Node> X = new TreeSet(); for (Node n : G.getNodes()) if (X.size() != 5) X.add(n); DGraph SG = G.getSubgraphByNodes(X); String nameSG = name + "Subgraph.dot"; SG.save(outputDir + nameSG); log = "-> Subgraph induced by 5 first nodes saved in " + nameSG + "\n"; System.out.println(log + SG.toString()); file.write(log); file.close(); } catch (Exception e) { } }
/** Use example for DAGraph and Lattice classes * */ public static void ExampleDAGraph() { try { String name = "DAGraph"; // create the directory to save files File f = new File(outputDir + name); f.mkdir(); // create the Readme file name = name + File.separator + name; BufferedWriter file = new BufferedWriter(new FileWriter(outputDir + name + "Readme.txt")); String log = "EXAMPLE FOR DAGRAPH AND LATTICE CLASSES\n"; log += "-----------------------------------------\n"; System.out.println(log); file.write(log); // randomly generates a directed graph of 10 nodes DAGraph G = DAGraph.random(10); String nameGraph = name + ".dot"; G.save(outputDir + nameGraph); log = "-> Randomly generated DAGraph saved in " + nameGraph + "\n"; System.out.println(log + G.toString()); file.write(log); // verify if the dagraph is acyclic log = nameGraph + " acyclic? " + G.isAcyclic() + "\n"; System.out.println(log); file.write(log); // computes and print the transitive reduction of the dagraph G.transitiveReduction(); String nameTR = name + "TransitiveReduction.dot"; G.save(outputDir + nameTR); log = "-> Transitive reduction saved in " + nameTR + "\n"; System.out.println(log + G.toString()); file.write(log); // computes and print the ideal and the filter of the first node Node n = G.getNodes().first(); DAGraph ideal = G.ideal(n); String nameIdeal = name + "Ideal.dot"; ideal.save(outputDir + nameIdeal); log = "-> Minorants of " + n + " : " + G.minorants(n) + "\n saved as a dagraph in " + nameIdeal + "\n"; System.out.println(log); file.write(log); DAGraph filter = G.filter(n); String nameFilter = name + "Filter.dot"; filter.save(outputDir + nameFilter); log = "-> Majorants of " + n + " : " + G.majorants(n) + "\n saved as a dagraph in " + nameFilter + "\n"; System.out.println(log); file.write(log); // computes and print the ideals lattice of the dagraph ConceptLattice CSL = ConceptLattice.idealLattice(G); String nameIdealsLattice = name + "IdealsLattice.dot"; CSL.save(outputDir + nameIdealsLattice); log = "-> Ideal lattice saved in " + nameIdealsLattice + "\n"; System.out.println(log + CSL.toString()); file.write(log); // check if the ideals lattice is a lattice log = "-> Check if the ideal lattice is a lattice ? " + CSL.isLattice() + "\n"; System.out.println(log); file.write(log); // print the irreducibles elements of the ideal lattice log = "-> Join irreducibles of ideal lattice: " + CSL.joinIrreducibles() + "\n"; log += "Meet irreducibles of ideal lattice: " + CSL.meetIrreducibles() + "\n"; System.out.println(log); file.write(log); // reduces the ideal lattice by replacing each join irreducible node by one element Lattice L = CSL.getJoinReduction(); String nameReducedLattice = name + "ReducedLattice.dot"; L.save(outputDir + nameReducedLattice); log = "-> Reduced ideal lattice saved in " + nameReducedLattice + "\n"; System.out.println(log + L.toString()); file.write(log); // print the irreducibles elements of the reduces ideal lattice log = "-> Join irreducibles of reduced ideal lattice: " + L.joinIrreducibles() + "\n"; log += "Meet irreducibles of reduced ideal lattice: " + L.meetIrreducibles() + "\n"; System.out.println(log); file.write(log); // computes the table of the reduced lattice Context T = L.getTable(); String nameTable = name + "IrrTable.txt"; T.save(outputDir + nameTable); log = "-> Irreducibles table of the reduced ideal lattice saved in " + nameTable + ":\n " + T.toString(); System.out.println(log); file.write(log); // compute the subgraph of join irreducible nodes DAGraph JIrr = L.joinIrreduciblesSubgraph(); String nameIrrSG = name + "IrrSubgraph.dot"; JIrr.save(outputDir + nameIrrSG); log = "-> Join irreducibles subgraph saved in " + nameIrrSG + "\n"; System.out.println(log + JIrr.toString()); file.write(log); // BIJECTION log = "--- BIJECTION --- \n"; log += "Initial random DAGraph (" + nameGraph + ") isomorphic to\n"; log += "Join irreducible subgraph of its ideal lattice (" + nameIrrSG + ")\n"; System.out.println(log); file.write(log); file.close(); } catch (Exception e) { } }