예제 #1
0
        static void IndependentSetProblem()
        {
            PrintIndependentSetUsage();

            IndependentSetProblem problem = new IndependentSetProblem();

            problem.ReadInput(Console.In);

            CNF problemCNF = problem.ConvertToCNF();

            DPLL problemDPLL = new DPLL();
            Task <DPLLResultHolder> parallelSAT = problemDPLL.SatisfiableParallel(problemCNF);

            parallelSAT.Wait();
            Console.WriteLine();
            Console.WriteLine(problem.InterpretDPLLResult(parallelSAT.Result));
        }
예제 #2
0
        static void ThreeColorabilityProblem()
        {
            Print3ColorabilityUsage();

            ThreeColorabilityProblem problem = new ThreeColorabilityProblem();

            problem.ReadInput(Console.In);

            CNF problemCNF = problem.ConvertToCNF();

            DPLL problemDPLL = new DPLL();
            Task <DPLLResultHolder> parallelSAT = problemDPLL.SatisfiableParallel(problemCNF);

            parallelSAT.Wait();
            Console.WriteLine();
            Console.WriteLine(problem.InterpretDPLLResult(parallelSAT.Result));
        }
예제 #3
0
        static void HamiltonianPathProblem()
        {
            PrintHamiltonianPathUsage();

            HamiltonianPathProblem problem = new HamiltonianPathProblem();

            problem.ReadInput(Console.In);

            CNF problemCNF = problem.ConvertToCNF();

            DPLL problemDPLL = new DPLL();
            Task <DPLLResultHolder> parallelSAT = problemDPLL.SatisfiableParallel(problemCNF);

            parallelSAT.Wait();
            Console.WriteLine();
            Console.WriteLine(problem.InterpretDPLLResult(parallelSAT.Result));
        }
예제 #4
0
파일: DPLL.cs 프로젝트: Popa611/SAT-solver
        // Each thread's "main" function
        private DPLLResultHolder Solve(DPLL parallelDPLL, Queue <CNF> sharedModelQueue, IdleThreadsCounter idleThreadsCounter, CancellationToken token)
        {
            CNF model;

            while (true)
            {
                lock (sharedModelQueue)
                {
                    while (sharedModelQueue.Count == 0)
                    {
                        Monitor.Wait(sharedModelQueue); // Wait if there's nothing to solve
                        token.ThrowIfCancellationRequested();
                    }

                    Interlocked.Decrement(ref idleThreadsCounter.Counter); // This task started working - is no longer idle
                    model = sharedModelQueue.Dequeue();                    // Get a CNF model from the shared queue
                }

                token.ThrowIfCancellationRequested();
                DPLLResultHolder solverThreadResult = parallelDPLL.Satisfiable(model);

                if (solverThreadResult.SAT)
                {
                    return(solverThreadResult);  // The task has found SAT model
                }
                else
                {
                    Interlocked.Increment(ref idleThreadsCounter.Counter);  // The task is idle for now
                }

                lock (sharedModelQueue)
                {
                    // If all threads are idle and the queue is empty -> we're done and result remains unsat
                    if (Interlocked.Read(ref idleThreadsCounter.Counter) == Environment.ProcessorCount && sharedModelQueue.Count == 0)
                    {
                        return(solverThreadResult);
                    }
                }
            }
        }
예제 #5
0
        static void SATSolver()
        {
            PrintSATSolverUsage();

            CNF cnf = new CNF();

            cnf.ReadFormula(Console.In);

            // Sequential solution

            /*CNF cnfCopy = new CNF(cnf);
             * DPLL sequentialDPLL = new DPLL();
             * DPLLResultHolder sequentialResult = sequentialDPLL.Satisfiable(cnfCopy);
             * Console.WriteLine();
             * Console.WriteLine(sequentialResult);*/

            // Parallel solution
            DPLL parallelDPLL = new DPLL();
            Task <DPLLResultHolder> parallelSAT = parallelDPLL.SatisfiableParallel(cnf);

            parallelSAT.Wait();
            Console.WriteLine();
            Console.WriteLine(parallelSAT.Result);
        }