15 #include <boost/algorithm/string.hpp> 20 HeuleVerwerNonCNFMethod::HeuleVerwerNonCNFMethod(
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) :
35 std::string formula =
"";
46 formula +=
"! ( d_" + std::to_string(p) +
"_" + a +
"_" + std::to_string(q) +
47 " & d_" + std::to_string(p) +
"_" + a +
"_" + std::to_string(r) +
" )";
52 formula = formula.substr(0, formula.length() - 3);
55 formula = formula.substr(0, formula.length() - 3);
59 formula = formula.substr(0, formula.length() - 3);
69 formula +=
"x_" + u +
"_" + std::to_string(q);
70 if (q != m_numberStates - 1){
77 formula = formula.substr(0, formula.length() - 3);
82 for (
const auto &ua : m_prefixes) {
84 const std::string &u = ua.substr(0, ua.size() - 1);
85 const char &a = ua.at(ua.size() - 1);
89 formula +=
"( ( x_" + u +
"_" + std::to_string(p) +
90 " & d_" + std::to_string(p) +
"_" + a +
"_" + std::to_string(q) +
" ) -> x_" +
91 ua +
"_" + std::to_string(q) +
" )";
98 formula = formula.substr(0, formula.length() - 3);
104 for (
const auto &u :
m_Sp){
105 formula +=
"( x_" + u +
"_" + std::to_string(q) +
" -> f_" + std::to_string(q) +
" )";
109 for (
const auto &u :
m_Sm){
110 formula +=
"( x_" + u +
"_" + std::to_string(q) +
" -> ! f_" + std::to_string(q) +
" )";
115 formula = formula.substr(0, formula.length() - 3);
124 formula +=
"d_" + std::to_string(p) +
"_" + a +
"_" + std::to_string(q);
127 formula = formula.substr(0, formula.length() - 3);
132 formula = formula.substr(0, formula.length() - 3);
137 for (
const auto &u : m_prefixes) {
141 formula +=
"( ! ( x_" + u +
"_" + std::to_string(p) +
" & x_" +
142 u +
"_" + std::to_string(q) +
" ) )";
149 formula = formula.substr(0, formula.length() - 3);
154 for (
const auto &ua : m_prefixes) {
156 const std::string &u = ua.substr(0, ua.size() - 1);
157 const char &a = ua.at(ua.size() - 1);
161 formula +=
"( ( x_" + u +
"_" + std::to_string(p) +
" & " +
"x_" + ua +
"_" + std::to_string(q) +
" ) " 162 +
"-> d_" + std::to_string(p) +
"_" + a +
"_" + std::to_string(q) +
" ) ";
169 formula = formula.substr(0, formula.length() - 3);
181 std::vector<std::vector<std::string>> d_vars;
182 std::vector<unsigned int> f_vars;
184 std::unique_ptr<DFA<char>> dfa;
186 while(std::getline(stream, line)){
188 if (line.at(0) ==
'x'){
189 std::vector<std::string> results;
190 std::vector<std::string> results_2;
192 boost::split(results, line, [](
char c){
return c ==
' ';});
194 boost::split(results_2, results[0], [](
char c){
return c ==
'_';});
197 if (std::stoi(results[2]) == 1 && results_2[1] ==
""){
198 dfa = std::make_unique<DFA<char>>(std::stoi(results_2[2]),
m_Sp.find(
"") !=
m_Sp.end());
201 if (line.at(0) ==
'd'){
202 std::vector<std::string> results;
203 std::vector<std::string> results_2;
205 boost::split(results, line, [](
char c){
return c ==
' ';});
207 boost::split(results_2, results[0], [](
char c){
return c ==
'_';});
210 if(std::stoi(results[2]) == 1){
211 std::vector<std::string> my_vec;
212 my_vec.push_back(results_2[1]);
213 my_vec.push_back(results_2[2]);
214 my_vec.push_back(results_2[3]);
215 d_vars.push_back(my_vec);
218 if (line.at(0) ==
'f'){
219 std::vector<std::string> results;
220 std::vector<std::string> results_2;
222 boost::split(results, line, [](
char c){
return c ==
' ';});
224 boost::split(results_2, results[0], [](
char c){
return c ==
'_';});
227 if (std::stoi(results[2]) == 1){
228 f_vars.push_back(std::stoi(results_2[1]));
234 if(std::find(f_vars.begin(), f_vars.end(), i) != f_vars.end()){
235 dfa->addState(i,
true);
238 dfa->addState(i,
false);
242 for(
const auto &vec : d_vars){
243 const char *a = vec.at(1).c_str();
244 dfa->addTransition(std::stoi(vec.at(0)), a[0], std::stoi(vec.at(2)));
const std::set< char > m_alphabet
The namespace of the library.
const std::set< std::string > m_Sm
The set of words to reject .
const std::set< std::string > m_prefixes
This file declares the Heule and Verwer method that relies on non CNF SAT solver. ...
HeuleVerwerNonCNFMethod()=delete
std::unique_ptr< DFA< char > > toDFA(std::istream &stream) const override
Effectively creates the DFA.
static bool s_registered
Useful to make sure the template is correctly used by the compiler.
virtual std::string getFileName() const override
Gives the name of the file in which the boolean formula must be written.
virtual bool createFormula(std::ostream &stream) override
Creates the boolean formula (must not be in CNF) and writes it in the stream.
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 .
~HeuleVerwerNonCNFMethod()
static std::string getFactoryName()