From f3f71765f075f02aa57d6b1180b76f015b1d40af Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Fri, 24 May 2019 00:41:54 +0200 Subject: [PATCH] final changes --- TMI-practicum/Program.cs | 44 +++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/TMI-practicum/Program.cs b/TMI-practicum/Program.cs index 3cbea4e..cf5511c 100644 --- a/TMI-practicum/Program.cs +++ b/TMI-practicum/Program.cs @@ -10,24 +10,26 @@ namespace TMI_practicum { public static void Main(string[] args) { - //CheckAlgo(); - GetChartData(); - if (args.Length < 1) + if (args.Length == 0 && !File.Exists("input.txt")) { Console.WriteLine("Please enter a file."); Environment.Exit(1); } - if (!File.Exists(args[0])) + var inputFile = "input.txt"; + if (args.Length != 0) inputFile = args[0]; + + if (!File.Exists(inputFile)) { - Console.WriteLine("File {0} not found.", args[0]); + Console.WriteLine("File {0} not found.", inputFile); Environment.Exit(1); } - var (algorithm, _, circles) = ParseFile(args[0]); + + (byte algorithm, _, IList circles) = ParseFile(inputFile); - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); IEnumerable solved; stopwatch.Start(); @@ -44,6 +46,16 @@ namespace TMI_practicum solved = SweepLineEffAlgorithm.Solve(circles); break; default: + if (File.Exists(OutputFile)) + { + File.Delete(OutputFile); + } + + using (StreamWriter sw = File.CreateText(OutputFile)) + { + sw.WriteLine("Dit algoritme is niet ge ̈ımplementeerd."); + } + throw new ArgumentException("Algorithm with id: " + algorithm + " is not defined!"); } @@ -64,7 +76,7 @@ namespace TMI_practicum var correctSol = SweepLineAlgorithm.Solve(circles); var solved = SweepLineEffAlgorithm.Solve(circles); - + foreach (var intersection in correctSol) { if (solved.Contains(intersection)) continue; @@ -79,12 +91,13 @@ namespace TMI_practicum solved.Contains(new Intersection(intersection.X, intersection.Y - 1e-15)) ) continue; - bool found = solved.Any(ints => Math.Abs(ints.X - intersection.X) < 1e-12 && Math.Abs(ints.Y - intersection.Y) < 1e-12); + bool found = solved.Any(ints => + Math.Abs(ints.X - intersection.X) < 1e-12 && Math.Abs(ints.Y - intersection.Y) < 1e-12); if (found) continue; Console.WriteLine(InCircles(circles)); - + failed = true; Console.WriteLine("Not found: {0}\t{1}", intersection.X, intersection.Y); Console.WriteLine("correct"); @@ -92,6 +105,7 @@ namespace TMI_practicum { Console.WriteLine("{0}\t{1}", intersection1.X, intersection1.Y); } + Console.WriteLine("wrong"); foreach (var intersection1 in solved) { @@ -108,9 +122,9 @@ namespace TMI_practicum { Console.WriteLine("{0} {1} {2}", circle.X, circle.Y, circle.R); } + break; } - } } @@ -122,7 +136,7 @@ namespace TMI_practicum for (int i = 0; i < amount; i++) { circles.Add(new Circle(Math.Round(rnd.NextDouble() * 1.0, 15), Math.Round(rnd.NextDouble() * 1.0, 15), - Math.Round(rnd.NextDouble() * (1.0/amount), 15))); + Math.Round(rnd.NextDouble() * (1.0 / amount), 15))); } return circles; @@ -175,7 +189,9 @@ namespace TMI_practicum int i = 0; while ((line = file.ReadLine()) != null) { - double[] parts = line.Split(' ').Select(double.Parse).ToArray(); + double[] parts = line.Split(' ').Where(x => x.Length != 0).Select(double.Parse).ToArray(); + if (parts.Length == 0) continue; + circles[i++] = new Circle(parts[0], parts[1], parts[2]); } } @@ -201,7 +217,7 @@ namespace TMI_practicum using (StreamWriter sw = File.CreateText(OutputFile)) { - foreach (var intersection in intersections) + foreach (Intersection intersection in intersections) { sw.WriteLine("{0:0.000000000000000}\t{1:0.000000000000000}", intersection.X, intersection.Y); }