27std::mt19937
Matrix::d(params::random_seed);
32, index((num_predicates * 2), vector<MatrixPairType>())
33, literal_clause_index((num_predicates * 2), vector<LiteralClausePairType>())
45 index = vector<vector<MatrixPairType> >((num_predicates * 2), vector<MatrixPairType>());
46 literal_clause_index = vector<vector<LiteralClausePairType> >((num_predicates * 2), vector<LiteralClausePairType>());
55 bool found_positive =
false;
56 bool found_negative =
false;
57 size_t first_positive = 0;
58 size_t first_negative = 0;
59 bool found_candidate =
false;
64 if (!found_positive) {
66 found_positive =
true;
70 if (!found_negative) {
72 found_negative =
true;
78 found_candidate =
true;
84 if (!(found_positive && found_negative))
85 return pair<bool,size_t>(
false, 0);
87 return pair<bool, size_t>(
true, candidate);
88 else if (params::positive_representation)
89 return pair<bool, size_t>(
true, first_positive);
91 return pair<bool, size_t>(
true, first_negative);
98 ClauseNum clause_number =
clauses.size();
99 LitNum literal_number = 0;
100 for (
size_t j = 0; j < clause.
size(); j++) {
101 size_t i = clause[j].get_pred_as_index();
102 index[i].push_back(MatrixPairType(clause_number, literal_number));
103 Clause new_clause = clause;
122 size_t s2 =
index.size();
126 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
127 literal_clause_index = vector<vector<LiteralClausePairType> >(s3, vector<LiteralClausePairType>());
128 for (
size_t i = 0; i < s; i++) {
144 vector<uint32_t> new_order;
146 for (
size_t i = 0; i < s; i++)
147 new_order.push_back(i);
148 new_order = deterministic_reorder_n_times<uint32_t>(new_order, n);
154 for (
size_t i = 0; i < s; i++) {
165 vector<Clause> saved_clauses(
clauses);
170 vector<uint32_t> new_order;
172 for (
size_t i = 0; i < s; i++)
173 new_order.push_back(i);
174 std::shuffle(new_order.begin(), new_order.end(),
d);
180 for (
size_t i = 0; i < s; i++) {
181 cs.push_back(saved_clauses[new_order[i]]);
182 ss.push_back(saved_clause_roles[new_order[i]]);
191 vector<Clause> saved_clauses(
clauses);
197 for (
size_t i = 0; i < s; i++) {
198 Clause c(saved_clauses[i]);
200 saved_clauses[i] = c;
210 cerr <<
"Why are you trying to move equality axioms - there aren't any?" << endl;
219 size_t s2 =
index.size();
223 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
224 literal_clause_index = vector<vector<LiteralClausePairType> >(s3, vector<LiteralClausePairType>());
226 for (
size_t i = n_clauses -
num_equals; i < n_clauses; i++) {
229 for (
size_t i = 0; i < n_clauses -
num_equals; i++) {
242 result += cs(
"*").orange();
246 result += cs(
"+").orange();
248 result += cs(
"-").orange();
253 result += c.to_string();
260 string s (
"\\[\n\\begin{split}\n");
261 s +=
"\\textcolor{magenta}{M} = ";
264 s += c.make_LaTeX(subbed);
267 s +=
"\n\\end{split}\n\\]\n";
273 std::ofstream file(path_to_file);
277 file <<
":- style_check(-singleton)." << std::endl;
280 file << std::to_string(matrix_i++);
282 file << c.to_prolog_string();
292 cout <<
"cnf(matrix-";
293 cout << std::to_string(matrix_i++);
295 cout << c.to_tptp_string();
304 _clause = result.second;
307ostream& operator<<(ostream& out,
const Matrix& m) {
308 out <<
"Clauses in matrix:" << endl;
309 out <<
"------------------" << endl;
311 for (
const Clause& c : m.clauses) {
312 out << setw(params::output_width) << i
319 vector<string> index_lits(m.
index.size(),
string(
""));
320 for (
Clause c : m.clauses)
321 for (size_t i = 0; i < c.size(); i++)
322 index_lits[c[i].get_pred_as_index()] = c[i].get_small_lit();
324 out << endl <<
"Index: (Clause, Literal):" << endl;
325 out <<
"-------------------------" << endl;
326 for (vector<MatrixPairType> v : m.index) {
327 out << setw(params::output_width + 20) << index_lits[i++] <<
": ";
328 for (MatrixPairType p : v) {
329 out <<
"(" << p.first <<
", " << p.second <<
") ";
333 out << endl <<
"Index: (Literal, Clause without Literal):" << endl;
334 out <<
"-----------------------------------------" << endl;
336 for (vector<LiteralClausePairType> v : m.literal_clause_index) {
337 out << setw(params::output_width + 20) << index_lits[i++] <<
": " << endl;;
338 for (LiteralClausePairType p : v) {
339 out << p.first.to_string() <<
" --- " << p.second.to_string() << endl;
Representation of clauses.
void random_reorder()
Randomly re-order the literals.
bool is_positive() const
A clause is positive if it has no negated literals.
size_t size() const
Straightforward get method.
bool is_negative() const
A clause is negative if it has only negated literals.
bool is_ground() const
Is this a ground clause?
void drop_literal(LitNum)
Get rid of the specified Literal.
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Representation of the Matrix within a proof.
string to_string() const
Make a string representation.
void rebuild_index(vector< Clause > &, vector< string > &)
Rebuild the index after, for example, reordering.
vector< Clause > clauses
The Matrix itself is just a set of Clauses.
void deterministic_reorder(size_t)
Deterministic reorder of the clauses.
void move_equals_to_start()
Self-explanatory.
string make_LaTeX(bool=false) const
Make a usable LaTeX representation.
vector< string > clause_roles
Keep track of which clauses are conjectures etc.
void make_clauses_copy()
Store a copy of the clauses.
Matrix()
Use this constructor if you really want an empty Matrix.
void get_literal_clause_pair(LitNum, size_t, Literal &, Clause &) const
Get a literal and clause from the index.
uint32_t num_equals
You need to know how many equality axioms there are in case you want to move them around.
vector< vector< MatrixPairType > > index
We want to be able to quickly identify where in each clause a particular literal lives.
void add_clause(Clause &, string="")
Add a Clause to the Matrix and update the index accordingly.
bool copy_saved
Remember whether you've saved a copy.
static std::mt19937 d
Randomness for random reordering.
bool is_conjecture(size_t i) const
Is a particular Clause a conjecture?
vector< string > roles_copy
It makes sense to keep a copy of the roles if your schedule reorders multiple times.
void write_to_prolog_file(const path &) const
Write to a file that can be read by Prolog.
void random_reorder_literals()
Randomly reorder the literals in each clause in the matrix.
void show_tptp() const
Output in TPTP compatible format.
vector< Clause > clauses_copy
It makes sense to keep a copy of the clauses if your schedule reorders multiple times.
void set_num_preds(size_t)
Make an empty index.
vector< vector< LiteralClausePairType > > literal_clause_index
This corresponds closely to index, but has the actual Literal, and the Clause after the Literal's rem...
pair< bool, size_t > find_start() const
Use a simple heuristic to find a good start clause.
void random_reorder()
Randomly reorder the matrix.
vector< bool > negative_clauses
Keep track of which clauses are negative.
vector< bool > ground_clauses
We need to know this to control backtracking.
vector< bool > positive_clauses
Keep track of which clauses are positive.
Simple addition of colour to strings and ostreams.