aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json4
-rw-r--r--.vscode/tasks.json37
-rw-r--r--README.md40
-rw-r--r--src/Program/Program.cs29
4 files changed, 57 insertions, 53 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 204ed6f..22952de 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -11,7 +11,9 @@
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Program/bin/Debug/net5.0/Program.dll",
- "args": [],
+ "args": [
+ "${workspaceFolder}/points1.txt"
+ ],
"cwd": "${workspaceFolder}/src/Program",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index d8704c4..292bc5e 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -15,48 +15,15 @@
},
{
"label": "release",
- "type": "shell",
- "dependsOn": [
- "release-win-x64",
- "release-linux-x64"
- ],
- "problemMatcher": []
- },
- {
- "label": "release-win-x64",
- "command": "dotnet",
- "type": "process",
- "args": [
- "publish",
- "${workspaceFolder}/src/Program/Program.csproj",
- "/property:GenerateFullPaths=true",
- "/property:PublishSingleFile=true",
- "/consoleloggerparameters:NoSummary",
- "-c",
- "Release",
- "-r",
- "win-x64",
- "-o",
- "${workspaceFolder}/release/win-64"
- ],
- "problemMatcher": "$msCompile"
- },
- {
- "label": "release-linux-x64",
"command": "dotnet",
"type": "process",
"args": [
"publish",
- "${workspaceFolder}/src/Program/Program.csproj",
- "/property:GenerateFullPaths=true",
- "/property:PublishSingleFile=true",
- "/consoleloggerparameters:NoSummary",
+ "${workspaceFolder}/ClosestPairs.sln",
"-c",
"Release",
- "-r",
- "linux-x64",
"-o",
- "${workspaceFolder}/release/linux-64"
+ "${workspaceFolder}/release"
],
"problemMatcher": "$msCompile"
}
diff --git a/README.md b/README.md
index 394e551..faef33d 100644
--- a/README.md
+++ b/README.md
@@ -1,25 +1,37 @@
-# CS 456 Design and Analysis of Algorithms
+# ClosestPair
-## Project2: Fast Closest Pairs (75 points)
+## Building the project
-### Description
-You are to implement the divide-and-conquer based closest pair algorithm given in section 5.4 of K\&T. Your algorithm must run correctly and take O(n log n) time
+Provided you have dotnet installed, the project can be built in one of the following ways:
-### Input and Output
-Format You will read the input points from a file named points.txt which contains a line for each point, where each point is given by its x-coordinate then a space followed by the y-coordinate. E.g., point set { (12, 45), (67, 32), (43, 93) } would look as follows:
+- Running the [`release`](.vscode/tasks.json) task in VS Code.
+- Executing the following command in any shell
+
+ ```sh
+ dotnet publish ClosestPairs.sln -c release -o ./release
+ ```
+
+## Running the program
+
+Project can be run from the command line using:
```
-12 45
+Usage:
+ ./release/Program[.exe] TEXTFILE
-67 32
+ TEXTFILE Path to text file containing a point on each line seperated by a space.
-43 93
```
-Your output should just be displayed to the user.
+### Example
-### Specifications
-This is an “all or nothing” project. There is no report for this project. You must simply correctly implement the O(n log n) time closest pair algorithm outlined in section 5.4 of your textbook, with appropriate and comprehensive documentation as to where you are performing what operations on the points. Incorrect implementation, (e.g. implementation that does not run in O(n log n) total time, or implementation that does not return the correct closest pair), will receive no credit. Non-compiling code will also receive no credit.
+Find the closest points in the file 'points1.txt'
-### What to turn in
-You must turn in a single zipped file containing your C++, C\# or Java code. If your program cannot be compiled and/or run you will have to demonstrate your code running in office hours.
+Linux
+ ```
+ ./release/Program ../points1.txt
+ ```
+Windows
+ ```
+ .\release\Program.exe ..\points1.txt
+ ```
diff --git a/src/Program/Program.cs b/src/Program/Program.cs
index f4c83d1..9985c10 100644
--- a/src/Program/Program.cs
+++ b/src/Program/Program.cs
@@ -9,13 +9,14 @@ namespace ClosestPair
{
public static void Main(string[] args)
{
- FileInfo inputFile = (args.Length > 0) ? new FileInfo(args[0]) : new FileInfo("points1.txt");
+ FileInfo inputFile = (args.Length > 0) ? new FileInfo(args[0]) : ReadFileName();
- if (!inputFile.Exists) {
+ if (!inputFile.Exists)
+ {
Console.WriteLine($"Failed to open {inputFile}: File does not exist.");
return;
}
-
+
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Point[] points = PointFile.ReadFile(inputFile.FullName);
@@ -28,6 +29,28 @@ namespace ClosestPair
Console.WriteLine($"Closest Points: {closestPair.ToString("F3")}");
Console.WriteLine($"Runtime: {ts.ToString("mm\\:ss\\.ff")}");
}
+ public static FileInfo ReadFileName()
+ {
+ FileInfo file = new FileInfo(" ");
+ string? filePath;
+
+ while (true)
+ {
+ Console.Write("Enter a path to a points file: ");
+ filePath = Console.ReadLine();
+
+ if (String.IsNullOrEmpty(filePath))
+ Console.WriteLine("File path cannot be empty!");
+ else if (!System.IO.File.Exists(filePath))
+ Console.WriteLine($"{filePath} does not exist.");
+ else
+ break;
+ }
+
+ file = new FileInfo(filePath);
+
+ return file;
+ }
}
} \ No newline at end of file