private void OnSolveSelectedProblem() { string[] sourceFiles = SourceFile.Split(';'); StateText = string.Format("Testing {0} problem on {1} compiler", ProblemSet.SelectedProblem.Name, SelectedCompiler.Name); State = MainWindowStatus.Running; ProblemSpecification ps = ProblemSet.SelectedProblem.ProblemSpecification; Compiler c = SelectedCompiler; var t = Task.Factory.StartNew(() => tester.TestFiles(sourceFiles, ps, c)); t.ContinueWith((task) => { if (t.IsFaulted) { Dispatcher.BeginInvoke((Action)(() => { StateText = string.Format("Error while testing problem {0}: {1}", ProblemSet.SelectedProblem.Name, t.Exception.Message); State = MainWindowStatus.Error; })); } else { Dispatcher.BeginInvoke((Action)(() => { ProblemSet.SelectedProblem.SetSolution(t.Result); StateText = string.Format("Problem {0} tested", ProblemSet.SelectedProblem.Name); State = MainWindowStatus.Ready; })); } }); }
static void Main(string[] args) { var blue = new Color("B", new[] { 10, 20, 100, 200 }, new Interval(0, 0)); var red = new Color("R", new[] { 50, 105, 150 }, new Interval(0, 20)); var green = new Color("G", new[] { 80, 110, 250 }, new Interval(0, 25)); var yellow = new Color("Y", new[] { 42, 62, 82, 102, 122, 142, 162 }, new Interval(0, 25)); var spec = new ProblemSpecification(new[] { blue, red, green, yellow }, 0.5); var groups = ProblemSolver.NaiveSolver(spec); Console.WriteLine("*** Color Group Finder ***"); Console.WriteLine(); Console.WriteLine("The colors:"); Console.WriteLine("Blue: {0}", String.Join(", ", blue.Points)); Console.WriteLine("Red: {0}", String.Join(", ", red.Points)); Console.WriteLine("Green: {0}", String.Join(", ", green.Points)); Console.WriteLine("Yellow: {0}", String.Join(", ", yellow.Points)); Console.WriteLine(); Console.WriteLine("The distances:"); Console.WriteLine("Before red: {0}", red.Distance); Console.WriteLine("Before green: {0}", green.Distance); Console.WriteLine("Before yellow: {0}", yellow.Distance); Console.WriteLine(); Console.WriteLine("{0} colors may be skipped.", spec.Colors.Count - ProblemSolver.MinimalNumberOfColors(spec.Colors.Count, spec.Fraction)); Console.WriteLine(); Console.WriteLine("The groups:"); foreach (var group in groups) { Console.WriteLine(String.Join(", ", group.Elements)); } }