static void Main(string[] args) { string parametersUsage = " <alg_opt>:\n\t0: accurate McGregor algorithm: vertices criterion\n\t1: accurate McGregor algorithm: sum of vertices and edges criterion\n\t2: approximate algorithm based on finding maximal clique in a modular product of two input graphs\n\t3: approximate algorithm based on merging cliques created from input graphs"; if (args.Length == 0 || args.Length != 3) { Console.WriteLine("Usage:"); Console.WriteLine("dotnet run <alg_opt> <g1> <g2>"); Console.WriteLine(parametersUsage); Console.WriteLine(" <g1>:"); Console.WriteLine("\t name of G1"); Console.WriteLine(" <g2>:"); Console.WriteLine("\t name of G2"); return; } int algorithmFlag; try { algorithmFlag = Convert.ToInt32(args[0]); } catch { Console.WriteLine(parametersUsage); return; } IAlgorithm alg; var g1Path = Environment.CurrentDirectory + "\\Graphs\\" + args[1]; var g2Path = Environment.CurrentDirectory + "\\Graphs\\" + args[2]; string title; string criterion; string description; switch (algorithmFlag) { case 0: alg = new McGregorAlgorithm(true); title = "******ACCURATE ALGORITHM********"; criterion = "Criterion: number of vertices."; description = "McGregor's algorithm."; break; case 1: alg = new McGregorAlgorithm(false); title = "******ACCURATE ALGORITHM********"; criterion = "Criterion: sum of vertices and edges."; description = "McGregor's algorithm."; break; case 2: alg = new ModularGraphMaxCliqueAlgorithm(); title = "******APPROXIMATE ALGORITHM******"; criterion = "Criterion: number of vertices."; description = "Description: algorithm finding the maximal clique in a modular product of input graphs"; break; case 3: alg = new LinkingCliquesAlgorithm(); title = "******APPROXIMATE ALGORITHM******"; criterion = "Criterion: number of vertices."; description = "Description: algorithm finding the maximal clique in a modular product of input graphs"; break; default: Console.WriteLine(parametersUsage); return; } Console.WriteLine(); Console.WriteLine(title); Console.WriteLine(criterion); Console.WriteLine(description); Console.WriteLine(); int[] g1Mapping; int[] g2Mapping; (g1Mapping, g2Mapping) = alg.GetMaximalCommonSubgraphMapping(g1Path, g2Path); Console.WriteLine("******RESULTS******"); Console.Write("G1:"); for (int i = 0; i < g1Mapping.Length; i++) { Console.Write(" " + g1Mapping[i]); } Console.WriteLine(); Console.Write("G2:"); for (int i = 0; i < g1Mapping.Length; i++) { Console.Write(" " + g2Mapping[i]); } }
public void GetGraphCliques(Graph g, List <List <int> > cliques) { int[,] graphData = (int[, ])g.GraphData.Clone(); Graph gCp = new Graph(g.GraphData); List <int> clique; int sizeToDelete = 0; List <int> vertices = new List <int>(); while (gCp.AnyEdgesLeft()) { mgAlg = new ModularGraphMaxCliqueAlgorithm(); mgAlg.MaxCliquePolynomial(gCp, true); clique = new List <int>(); // issue when we dissolve the graph if (mgAlg._maxCP.Count == 0) { break; } for (int i = 0; i < mgAlg._maxCP.Count; i++) { clique.Add(mgAlg._maxCP[i]); vertices.Add(mgAlg._maxCP[i]); } sizeToDelete += clique.Count; cliques.Add(clique); for (int i = 0; i < mgAlg._maxCP.Count; i++) { for (int j = 0; j < g.GraphData.GetLength(0); j++) { graphData[mgAlg._maxCP[i], j] = 0; } } for (int i = 0; i < g.GraphData.GetLength(0); i++) { for (int j = 0; j < mgAlg._maxCP.Count; j++) { graphData[i, mgAlg._maxCP[j]] = 0; } } gCp = new Graph((int[, ])graphData.Clone()); gCp.Size -= sizeToDelete; } vertices.Sort((a, b) => a.CompareTo(b)); // for single vertices if (vertices.Count != g.GraphData.GetLength(0)) { for (int i = 0; i < g.GraphData.GetLength(0); i++) { if (!vertices.Contains(i)) { cliques.Add(new List <int> { i }); } } } }