5 #include <boost/algorithm/string.hpp> 10 UnaryNonCNFMethod::UnaryNonCNFMethod(
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) :
29 std::string formula =
"";
33 formula +=
"x_" + u +
"_" + std::to_string(q);
34 if (q != m_numberStates - 1){
41 formula = formula.substr(0, formula.length() - 3);
46 for (
const auto &u : m_prefixes) {
51 formula +=
" ! ( x_" + u +
"_" + std::to_string(q) +
" & x_" + u +
"_" + std::to_string(p) +
" )";
56 formula = formula.substr(0, formula.length() - 2);
60 formula = formula.substr(0, formula.length() - 3);
65 for (
const auto &ua : m_prefixes) {
66 for (
const auto &va : m_prefixes) {
69 if (ua.size() > 0 && va.size() > 0 && ua.at(ua.size() - 1) == va.at(va.size() - 1)) {
70 std::string u = ua.substr(0, ua.size() - 1);
71 std::string v = va.substr(0, va.size() - 1);
75 formula +=
"( ( x_" + u +
"_" + std::to_string(p) +
" & " +
76 "x_" + v +
"_" + std::to_string(p) +
" ) " +
" -> ( " 77 "x_" + ua +
"_" + std::to_string(q) +
" <-> " +
78 "x_" + va +
"_" + std::to_string(q) +
" ) )";
86 formula = formula.substr(0, formula.length() - 3);
91 for (
const auto &u :
m_Sp) {
92 for (
const auto &v :
m_Sm) {
94 formula +=
" ! ( x_" + u +
"_" + std::to_string(q) +
" & x_" + v +
"_" + std::to_string(q) +
" )";
99 formula = formula.substr(0, formula.length() - 3);
108 std::map<std::string, unsigned int> words_states;
110 while(std::getline(stream, line)){
112 if (line.at(0) ==
'x'){
113 std::vector<std::string> results;
114 std::vector<std::string> results_2;
116 boost::split(results, line, [](
char c){
return c ==
' ';});
118 boost::split(results_2, results[0], [](
char c){
return c ==
'_';});
121 if (std::stoi(results[2]) == 1){
122 words_states.emplace(results_2[1], std::stoi(results_2[2]));
127 std::unique_ptr<DFA<char>> dfa = std::make_unique<DFA<char>>(words_states.find(
"") -> second,
m_Sp.find(
"") !=
m_Sp.end());
130 unsigned int state = words_states.find(u) -> second;
132 if(std::find(
m_Sp.begin(),
m_Sp.end(), u) !=
m_Sp.end()){
133 dfa->addState(state,
true);
136 dfa->addState(state,
false);
144 for (
const auto &ua : m_prefixes) {
145 if (ua.size() > 0 && ua.at(ua.size() - 1) == a){
146 std::string u = ua.substr(0, ua.size() - 1);
148 if (words_states.at(u) == i && words_states.at(ua) == j) {
150 dfa->addTransition(i, a, j);
157 dfa->addTransition(i, a, i);
static std::string getFactoryName()
const std::set< char > m_alphabet
The namespace of the library.
virtual std::string getFileName() const override
Gives the name of the file in which the boolean formula must be written.
const std::set< std::string > m_Sm
The set of words to reject .
const std::set< std::string > m_prefixes
virtual bool createFormula(std::ostream &stream) override
Creates the boolean formula (must not be in CNF) and writes it in the stream.
static bool s_registered
Useful to make sure the template is correctly used by the compiler.
UnaryNonCNFMethod()=delete
const unsigned int m_numberStates
The number of states in the DFA to construct.
Base class for every method that relies on a non-CNF SAT solver.
const std::set< std::string > m_Sp
The set of words to accept .
std::unique_ptr< DFA< char > > toDFA(std::istream &stream) const override
Effectively creates the DFA.