libgsjj  1
Deterministic finite automata learning library
SATCNFMethod.cpp
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 #include "MapleCOMSPS_LRB/utils/System.h"
6 
7 using namespace Minisat;
8 
9 namespace gsjj {
10  namespace passive {
11  namespace CNF {
12  SATCNFMethod::SATCNFMethod(const std::set<std::string> &SpSet, const std::set<std::string> &SmSet, const std::set<std::string> &SSet, const std::set<std::string> &prefixesSet, const std::set<char> &alphabetSet, unsigned int n) :
13  Method(SpSet, SmSet, SSet, prefixesSet, alphabetSet, n),
14  mustStop(nullptr)
15  {
16  }
17 
19 
20  }
21 
23  if (mustStop) {
24  m_solver = std::make_unique<SimpSolver>(*mustStop);
25  }
26  else {
27  std::atomic_bool falseBool(false);
28  m_solver = std::make_unique<SimpSolver>(falseBool);
29  }
30  m_solver->verbosity = 0;
32  createClauses();
33 
34  m_triedSolve = true;
35  // If mustStop is a valid pointer and if the value is true
36  if (mustStop && *mustStop) {
37  return false;
38  }
39  m_cpuTimeStart = cpuTime();
40  m_hasSolution = m_solver->solve(true, false);
41  m_cpuTimeEnd = cpuTime();
42  return m_hasSolution;
43  }
44 
45  std::unique_ptr<DFA<char>> SATCNFMethod::constructDFA() {
46  // We try to solve the SAT problem if not yet done
47  if (!m_triedSolve) {
48  if (!solve()) {
49  return nullptr;
50  }
51  }
52  // If the SAT problem is not satisfiable
53  if (!hasSolution()) {
54  return nullptr;
55  }
56  // The SAT problem has a solution
57  else {
58  return toDFA(m_solver->model);
59  }
60  }
61 
62  void SATCNFMethod::setStopTrigger(const std::chrono::seconds &timeLimit, std::atomic_bool &stopTrigger, const bool *stopPointer) {
63  mustStop = &stopTrigger;
64  }
65 
66  Minisat::Var SATCNFMethod::newVariable() {
67  return m_solver->newVar();
68  }
69 
70  void SATCNFMethod::addClause(const Minisat::vec<Minisat::Lit> &clause) {
71  m_solver->addClause(clause);
72  }
73  }
74  }
75 }
The namespace of the library.
Definition: binary.h:11
void addClause(const Minisat::vec< Minisat::Lit > &clause)
Adds a new clause to the SAT solver.
double m_cpuTimeStart
Definition: Method.h:126
std::unique_ptr< DFA< char > > constructDFA() override
Constructs the DFA induced by the variables according to the method.
virtual void createVariables()=0
Creates all needed variables for the method.
bool hasSolution() const
If solve() has been called and if there exists a solution, return True.
Definition: Method.h:60
bool solve() override
Solves the SAT/SMT problem induced by the method.
The base class of all passive methods.
Definition: Method.h:40
virtual std::unique_ptr< DFA< char > > toDFA(const Minisat::vec< Minisat::lbool > &model) const =0
Effectively creates the DFA from the values of the variables in the given model.
virtual void createClauses()=0
Creates all needed clauses for the method.
virtual void setStopTrigger(const std::chrono::seconds &timeLimit, std::atomic_bool &stopTrigger, const bool *stopPointer) override
Sets the stop trigger for this method.
Minisat::Var newVariable()
Creates a new variable in the SAT solver.