Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 196 additions & 53 deletions AdditionalControllers/Navigation/Nav_Problems.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,95 @@
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Collections;

//NOTE - Corbin: In order to add a controller for another file within /Problems, simply copy a specified controller (such as 'NPC_ProblemsRefactorController')
// paste and rename, the only changes needed is the path which defines subdirs for both functions: getDefault and getProblemsJson and update comments

// Get all problems regardless of complexity class
//NOTE - Corbin: All specific controllers should probably be removed with the addition of tags, instead of one function per folder it should probably query a tag (like the NagGraph does for chosenProblem)
// in order to have one generalized specified problem controller

// Get all problems
[ApiController]
[Route("Navigation/[controller]")]
[Tags("- Navigation (Problems)")]
#pragma warning disable CS1591
public class All_ProblemsController : ControllerBase {
#pragma warning restore CS1591
//Note: CALEB - should probably be renamed with api refactor


///<summary>Returns list of all available problem types </summary>
///<response code="200">Returns string array of problem types</response>
public class ALL_ProblemsRefactorController : ControllerBase
{
#pragma warning restore CS1591

///<summary>Returns all problems</summary>
///<response code = "200">Returns string array of all problems regardless of class</response>

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet]
public String getDefault() {

public String getDefault()
{
string projectSourcePath = ProjectSourcePath.Value;
string?[] subdirs = Directory.GetDirectories(projectSourcePath+ @"Problems")
.Select(Path.GetFileName)
.ToArray();
var allProblemDirNames = new List<string>();

foreach (var classDir in Directory.GetDirectories(projectSourcePath + @"Problems"))
{
foreach (var problemDir in Directory.GetDirectories(classDir))
{
var name = Path.GetFileName(problemDir);
if (name != null)
allProblemDirNames.Add(name);
}
}
string?[] subdirs = allProblemDirNames.ToArray();
ArrayList subdirsNoPrefix = new ArrayList();
foreach (var problemDirName in subdirs)
{
if (problemDirName is null)
continue;
string[] splitStr = problemDirName.Split('_');
string newName = splitStr[1];
subdirsNoPrefix.Add(newName);
}

// Not completed. Needs to loop through these directories to get the rest of the problems
var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(subdirs, options);
string jsonString = JsonSerializer.Serialize(subdirsNoPrefix, options);
return jsonString;
}


///<summary>Returns all problems</summary>
///<response code = "200">Returns string array of all problems regardless of class</response>

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet("json")]
public string getProblemsJson()
{
string projectSourcePath = ProjectSourcePath.Value;
string objectPrefix = "problemName";

var allProblemDirNames = new List<string>();

foreach (var classDir in Directory.GetDirectories(projectSourcePath + @"Problems"))
{
foreach (var problemDir in Directory.GetDirectories(classDir))
{
var name = Path.GetFileName(problemDir);
if (name != null)
allProblemDirNames.Add(name);
}
}

ArrayList jsonedList = new ArrayList();
foreach (var problemInstance in allProblemDirNames)
{
string jsonPair = $"{{\"{objectPrefix}\" : \"{problemInstance}\"}}";
jsonedList.Add(jsonPair);
}

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(jsonedList, options);
return jsonString;
}
}
Expand All @@ -40,80 +100,104 @@ public String getDefault() {
[Tags("- Navigation (Problems)")]
#pragma warning disable CS1591

public class NPC_ProblemsController : ControllerBase {
public class NPC_ProblemsRefactorController : ControllerBase
{
#pragma warning restore CS1591
//Note: CALEB - should probably be removed with api refactor

///<summary>Returns all NP-Complete problems </summary>
///<response code="200">Returns string array of all NP-Complete problems</response>
///<summary>Returns all NP-Complete problems </summary>
///<response code="200">Returns string array of all NP-Complete problems</response>

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet]

public String getDefault() {
public String getDefault()
{
// File system patch that should work on both Window/Linux enviroments
string projectSourcePath = ProjectSourcePath.Value;
string?[] subdirs = Directory.GetDirectories(projectSourcePath+ @"Problems/NPComplete")
.Select(Path.GetFileName)
.ToArray();

string?[] subdirs = Directory.GetDirectories(projectSourcePath + @"/Problems/NPComplete")
.Select(Path.GetFileName)
.ToArray();

ArrayList subdirsNoPrefix = new ArrayList();
foreach (var problemDirName in subdirs)
{
if (problemDirName is null)
continue;
string[] splitStr = problemDirName.Split('_');
string newName = splitStr[1];
subdirsNoPrefix.Add(newName);
}

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(subdirs, options);
string jsonString = JsonSerializer.Serialize(subdirsNoPrefix, options);

//NOTE - Corbin: below is someone elses commented out code, I am leaving it for now just in case it is needed.

// ProblemGraph graph = new ProblemGraph();
// graph.getConnectedNodes("SAT3");
// string ring = JsonSerializer.Serialize(graph.getConnectedNodes("SAT3"), options);
// Console.WriteLine("\n"+ring );

//Response.Headers.Add("Access-Control-Allow-Origin", "http://127.0.0.1:5500");
return jsonString;
}

///<summary>Returns all NP-Complete problems </summary>
///<response code="200">Returns json dictionary of all NP-Complete problems</response>
///<summary>Returns all NP-Complete problems </summary>
///<response code="200">Returns json dictionary of all NP-Complete problems</response>
//Note: CALEB - should probably be removed with api refactor

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet("json")]
public string getProblemsJson(){
public string getProblemsJson()
{
string projectSourcePath = ProjectSourcePath.Value;
string objectPrefix = "problemName";
string?[] subdirs = Directory.GetDirectories(projectSourcePath+ @"Problems/NPComplete")
string?[] subdirs = Directory.GetDirectories(projectSourcePath + @"Problems/NPComplete")
.Select(Path.GetFileName)
.ToArray();

ArrayList jsonedList = new ArrayList();
foreach(var problemInstance in subdirs){
foreach (var problemInstance in subdirs)
{
if (problemInstance is null)
continue;
string jsonPair = $"{{\"{objectPrefix}\" : \"{problemInstance}\"}}";
jsonedList.Add(jsonPair);
}
var options = new JsonSerializerOptions { WriteIndented = true };

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(jsonedList, options);
return jsonString;
}
}


// Get only NP-Complete problems
// Get only P-Class problems
[ApiController]
[Route("Navigation/[controller]")]
[Tags("- Navigation (Problems)")]
#pragma warning disable CS1591

public class NPC_ProblemsRefactorController : ControllerBase {
public class P_ProblemsRefactorController : ControllerBase
{
#pragma warning restore CS1591

///<summary>Returns all NP-Complete problems </summary>
///<response code="200">Returns string array of all NP-Complete problems</response>
///<summary>Returns all P-Class problems </summary>
///<response code="200">Returns string array of all NP-Complete problems</response>

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet]

public String getDefault() {
public String getDefault()
{
// File system patch that should work on both Window/Linux enviroments
string projectSourcePath = ProjectSourcePath.Value;
string?[] subdirs = Directory.GetDirectories(projectSourcePath+ @"/Problems/NPComplete")
string?[] subdirs = Directory.GetDirectories(projectSourcePath + @"/Problems/P")
.Select(Path.GetFileName)
.ToArray();

ArrayList subdirsNoPrefix = new ArrayList();
foreach(var problemDirName in subdirs){
foreach (var problemDirName in subdirs)
{
if (problemDirName is null)
continue;
string[] splitStr = problemDirName.Split('_');
Expand All @@ -123,38 +207,99 @@ public String getDefault() {

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(subdirsNoPrefix, options);
return jsonString;
}

// ProblemGraph graph = new ProblemGraph();
// graph.getConnectedNodes("SAT3");
// string ring = JsonSerializer.Serialize(graph.getConnectedNodes("SAT3"), options);
// Console.WriteLine("\n"+ring );
///<summary>Returns all P-Class problems </summary>
///<response code="200">Returns json dictionary of all NP-Complete problems</response>

//Response.Headers.Add("Access-Control-Allow-Origin", "http://127.0.0.1:5500");
[ProducesResponseType(typeof(string[]), 200)]
[HttpGet("json")]
public string getProblemsJson()
{
string projectSourcePath = ProjectSourcePath.Value;
string objectPrefix = "problemName";
string?[] subdirs = Directory.GetDirectories(projectSourcePath + @"Problems/P")
.Select(Path.GetFileName)
.ToArray();

ArrayList jsonedList = new ArrayList();
foreach (var problemInstance in subdirs)
{
if (problemInstance is null)
continue;
string jsonPair = $"{{\"{objectPrefix}\" : \"{problemInstance}\"}}";
jsonedList.Add(jsonPair);
}

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(jsonedList, options);
return jsonString;
}
}

///<summary>Returns all NP-Complete problems </summary>
///<response code="200">Returns json dictionary of all NP-Complete problems</response>
//Note: CALEB - should probably be removed with api refactor
// Get only NP-Hard problems
[ApiController]
[Route("Navigation/[controller]")]
[Tags("- Navigation (Problems)")]
#pragma warning disable CS1591

public class NPHard_ProblemsRefactorController : ControllerBase
{
#pragma warning restore CS1591

///<summary>Returns all NPHard problems </summary>
///<response code="200">Returns string array of all NP-Complete problems</response>

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet]

public String getDefault()
{
// File system patch that should work on both Window/Linux enviroments
string projectSourcePath = ProjectSourcePath.Value;
string?[] subdirs = Directory.GetDirectories(projectSourcePath + @"/Problems/NPHard")
.Select(Path.GetFileName)
.ToArray();

ArrayList subdirsNoPrefix = new ArrayList();
foreach (var problemDirName in subdirs)
{
if (problemDirName is null)
continue;
string[] splitStr = problemDirName.Split('_');
string newName = splitStr[1];
subdirsNoPrefix.Add(newName);
}

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(subdirsNoPrefix, options);
return jsonString;
}

///<summary>Returns all NPHard problems </summary>
///<response code="200">Returns json dictionary of all NP-Complete problems</response>

[ProducesResponseType(typeof(string[]), 200)]
[HttpGet("json")]
public string getProblemsJson(){
public string getProblemsJson()
{
string projectSourcePath = ProjectSourcePath.Value;
string objectPrefix = "problemName";
string?[] subdirs = Directory.GetDirectories(projectSourcePath+ @"Problems/NPComplete")
string?[] subdirs = Directory.GetDirectories(projectSourcePath + @"Problems/NPHard")
.Select(Path.GetFileName)
.ToArray();

ArrayList jsonedList = new ArrayList();
foreach(var problemInstance in subdirs){
foreach (var problemInstance in subdirs)
{
if (problemInstance is null)
continue;
string jsonPair = $"{{\"{objectPrefix}\" : \"{problemInstance}\"}}";
jsonedList.Add(jsonPair);
}
var options = new JsonSerializerOptions { WriteIndented = true };

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(jsonedList, options);
return jsonString;
}
Expand Down Expand Up @@ -212,6 +357,4 @@ public string getPaths([FromQuery]string reducingFrom, string reducingTo){

return jsonString;
}


}
2 changes: 1 addition & 1 deletion Problems/NPComplete/NPC_ARCSET/Solvers/ArcSetBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class ArcSetBruteForce : ISolver<ARCSET> {
public string solverName {get;} = "Arc Set Brute Force Solver";
public string solverDefinition {get;} = @" This Solver is a brute force solver, which checks all combinations of k edges until a solution is found or its determined there is no solution";
public string source {get;} = "";
public bool timerHasExpired { get; set; }

public string[] contributors {get;} = { "Alex Diviney","Caleb Eardley","Russell Phillips"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public ArcSetBruteForce() {
Expand Down
File renamed without changes.
File renamed without changes.
Loading