diff --git a/Interfaces/SolverInterface.cs b/Interfaces/SolverInterface.cs index 0ba17ec8..ba0085aa 100644 --- a/Interfaces/SolverInterface.cs +++ b/Interfaces/SolverInterface.cs @@ -1,6 +1,3 @@ -using API.Interfaces.JSON_Objects; -using API.Interfaces.JSON_Objects.Graphs; -using API.Tools; namespace API.Interfaces; @@ -10,6 +7,21 @@ interface ISolver { string source {get;} string[] contributors { get; } + bool timerHasExpired { get; set; } + + /// + /// 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. + /// + public void TimerExpired() + { + timerHasExpired = true; + } + public void ResetTimer() + { + timerHasExpired = false; + } string solve(string problem); List GetSteps(string instance) @@ -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 ISolver.GetSteps(string instance) { diff --git a/Problems/NPComplete/NPC_ARCSET/Solvers/ArcSetBruteForce.cs b/Problems/NPComplete/NPC_ARCSET/Solvers/ArcSetBruteForce.cs index d1b4af07..b81b65d0 100644 --- a/Problems/NPComplete/NPC_ARCSET/Solvers/ArcSetBruteForce.cs +++ b/Problems/NPComplete/NPC_ARCSET/Solvers/ArcSetBruteForce.cs @@ -13,6 +13,7 @@ class ArcSetBruteForce : ISolver { public string source {get;} = ""; public string[] contributors {get;} = { "Alex Diviney","Caleb Eardley","Russell Phillips"}; + public bool timerHasExpired { get; set; } // --- Methods Including Constructors --- public ArcSetBruteForce() { diff --git a/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniClassicalSolver.cs b/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniClassicalSolver.cs index afa8d365..ca885c69 100644 --- a/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniClassicalSolver.cs +++ b/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniClassicalSolver.cs @@ -8,6 +8,7 @@ class BernsteinVaziraniClassicalSolver : ISolver { 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() {} diff --git a/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniQuantumSolver.cs b/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniQuantumSolver.cs index 21598bab..f2bfb739 100644 --- a/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniQuantumSolver.cs +++ b/Problems/NPComplete/NPC_BERNSTEINVAZIRANI/Solvers/BernsteinVaziraniQuantumSolver.cs @@ -15,6 +15,7 @@ class BernsteinVaziraniQuantumSolver : ISolver { 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; diff --git a/Problems/NPComplete/NPC_CLIQUE/Solvers/CliqueBruteForce.cs b/Problems/NPComplete/NPC_CLIQUE/Solvers/CliqueBruteForce.cs index fe74bb07..98b74d5d 100644 --- a/Problems/NPComplete/NPC_CLIQUE/Solvers/CliqueBruteForce.cs +++ b/Problems/NPComplete/NPC_CLIQUE/Solvers/CliqueBruteForce.cs @@ -12,6 +12,7 @@ class CliqueBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_CLIQUECOVER/Solvers/CliqueCoverBruteForce.cs b/Problems/NPComplete/NPC_CLIQUECOVER/Solvers/CliqueCoverBruteForce.cs index bd604314..80ba39f7 100644 --- a/Problems/NPComplete/NPC_CLIQUECOVER/Solvers/CliqueCoverBruteForce.cs +++ b/Problems/NPComplete/NPC_CLIQUECOVER/Solvers/CliqueCoverBruteForce.cs @@ -10,6 +10,7 @@ class CliqueCoverBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_CUT/Solvers/CutBruteForce.cs b/Problems/NPComplete/NPC_CUT/Solvers/CutBruteForce.cs index bd8879a5..9ffff219 100644 --- a/Problems/NPComplete/NPC_CUT/Solvers/CutBruteForce.cs +++ b/Problems/NPComplete/NPC_CUT/Solvers/CutBruteForce.cs @@ -10,8 +10,9 @@ class CutBruteForce : ISolver { 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){ diff --git a/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschClassicalSolver.cs b/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschClassicalSolver.cs index 5190c51c..16a496ed 100644 --- a/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschClassicalSolver.cs +++ b/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschClassicalSolver.cs @@ -8,6 +8,7 @@ class DeutschClassicalSolver : ISolver { 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() {} diff --git a/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschQuantumSolver.cs b/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschQuantumSolver.cs index bb106de8..d3fd9219 100644 --- a/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschQuantumSolver.cs +++ b/Problems/NPComplete/NPC_DEUTSCH/Solvers/DeutschQuantumSolver.cs @@ -18,9 +18,10 @@ class DeutschQuantumSolver : ISolver { // Configuration: Change this to switch between servers private readonly QuantumServerAPI.ServerEnvironment _serverEnvironment; + public bool timerHasExpired { get; set; } // --- Constructors --- - + /// /// Creates a new DeutschQuantumSolver using the ISU AWS server by default /// diff --git a/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaClassicalSolver.cs b/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaClassicalSolver.cs index cc472748..8d9ddc4f 100644 --- a/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaClassicalSolver.cs +++ b/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaClassicalSolver.cs @@ -10,6 +10,7 @@ class DeutschJozsaClassicalSolver : ISolver { 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() {} diff --git a/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaQuantumSolver.cs b/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaQuantumSolver.cs index 0264dc6f..362078e1 100644 --- a/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaQuantumSolver.cs +++ b/Problems/NPComplete/NPC_DEUTSCHJOZSA/Solvers/DeutschJozsaQuantumSolver.cs @@ -15,6 +15,7 @@ class DeutschJozsaQuantumSolver : ISolver { 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; diff --git a/Problems/NPComplete/NPC_DIRECTEDHAMILTONIAN/Solvers/DirectedHamiltonianBruteForce.cs b/Problems/NPComplete/NPC_DIRECTEDHAMILTONIAN/Solvers/DirectedHamiltonianBruteForce.cs index e752b590..0c717139 100644 --- a/Problems/NPComplete/NPC_DIRECTEDHAMILTONIAN/Solvers/DirectedHamiltonianBruteForce.cs +++ b/Problems/NPComplete/NPC_DIRECTEDHAMILTONIAN/Solvers/DirectedHamiltonianBruteForce.cs @@ -10,6 +10,7 @@ class DirectedHamiltonianBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_DM3/Solvers/ThreeDimensionalMatchingBruteForce.cs b/Problems/NPComplete/NPC_DM3/Solvers/ThreeDimensionalMatchingBruteForce.cs index d1662924..386ed11c 100644 --- a/Problems/NPComplete/NPC_DM3/Solvers/ThreeDimensionalMatchingBruteForce.cs +++ b/Problems/NPComplete/NPC_DM3/Solvers/ThreeDimensionalMatchingBruteForce.cs @@ -9,6 +9,7 @@ class ThreeDimensionalMatchingBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_EXACTCOVER/Solvers/DancingLinks.cs b/Problems/NPComplete/NPC_EXACTCOVER/Solvers/DancingLinks.cs index fe18db8f..4a4e7a3b 100644 --- a/Problems/NPComplete/NPC_EXACTCOVER/Solvers/DancingLinks.cs +++ b/Problems/NPComplete/NPC_EXACTCOVER/Solvers/DancingLinks.cs @@ -9,6 +9,7 @@ class DancingLinks : ISolver { public string solverDefinition {get;} = ""; public string source {get;} = ""; public string[] contributors {get;} = { "Andrija Sevaljevic"}; + public bool timerHasExpired { get; set; } // --- Methods Including Constructors --- public DancingLinks() { diff --git a/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverBruteForce.cs b/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverBruteForce.cs index da0cd8c6..09d07ea2 100644 --- a/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverBruteForce.cs +++ b/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverBruteForce.cs @@ -8,6 +8,7 @@ class ExactCoverBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverRecursive.cs b/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverRecursive.cs index cbfeede2..f8cd156d 100644 --- a/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverRecursive.cs +++ b/Problems/NPComplete/NPC_EXACTCOVER/Solvers/ExactCoverRecursive.cs @@ -8,6 +8,7 @@ class ExactCoverRecursive : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_GRAPHCOLORING/Solvers/GraphColoringBruteForce.cs b/Problems/NPComplete/NPC_GRAPHCOLORING/Solvers/GraphColoringBruteForce.cs index d5b5c96f..5e55ded2 100644 --- a/Problems/NPComplete/NPC_GRAPHCOLORING/Solvers/GraphColoringBruteForce.cs +++ b/Problems/NPComplete/NPC_GRAPHCOLORING/Solvers/GraphColoringBruteForce.cs @@ -10,6 +10,7 @@ class GraphColoringBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_HAMILTONIAN/Solvers/HamiltonianBruteForce.cs b/Problems/NPComplete/NPC_HAMILTONIAN/Solvers/HamiltonianBruteForce.cs index df3a11f9..03a8be9d 100644 --- a/Problems/NPComplete/NPC_HAMILTONIAN/Solvers/HamiltonianBruteForce.cs +++ b/Problems/NPComplete/NPC_HAMILTONIAN/Solvers/HamiltonianBruteForce.cs @@ -10,6 +10,7 @@ class HamiltonianBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_HITTINGSET/Solvers/HittingSetBruteForce.cs b/Problems/NPComplete/NPC_HITTINGSET/Solvers/HittingSetBruteForce.cs index a9a354d2..a7150cea 100644 --- a/Problems/NPComplete/NPC_HITTINGSET/Solvers/HittingSetBruteForce.cs +++ b/Problems/NPComplete/NPC_HITTINGSET/Solvers/HittingSetBruteForce.cs @@ -11,6 +11,7 @@ class HittingSetBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_INDEPENDENTSET/Solvers/IndependentSetBruteForce.cs b/Problems/NPComplete/NPC_INDEPENDENTSET/Solvers/IndependentSetBruteForce.cs index 846b2903..2abb9821 100644 --- a/Problems/NPComplete/NPC_INDEPENDENTSET/Solvers/IndependentSetBruteForce.cs +++ b/Problems/NPComplete/NPC_INDEPENDENTSET/Solvers/IndependentSetBruteForce.cs @@ -10,6 +10,7 @@ class IndependentSetBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_INTPROGRAMMING01/Solvers/IntegerProgrammingBruteForce.cs b/Problems/NPComplete/NPC_INTPROGRAMMING01/Solvers/IntegerProgrammingBruteForce.cs index af38b7e4..4b03abf5 100644 --- a/Problems/NPComplete/NPC_INTPROGRAMMING01/Solvers/IntegerProgrammingBruteForce.cs +++ b/Problems/NPComplete/NPC_INTPROGRAMMING01/Solvers/IntegerProgrammingBruteForce.cs @@ -8,6 +8,7 @@ class IntegerProgrammingBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_JOBSEQ/Solvers/JobSeqBruteForce.cs b/Problems/NPComplete/NPC_JOBSEQ/Solvers/JobSeqBruteForce.cs index a105b208..3ba62171 100644 --- a/Problems/NPComplete/NPC_JOBSEQ/Solvers/JobSeqBruteForce.cs +++ b/Problems/NPComplete/NPC_JOBSEQ/Solvers/JobSeqBruteForce.cs @@ -10,6 +10,7 @@ class JobSeqBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_KNAPSACK/Solvers/KnapsackBruteForce.cs b/Problems/NPComplete/NPC_KNAPSACK/Solvers/KnapsackBruteForce.cs index d8cb0a46..e25c9948 100644 --- a/Problems/NPComplete/NPC_KNAPSACK/Solvers/KnapsackBruteForce.cs +++ b/Problems/NPComplete/NPC_KNAPSACK/Solvers/KnapsackBruteForce.cs @@ -10,6 +10,7 @@ class KnapsackBruteForce : ISolver { 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)"; diff --git a/Problems/NPComplete/NPC_MAXCUT/Solvers/MaxCutSolver.cs b/Problems/NPComplete/NPC_MAXCUT/Solvers/MaxCutSolver.cs index 6771dbc6..f7c1021b 100644 --- a/Problems/NPComplete/NPC_MAXCUT/Solvers/MaxCutSolver.cs +++ b/Problems/NPComplete/NPC_MAXCUT/Solvers/MaxCutSolver.cs @@ -10,6 +10,7 @@ class MaxCutSolver : ISolver { 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() { } diff --git a/Problems/NPComplete/NPC_NODESET/Solvers/NodeSetBruteForce.cs b/Problems/NPComplete/NPC_NODESET/Solvers/NodeSetBruteForce.cs index fc0c18e2..69183d9e 100644 --- a/Problems/NPComplete/NPC_NODESET/Solvers/NodeSetBruteForce.cs +++ b/Problems/NPComplete/NPC_NODESET/Solvers/NodeSetBruteForce.cs @@ -10,8 +10,9 @@ class NodeSetBruteForce : ISolver { 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){ diff --git a/Problems/NPComplete/NPC_PARTITION/Solvers/PartitionBruteForce.cs b/Problems/NPComplete/NPC_PARTITION/Solvers/PartitionBruteForce.cs index 08cdabe6..3aa2e9f1 100644 --- a/Problems/NPComplete/NPC_PARTITION/Solvers/PartitionBruteForce.cs +++ b/Problems/NPComplete/NPC_PARTITION/Solvers/PartitionBruteForce.cs @@ -10,6 +10,7 @@ class PartitionBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/PrimeFactorSolver.cs b/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/PrimeFactorSolver.cs index 786814ec..ab23c3f1 100644 --- a/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/PrimeFactorSolver.cs +++ b/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/PrimeFactorSolver.cs @@ -8,7 +8,7 @@ class PrimeFactorSolver : ISolver { 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() {} diff --git a/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/ShorsQuantumSolver.cs b/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/ShorsQuantumSolver.cs index f866c3ff..95c0aa09 100644 --- a/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/ShorsQuantumSolver.cs +++ b/Problems/NPComplete/NPC_PRIMEFACTOR/Solvers/ShorsQuantumSolver.cs @@ -20,6 +20,7 @@ class ShorsQuantumSolver : ISolver { "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; diff --git a/Problems/NPComplete/NPC_SAT/Solvers/SATBruteForceSolver.cs b/Problems/NPComplete/NPC_SAT/Solvers/SATBruteForceSolver.cs index f4f8c039..79c96170 100644 --- a/Problems/NPComplete/NPC_SAT/Solvers/SATBruteForceSolver.cs +++ b/Problems/NPComplete/NPC_SAT/Solvers/SATBruteForceSolver.cs @@ -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 @@ -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 currentClause in clause){ + if (timerHasExpired) + return "timeout"; + + foreach (List 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); diff --git a/Problems/NPComplete/NPC_SAT/Solvers/SATGroverSolver.cs b/Problems/NPComplete/NPC_SAT/Solvers/SATGroverSolver.cs index ead817b5..20731da3 100644 --- a/Problems/NPComplete/NPC_SAT/Solvers/SATGroverSolver.cs +++ b/Problems/NPComplete/NPC_SAT/Solvers/SATGroverSolver.cs @@ -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; diff --git a/Problems/NPComplete/NPC_SAT3/Solvers/Sat3BacktrackingSolver.cs b/Problems/NPComplete/NPC_SAT3/Solvers/Sat3BacktrackingSolver.cs index c6149ba4..4c5a4d60 100644 --- a/Problems/NPComplete/NPC_SAT3/Solvers/Sat3BacktrackingSolver.cs +++ b/Problems/NPComplete/NPC_SAT3/Solvers/Sat3BacktrackingSolver.cs @@ -11,6 +11,7 @@ class Sat3BacktrackingSolver : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_SETCOVER/Solvers/HeuristicSolver.cs b/Problems/NPComplete/NPC_SETCOVER/Solvers/HeuristicSolver.cs index 2064620a..b292e309 100644 --- a/Problems/NPComplete/NPC_SETCOVER/Solvers/HeuristicSolver.cs +++ b/Problems/NPComplete/NPC_SETCOVER/Solvers/HeuristicSolver.cs @@ -9,6 +9,7 @@ class HeuristicSolver : ISolver { public string solverDefinition {get;} = ""; public string source {get;} = ""; public string[] contributors {get;} = { "Andrija Sevaljevic" }; + public bool timerHasExpired { get; set; } // --- Methods Including Constructors --- public HeuristicSolver() diff --git a/Problems/NPComplete/NPC_SETCOVER/Solvers/SetCoverBruteForce.cs b/Problems/NPComplete/NPC_SETCOVER/Solvers/SetCoverBruteForce.cs index 43d04df7..764e6a10 100644 --- a/Problems/NPComplete/NPC_SETCOVER/Solvers/SetCoverBruteForce.cs +++ b/Problems/NPComplete/NPC_SETCOVER/Solvers/SetCoverBruteForce.cs @@ -11,6 +11,7 @@ class SetCoverBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_SIMON/Solvers/SimonSolver.cs b/Problems/NPComplete/NPC_SIMON/Solvers/SimonSolver.cs index d4013a41..98ee8e68 100644 --- a/Problems/NPComplete/NPC_SIMON/Solvers/SimonSolver.cs +++ b/Problems/NPComplete/NPC_SIMON/Solvers/SimonSolver.cs @@ -10,6 +10,7 @@ class SimonSolver : ISolver 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() { } diff --git a/Problems/NPComplete/NPC_STEINERTREE/Solvers/SteinerTreeBruteForce.cs b/Problems/NPComplete/NPC_STEINERTREE/Solvers/SteinerTreeBruteForce.cs index b0d99949..f7162c40 100644 --- a/Problems/NPComplete/NPC_STEINERTREE/Solvers/SteinerTreeBruteForce.cs +++ b/Problems/NPComplete/NPC_STEINERTREE/Solvers/SteinerTreeBruteForce.cs @@ -10,6 +10,7 @@ class SteinerTreeBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_SUBSETSUM/Solvers/SubsetSumBruteForce.cs b/Problems/NPComplete/NPC_SUBSETSUM/Solvers/SubsetSumBruteForce.cs index c5bbf5ae..f8ad0180 100644 --- a/Problems/NPComplete/NPC_SUBSETSUM/Solvers/SubsetSumBruteForce.cs +++ b/Problems/NPComplete/NPC_SUBSETSUM/Solvers/SubsetSumBruteForce.cs @@ -8,6 +8,7 @@ class SubsetSumBruteForce : ISolver { 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() { diff --git a/Problems/NPComplete/NPC_SUDOKU/Solvers/SudokuSolver.cs b/Problems/NPComplete/NPC_SUDOKU/Solvers/SudokuSolver.cs index 282aeb11..b61f73d7 100644 --- a/Problems/NPComplete/NPC_SUDOKU/Solvers/SudokuSolver.cs +++ b/Problems/NPComplete/NPC_SUDOKU/Solvers/SudokuSolver.cs @@ -8,6 +8,7 @@ class SudokuSolver : ISolver { 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() {} diff --git a/Problems/NPComplete/NPC_TSP/Solvers/TSPBruteForce.cs b/Problems/NPComplete/NPC_TSP/Solvers/TSPBruteForce.cs index 4321ee4e..da528995 100644 --- a/Problems/NPComplete/NPC_TSP/Solvers/TSPBruteForce.cs +++ b/Problems/NPComplete/NPC_TSP/Solvers/TSPBruteForce.cs @@ -10,6 +10,7 @@ class TSPBruteForce : ISolver { 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() diff --git a/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredGroverSolver.cs b/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredGroverSolver.cs index 7ed94c5d..7b4bd1a4 100644 --- a/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredGroverSolver.cs +++ b/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredGroverSolver.cs @@ -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; @@ -11,6 +10,7 @@ class UnstructuredGroverSolver : ISolver { 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; diff --git a/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredSearchSolver.cs b/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredSearchSolver.cs index b04426a7..b5e82e72 100644 --- a/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredSearchSolver.cs +++ b/Problems/NPComplete/NPC_UNSTRUCTUREDSEARCH/Solvers/UnstructuredSearchSolver.cs @@ -8,6 +8,7 @@ class UnstructuredSearchSolver : ISolver { public string solverDefinition { get; } = "This solver simply loops through all possible x until one f(x) = 1."; public string source { get; } = ""; public string[] contributors { get; } = { "Jason L. Wright", "Alex Svancara" }; + public bool timerHasExpired { get; set; } // --- Methods Including Constructors --- public UnstructuredSearchSolver() {} diff --git a/Problems/NPComplete/NPC_VERTEXCOVER/Solvers/VertexCoverBruteForce.cs b/Problems/NPComplete/NPC_VERTEXCOVER/Solvers/VertexCoverBruteForce.cs index f1aea3b3..8c41697f 100644 --- a/Problems/NPComplete/NPC_VERTEXCOVER/Solvers/VertexCoverBruteForce.cs +++ b/Problems/NPComplete/NPC_VERTEXCOVER/Solvers/VertexCoverBruteForce.cs @@ -11,6 +11,7 @@ class VertexCoverBruteForce : ISolver { public string solverDefinition {get;} = "This solver simply tests combinations of nodes of size k until a solution is found, or all combinations are tested."; public string source {get;} = ""; public string[] contributors {get;} = { "Caleb Eardley"}; + public bool timerHasExpired { get; set; } // --- Methods Including Constructors --- public VertexCoverBruteForce() { diff --git a/Problems/NPComplete/NPC_WEIGHTEDCUT/Solvers/WeightedCutBruteForce.cs b/Problems/NPComplete/NPC_WEIGHTEDCUT/Solvers/WeightedCutBruteForce.cs index 73e5ab8b..11c454d6 100644 --- a/Problems/NPComplete/NPC_WEIGHTEDCUT/Solvers/WeightedCutBruteForce.cs +++ b/Problems/NPComplete/NPC_WEIGHTEDCUT/Solvers/WeightedCutBruteForce.cs @@ -10,6 +10,7 @@ class WeightedCutBruteForce : ISolver { public string solverDefinition {get;} = "This is a brute force solver for the Weighted Cut problem"; public string source {get;} = ""; public string[] contributors {get;} = { "Andrija Sevaljevic" }; + public bool timerHasExpired { get; set; } public WeightedCutBruteForce() { @@ -126,4 +127,3 @@ public string solve(WEIGHTEDCUT cut) return "{}"; } } -