1
0

final changes

This commit is contained in:
2019-05-24 00:41:54 +02:00
parent 2366308ae1
commit f3f71765f0

View File

@@ -10,24 +10,26 @@ namespace TMI_practicum
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
//CheckAlgo(); if (args.Length == 0 && !File.Exists("input.txt"))
GetChartData();
if (args.Length < 1)
{ {
Console.WriteLine("Please enter a file."); Console.WriteLine("Please enter a file.");
Environment.Exit(1); 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); Environment.Exit(1);
} }
var (algorithm, _, circles) = ParseFile(args[0]);
(byte algorithm, _, IList<Circle> circles) = ParseFile(inputFile);
Stopwatch stopwatch = new Stopwatch(); var stopwatch = new Stopwatch();
IEnumerable<Intersection> solved; IEnumerable<Intersection> solved;
stopwatch.Start(); stopwatch.Start();
@@ -44,6 +46,16 @@ namespace TMI_practicum
solved = SweepLineEffAlgorithm.Solve(circles); solved = SweepLineEffAlgorithm.Solve(circles);
break; break;
default: 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!"); throw new ArgumentException("Algorithm with id: " + algorithm + " is not defined!");
} }
@@ -64,7 +76,7 @@ namespace TMI_practicum
var correctSol = SweepLineAlgorithm.Solve(circles); var correctSol = SweepLineAlgorithm.Solve(circles);
var solved = SweepLineEffAlgorithm.Solve(circles); var solved = SweepLineEffAlgorithm.Solve(circles);
foreach (var intersection in correctSol) foreach (var intersection in correctSol)
{ {
if (solved.Contains(intersection)) continue; if (solved.Contains(intersection)) continue;
@@ -79,12 +91,13 @@ namespace TMI_practicum
solved.Contains(new Intersection(intersection.X, intersection.Y - 1e-15)) solved.Contains(new Intersection(intersection.X, intersection.Y - 1e-15))
) continue; ) 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; if (found) continue;
Console.WriteLine(InCircles(circles)); Console.WriteLine(InCircles(circles));
failed = true; failed = true;
Console.WriteLine("Not found: {0}\t{1}", intersection.X, intersection.Y); Console.WriteLine("Not found: {0}\t{1}", intersection.X, intersection.Y);
Console.WriteLine("correct"); Console.WriteLine("correct");
@@ -92,6 +105,7 @@ namespace TMI_practicum
{ {
Console.WriteLine("{0}\t{1}", intersection1.X, intersection1.Y); Console.WriteLine("{0}\t{1}", intersection1.X, intersection1.Y);
} }
Console.WriteLine("wrong"); Console.WriteLine("wrong");
foreach (var intersection1 in solved) foreach (var intersection1 in solved)
{ {
@@ -108,9 +122,9 @@ namespace TMI_practicum
{ {
Console.WriteLine("{0} {1} {2}", circle.X, circle.Y, circle.R); Console.WriteLine("{0} {1} {2}", circle.X, circle.Y, circle.R);
} }
break; break;
} }
} }
} }
@@ -122,7 +136,7 @@ namespace TMI_practicum
for (int i = 0; i < amount; i++) 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), 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; return circles;
@@ -175,7 +189,9 @@ namespace TMI_practicum
int i = 0; int i = 0;
while ((line = file.ReadLine()) != null) 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]); circles[i++] = new Circle(parts[0], parts[1], parts[2]);
} }
} }
@@ -201,7 +217,7 @@ namespace TMI_practicum
using (StreamWriter sw = File.CreateText(OutputFile)) 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); sw.WriteLine("{0:0.000000000000000}\t{1:0.000000000000000}", intersection.X, intersection.Y);
} }