12 #include "MapleCOMSPS_LRB/utils/System.h" 21 BinaryCNFMethod::BinaryCNFMethod(
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) :
22 Method(SpSet, SmSet, SSet, prefixesSet, alphabetSet, n)
52 std::atomic_bool falseBool(
false);
53 m_solver = std::make_unique<BC>(falseBool);
70 auto dfa = std::make_unique<DFA<char>>(0,
m_Sp.size() != 0);
72 dfa->addTransition(0, a, 0);
98 m_solver = std::make_unique<BC>(stopTrigger);
111 Gate *formula =
nullptr;
116 const char &a = ua.at(ua.size() - 1);
117 const std::string &u = ua.substr(0, ua.size() - 1);
119 for (
const auto &va : m_prefixes) {
120 if (va.size() > 0 && va.at(va.size() - 1) == a) {
121 const std::string &v = va.substr(0, va.size() - 1);
126 Gate *eq =
equal(ua, va);
127 Gate *full =
m_solver->new_OR(different, eq);
130 formula =
m_solver->new_AND(formula, full);
142 for (
const auto &u :
m_Sp) {
143 for (
const auto &v :
m_Sm) {
150 for (
const auto &u : m_prefixes) {
164 Gate *gate =
nullptr;
167 Gate *x_uj =
m_stateToVar.find(std::make_pair(u, j))->second;
168 Gate *x_vj =
m_stateToVar.find(std::make_pair(v, j))->second;
171 Gate *total =
m_solver->new_OR(left, right);
174 gate =
m_solver->new_OR(gate, total);
185 Gate *gate =
nullptr;
190 Gate *x_uj =
m_stateToVar.find(std::make_pair(u, j))->second;
198 gate =
m_solver->new_OR(gate, l_uj);
209 unsigned int state = 0;
211 state += std::pow(2, j) *
m_stateToVar.at(std::make_pair(u, j))->value;
218 unsigned int initial =
toState(
"");
220 std::unique_ptr<DFA<char>> dfa = std::make_unique<DFA<char>>(initial,
m_Sp.find(
"") !=
m_Sp.end());
225 bool accepting =
false;
228 for (
const auto &u :
m_Sp) {
235 dfa->addState(i, accepting);
245 if (ua.size() > 0 && ua.at(ua.size() - 1) == a){
246 std::string u = ua.substr(0, ua.size() - 1);
250 dfa->addTransition(i, a, j);
257 dfa->addTransition(i, a, i);
const std::set< char > m_alphabet
The namespace of the library.
unsigned int toState(const std::string &u) const
SimplifyOptions m_simplify_opts
std::unique_ptr< BC > m_solver
unsigned int m_binarySize
const std::set< std::string > m_Sm
The set of words to reject .
const std::set< std::string > m_prefixes
static std::string getFactoryName()
This file declares the function to convert a number in its decimal form to its binary form and vice-v...
This file declares the Biermann method that relies on a CNF SAT solver.
std::unique_ptr< DFA< char > > constructDFA() override
Constructs the DFA induced by the variables according to the method.
bool solve() override
Solves the SAT/SMT problem induced by the method.
static bool s_registered
Useful to make sure the template is correctly used by the compiler.
std::vector< bool > decimal_to_binary(unsigned int dec_number, unsigned int size)
Converts a number in decimal form to binary form.
virtual Gate * createFormula()
virtual void createVariables()
bool hasSolution() const
If solve() has been called and if there exists a solution, return True.
virtual ~BinaryCNFMethod()
std::unique_ptr< DFA< char > > toDFA() const
const unsigned int m_numberStates
The number of states in the DFA to construct.
The base class of all passive methods.
const std::set< std::string > m_Sp
The set of words to accept .
Gate * equal(const std::string &u, const std::string &v)
virtual void setStopTrigger(const std::chrono::seconds &timeLimit, std::atomic_bool &stopTrigger, const bool *stopPointer) override
Sets the stop trigger for this method.
Gate * phi_not_q_i(const std::string &u, unsigned int i)
Gate * phi_different(const std::string &u, const std::string &v)