static void Main(string[] args) { Graph g = new Graph(new StreamReader(Console.OpenStandardInput())); ISolver solver = new HybridSolver(); OptionSet os = new OptionSet() { { "s=", "Solver to use", solverName => { switch (solverName) { case "greedy": solver = new GreedySolver(); break; case "cp": solver = new ConstraintSolver(); break; } } } }; os.Parse(args); Coloring coloring = solver.Solve(g); coloring.Output(new StreamWriter(Console.OpenStandardOutput())); }
public Coloring Solve(Graph g) { Coloring bestColoring = new GreedySolver().Solve(g); this.Cliques = new CliqueFinder(g).FindMaximalCliques(); //int maxCliqueSize = this.Cliques.Max(c => c.Length); //Debug.WriteLine("Cliques found"); while (true) { //Debug.WriteLine(bestColoring.ColorCount); /*if (bestColoring.ColorCount == maxCliqueSize) * { * bestColoring.IsOptimal = true; * break; * }*/ var task = Task.Factory.StartNew(() => this.FindColoring(g, bestColoring.ColorCount - 1)); if (!task.Wait(TimeLimit)) { break; } int[] coloring = task.Result; if (coloring == null) { bestColoring.IsOptimal = true; break; } bestColoring = new Coloring(coloring, false); } return(bestColoring); }