Skip to content
Merged
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
41 changes: 36 additions & 5 deletions Interfaces/SolverInterface.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using API.Interfaces.JSON_Objects;
using API.Interfaces.JSON_Objects.Graphs;
using API.Tools;

namespace API.Interfaces;

Expand All @@ -10,6 +7,21 @@ interface ISolver {
string source {get;}
string[] contributors { get; }

bool timerHasExpired { get; set; }

/// <summary>
/// Called when the run time timer for this solver has run out. The solver is
/// expected to check the "timerHasExpired" periodically and abandon the solution
/// if the flag is found to be true.
/// </summary>
public void TimerExpired()
{
timerHasExpired = true;
}
public void ResetTimer()
{
timerHasExpired = false;
}
string solve(string problem);

List<string> GetSteps(string instance)
Expand All @@ -23,10 +35,29 @@ string ISolver.solve(string problem) {
// Should there be some sort of contraint that assures there is a constructor
// that matches the signature of a single `string` argument?
// Perhaps a static `FromInstance(string instance)` method for `IProblem` will work.
return solve((T)Activator.CreateInstance(typeof(T), problem));
T problemInstance = (T)Activator.CreateInstance(typeof(T), problem);
if (problemInstance == null)
throw new ArgumentException($"Could not create problem instance for {problem}.");

string result = "no solution found";
Thread thread = new Thread(() => result = solve(problemInstance));

// start the thread
ResetTimer();
thread.Start();

// after 5 seconds w/out finishing, tell the thread it's time
// is up and wait for it to finish up.
// XXX make the solution time configurable
if (thread.Join(new TimeSpan(0, 0, 5)) == false)
{
TimerExpired();
thread.Join();
}
return result;
}
string solve(T problem);

string solve(T problem);

List<string> ISolver.GetSteps(string instance)
{
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_ARCSET/Solvers/ArcSetBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ArcSetBruteForce : ISolver<ARCSET> {
public string source {get;} = "";

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

// --- Methods Including Constructors ---
public ArcSetBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BernsteinVaziraniClassicalSolver : ISolver<BERNSTEINVAZIRANI> {
public string solverDefinition { get; } = "This is a classical verifier for the Bernstein-Vazirani problem which runs in O(n) time.";
public string source {get;} = "";
public string[] contributors {get;} = { "Jason L. Wright" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public BernsteinVaziraniClassicalSolver() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BernsteinVaziraniQuantumSolver : ISolver<BERNSTEINVAZIRANI> {
public string solverDefinition {get;} = "Calls external quantum computing API to solve Bernstein-Vazirani's algorithm";
public string source {get;} = "External API: towel.aws.cose.isu.edu:8080 or localhost:5000";
public string[] contributors {get;} = { "Grant Gardner" };
public bool timerHasExpired { get; set; }

// Configuration: Change this to switch between servers
private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment;
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_CLIQUE/Solvers/CliqueBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CliqueBruteForce : ISolver<CLIQUE> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Clique problem";
public string source {get;} = "";
public string[] contributors {get;} = {"Caleb Eardley", "Kaden Marchetti"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public CliqueBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CliqueCoverBruteForce : ISolver<CLIQUECOVER> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Clique Cover problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public CliqueCoverBruteForce()
Expand Down
3 changes: 2 additions & 1 deletion Problems/NPComplete/NPC_CUT/Solvers/CutBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class CutBruteForce : ISolver<CUT> {
public string solverDefinition {get;} = "This is a brute force solver for the Cut problem";
public string source {get;} = "";
public string[] contributors {get;} = {"Andrija Sevaljevic"};
public bool timerHasExpired { get; set; }

public CutBruteForce() {
public CutBruteForce() {

}
private long factorial(long x){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DeutschClassicalSolver : ISolver<DEUTSCH> {
public string solverDefinition { get; } = "This is a classical solver for the Deutsch Problem which simply tries both inputs to f(x) and computes whether they are the same (constant) or different (balanced)";
public string source { get; } = "Deutsch, David. 1985. Quantum theory, the Church-Turing principle and the universal quantum computer. Proc. R. Soc. Lond. A40097-117";
public string[] contributors {get;} = { "Jason L. Wright" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public DeutschClassicalSolver() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class DeutschQuantumSolver : ISolver<DEUTSCH> {

// Configuration: Change this to switch between servers
private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment;
public bool timerHasExpired { get; set; }

// --- Constructors ---

/// <summary>
/// Creates a new DeutschQuantumSolver using the ISU AWS server by default
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DeutschJozsaClassicalSolver : ISolver<DEUTSCHJOZSA> {
public string solverDefinition { get; } = "This solver classically solves the Deutsch-Jozsa problem by querying the oracle up to (n/2) + 1 times to determine if the function is constant or balanced.";
public string source { get; } = "Deutsch, David and Jozsa, Richard. 1992. Rapid solution of problems by quantum computation. Proc. R. Soc. Lond. A439553-558";
public string[] contributors {get;} = { "George Lake", "Eric Hill", "Paul Gilbreath", "Max Gruenwoldt", "Alex Svancara" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public DeutschJozsaClassicalSolver() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DeutschJozsaQuantumSolver : ISolver<DEUTSCHJOZSA> {
public string solverDefinition {get;} = "Calls external quantum computing API to solve Deutsch-Jozsa's algorithm";
public string source {get;} = "External API: towel.aws.cose.isu.edu:8080 or localhost:5000";
public string[] contributors {get;} = { "Grant Gardner" };
public bool timerHasExpired { get; set; }

// Configuration: Change this to switch between servers
private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DirectedHamiltonianBruteForce : ISolver<DIRECTEDHAMILTONIAN> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Directed Hamiltonian Path problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public DirectedHamiltonianBruteForce()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ThreeDimensionalMatchingBruteForce : ISolver<DM3> {
public string solverDefinition {get;} = "This is a generic local search solver for 3-Dimensional Matching, which, while possible, removes one constraint from the current solution, and swaps in two more constraints.";
public string source {get;} = "";
public string[] contributors {get;} = { "Caleb Eardley"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public ThreeDimensionalMatchingBruteForce() {
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_EXACTCOVER/Solvers/DancingLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DancingLinks : ISolver<EXACTCOVER> {
public string solverDefinition {get;} = "";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public DancingLinks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ExactCoverBruteForce : ISolver<EXACTCOVER> {
public string solverDefinition {get;} = "This is a generic brute force solver for Exact Cover";
public string source {get;} = "";
public string[] contributors {get;} = { "Caleb Eardley"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public ExactCoverBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ExactCoverRecursive : ISolver<EXACTCOVER> {
public string solverDefinition {get;} = "This is a optimized recursive solver for Exact Cover";
public string source {get;} = "";
public string[] contributors {get;} = { "Russell Phillips"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public ExactCoverRecursive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class GraphColoringBruteForce : ISolver<GRAPHCOLORING> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Graph Coloring problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public GraphColoringBruteForce()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HamiltonianBruteForce : ISolver<HAMILTONIAN> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Hamiltonian Path problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public HamiltonianBruteForce()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HittingSetBruteForce : ISolver<HITTINGSET> {
public string solverDefinition {get;} = "This is a brute force solver for Hitting Set";
public string source {get;} = "";
public string[] contributors {get;} = {"Russell Phillips"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public HittingSetBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class IndependentSetBruteForce : ISolver<INDEPENDENTSET> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Independent Set problem";
public string source {get;} = "";
public string[] contributors {get;} = {"Russell Phillips"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public IndependentSetBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class IntegerProgrammingBruteForce : ISolver<INTPROGRAMMING01> {
public string solverDefinition {get;} = "This is a generic brute force solver for 0-1 Integer Programming";
public string source {get;} = "";
public string[] contributors {get;} = { "Caleb Eardley"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public IntegerProgrammingBruteForce() {
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_JOBSEQ/Solvers/JobSeqBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class JobSeqBruteForce : ISolver<JOBSEQ> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Job Sequencing problem";
public string source {get;} = "";
public string[] contributors {get;} = {"Russell Phillips"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public JobSeqBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class KnapsackBruteForce : ISolver<KNAPSACK> {
public string solverDefinition {get;} = "This a brute force solver for the 0-1 Knapsack problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Russell Phillips"};
public bool timerHasExpired { get; set; }


public string complexity {get;} = "O(2^n)";
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_MAXCUT/Solvers/MaxCutSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MaxCutSolver : ISolver<MAXCUT> {
public string solverDefinition {get;} = "TODO";
public string source {get;} = "TODO";
public string[] contributors {get;} = {"Max Gruenwoldt", "Eric Hill"};
public bool timerHasExpired { get; set; }

public MaxCutSolver() { }

Expand Down
3 changes: 2 additions & 1 deletion Problems/NPComplete/NPC_NODESET/Solvers/NodeSetBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class NodeSetBruteForce : ISolver<NODESET> {
public string solverDefinition {get;} = "This is a brute force solver for the Node Set problem";
public string source {get;} = "";
public string[] contributors {get;} = {"Andrija Sevaljevic"};
public bool timerHasExpired { get; set; }

public NodeSetBruteForce() {
public NodeSetBruteForce() {

}
private long factorial(long x){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PartitionBruteForce : ISolver<PARTITION> {
public string solverDefinition {get;} = "This is a brute force solver for the Partition problem";
public string source {get;} = "";
public string[] contributors {get;} = {"Andrija Sevaljevic"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public PartitionBruteForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PrimeFactorSolver : ISolver<PRIMEFACTOR> {
public string solverDefinition {get;} = "TODO";
public string source {get;} = "https://doi.org/10.1137/S0036144598347011"; // A bone for the solutions team! ;)
public string[] contributors {get;} = { "Paul Gilbreath", "Alex Svancara" };

public bool timerHasExpired { get; set; }
// --- Methods Including Constructors ---
public PrimeFactorSolver() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ShorsQuantumSolver : ISolver<PRIMEFACTOR> {
"composite number through classical number theory operations like the greatest common divisor.";
public string source { get; } = "https://arxiv.org/abs/quant-ph/9708016";
public string[] contributors { get; } = { "Grant Gardner", "George Lake", "Jason Wright" };
public bool timerHasExpired { get; set; }

// Configuration: Change this to switch between servers
private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment;
Expand Down
6 changes: 5 additions & 1 deletion Problems/NPComplete/NPC_SAT/Solvers/SATBruteForceSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SATBruteForceSolver : ISolver {
public string solverName {get;} = "SAT Brute Force Solver";
public string solverDefinition {get;} = "This is a simple brute force solver for SAT";
public string source {get;} = "";
public bool timerHasExpired { get; set; }
public string[] contributors {get;} = { "Daniel Igbokwe", "Show Pratoomratana"};

#endregion
Expand Down Expand Up @@ -117,7 +118,10 @@ public string solve(string SATInstance){
// Loop through all combinations. The total number of binary choices you can make is 2^(number of items). E.G. 3 variables is 2^3.
for (int currentCombination = 0; currentCombination < Math.Pow(2, literals.Count); currentCombination++){
int trueClauses = 0;
foreach (List<string> currentClause in clause){
if (timerHasExpired)
return "timeout";

foreach (List<string> currentClause in clause){
// change the T/F values of the literals. Starts with at least 1 being true by incrementing at the start.
literalDict = increment(literalDict);
bool currentEvaluation = evaluate(literalDict, currentClause);
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_SAT/Solvers/SATGroverSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SATGroverSolver : ISolver
public string solverDefinition { get; } = "This solver builds the expression as a quantum circuit and then uses Grover's algorithm to probablisticly detemine a solution";
public string source {get;} = "External API: towel.aws.cose.isu.edu:8080 or localhost:5000";
public string[] contributors {get;} = { "Jason L. Wright" };
public bool timerHasExpired { get; set; }

// Configuration: Change this to switch between servers
private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Sat3BacktrackingSolver : ISolver<SAT3> {
public string solverDefinition { get; } = "This is a O(2^n) solution algorithm for the 3SAT problem which implements a back tracking algorithm to find an exact assignment boolean assignment of variables to satisfy the problem instance.";
public string source {get;} = "";
public string[] contributors {get;} = {"David Lindeman","Kaden Marchetti"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public Sat3BacktrackingSolver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class HeuristicSolver : ISolver<SETCOVER> {
public string solverDefinition {get;} = "";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public HeuristicSolver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SetCoverBruteForce : ISolver<SETCOVER> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Set Cover problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public SetCoverBruteForce()
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_SIMON/Solvers/SimonSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SimonSolver : ISolver<SIMON>
public string solverDefinition { get; } = "This solver classically solves Simon's Problem by analyzing the provided function values to determine the secret string.";
public string source { get; } = "Simon, Daniel R. (1997-10-01). \"On the Power of Quantum Computation\". SIAM Journal on Computing. 26 (5): 1474–1483. doi:10.1137/S0097539796298637. ISSN 0097-5397";
public string[] contributors { get; } = { "Jason L. Wright", "Eric Hill", "Paul Gilbreath", "Max Gruenwoldt", "Alex Svancara" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public SimonSolver() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SteinerTreeBruteForce : ISolver<STEINERTREE> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Steiner Tree problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public SteinerTreeBruteForce()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SubsetSumBruteForce : ISolver<SUBSETSUM> {
public string solverDefinition {get;} = "This is a brute force solver for Subset Sum";
public string source {get;} = "";
public string[] contributors {get;} = { "Caleb Eardley","Garret Stouffer"};
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public SubsetSumBruteForce() {
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_SUDOKU/Solvers/SudokuSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SudokuSolver : ISolver<SUDOKU> {
public string solverDefinition { get; } = "TODO";
public string source { get; } = "";
public string[] contributors { get; } = { "Eric Hill" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public SudokuSolver() {}
Expand Down
1 change: 1 addition & 0 deletions Problems/NPComplete/NPC_TSP/Solvers/TSPBruteForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TSPBruteForce : ISolver<TSP> {
public string solverDefinition {get;} = "This is a brute force solver for the NP-Complete Traveling Sales Person problem";
public string source {get;} = "";
public string[] contributors {get;} = { "Andrija Sevaljevic" };
public bool timerHasExpired { get; set; }

// --- Methods Including Constructors ---
public TSPBruteForce()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using API.Interfaces;
using API.Tools;
using API.Tools.ApiParameters;
using System.Text.Json;

namespace API.Problems.NPComplete.NPC_UNSTRUCTUREDSEARCH.Solvers;
Expand All @@ -11,6 +10,7 @@ class UnstructuredGroverSolver : ISolver<UNSTRUCTUREDSEARCH> {
public string solverDefinition { get; } = "This solver represents f(x) has a boolean circuit and then use Grover's algorithm to locate x such that f(x) = 1.";
public string source { get; } = "Grover L.K.: A fast quantum mechanical algorithm for database search, Proceedings, 28th Annual ACM Symposium on the Theory of Computing, (May 1996) p. 212.";
public string[] contributors { get; } = { "Jason L. Wright" };
public bool timerHasExpired { get; set; }

private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment;

Expand Down
Loading