} // GetNodeToDrop static List <int> MakeOneMissing(MaxCliqueGraph graph, List <int> clique) { int count; List <int> result = new List <int>(); for (int i = 0; i < graph.NumberNodes; ++i) { if (graph.NumberNeighbors(i) < clique.Count - 1) { continue; } if (clique.BinarySearch(i) >= 0) { continue; } count = 0; for (int j = 0; j < clique.Count; ++j) { if (graph.AreAdjacent(i, clique[j])) { ++count; } } if (count == clique.Count - 1) { result.Add(i); } } return(result); }
static void Main(string[] args) { try { Console.WriteLine("\nBegin greedy maximum clique demo\n"); Console.WriteLine("\nBegin tabu algorithm maximum clique demo\n"); string graphFile = "..\\..\\DimacsGraph.clq"; //string graphFile = "DimacsGraph.clq"; MaxCliqueGraph.ValidateGraphFile(graphFile, FileFormat.DIMACS); //"DIMACS" MaxCliqueGraph graph = new MaxCliqueGraph(graphFile, FileFormat.DIMACS); graph.ValidateGraph(); Console.WriteLine("Loading graph into memory"); Console.WriteLine("Graph loaded and validated\n"); int maxTime = 50; // В настоящей задаче о максимальной клике maxTime обычно находится в диапазоне от 1000 до 100 000. int targetCliqueSize = graph.NumberNodes; List <int> maxClique = FindMaxClique(graph, maxTime, targetCliqueSize); Console.WriteLine("\nMaximum time reached"); Console.WriteLine("\nSize of best clique found = " + maxClique.Count); Console.WriteLine("\nBest clique found:"); Console.WriteLine(ListAsString(maxClique)); Console.WriteLine("\nEnd greedy maximum clique demo\n"); Console.WriteLine(graph.ToString()); Console.WriteLine("\nAre nodes 5 and 8 adjacent? " + graph.AreAdjacent(5, 8)); Console.WriteLine("Number neighbors of node 4 = " + graph.NumberNeighbors(4)); WriteFile(ListAsString(maxClique), "output.txt"); string outputGraphFile = "..\\..\\output.txt"; graph.SaveTxtFormatGraph(outputGraphFile); } catch (Exception ex) { Console.WriteLine("Fatal: " + ex.Message); } } // Main