-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSATFormulae.cpp
93 lines (80 loc) · 1.91 KB
/
SATFormulae.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @file SATFormulae.cpp
* @class SATFormulae
* @brief Class encompassing a list of `OrClause` linked by and operators
* @author Federico Cerutti <[email protected]>
* @copyright GNU Public License v2
*/
#include "SATFormulae.h"
/**
* @brief Simple constructor
*/
SATFormulae::SATFormulae()
{
this->clauses_and = vector<OrClause>();
}
/**
* @brief Method for appending a new OrClause to the other clause
* @param[in] c The OrClause to append
* @retval void
*/
void SATFormulae::appendOrClause(OrClause c)
{
this->clauses_and.push_back(c);
}
/**
* @brief Method for transforming the SAT formulae into a string `DIMACS` compliant
* @param[out] ss A pointer to a stringstream object already initialised
* @retval void
*/
void SATFormulae::toSS(stringstream *ss) const
{
string newline = "\n";
for (int i = 0; i < (int) this->clauses_and.size(); i++)
{
(*ss) << this->clauses_and.at(i);
if (i != (int) this->clauses_and.size() - 1)
(*ss) << newline;
}
}
ostream& operator<<(ostream& out, const SATFormulae& r)
{
stringstream ss(stringstream::in | stringstream::out);
r.toSS(&ss);
out << ss.str();
return out;
}
/**
* @brief Method returning the number of OrClause
* @retval int The number of OrClause
*/
int SATFormulae::size()
{
return (int) this->clauses_and.size();
}
/**
* @brief Method for cloning (not coping the pointers) this object into a new one
* @param[out] newsat A pointer to an initialised SATFormulae() object which will contain the copy of this object
* @retval void
*/
void SATFormulae::clone(SATFormulae *newsat)
{
(*newsat) = SATFormulae();
for (int i = 0; i < this->size(); i++)
{
OrClause newor = OrClause();
this->clauses_and.at(i).clone(&newor);
(*newsat).appendOrClause(newor);
}
}
/**
* @brief Check if there are no formulae
* @retval bool
*/
bool SATFormulae::empty()
{
return this->clauses_and.empty();
}
SATFormulae::~SATFormulae()
{
}