Connect++ 0.6.1
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
ClauseCopyCache.cpp
1/*
2
3Copyright © 2023-25 Sean Holden. All rights reserved.
4
5*/
6/*
7
8This file is part of Connect++.
9
10Connect++ is free software: you can redistribute it and/or modify it
11under the terms of the GNU General Public License as published by the
12Free Software Foundation, either version 3 of the License, or (at your
13option) any later version.
14
15Connect++ is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18more details.
19
20You should have received a copy of the GNU General Public License along
21with Connect++. If not, see <https://www.gnu.org/licenses/>.
22
23*/
24
25#include "ClauseCopyCache.hpp"
26
27//---------------------------------------------------------------------------
29 if (params::clause_copy_cache_start_size < 1) {
30 cerr << "params::clause_copy_cache_start_size must be at least 1" << endl;
31 exit(EXIT_FAILURE);
32 }
33 cache = vector<vector<Clause>>(size, vector<Clause>());
34 Clause new_c;
35 for (size_t i = 0; i < size; i++) {
36 for (size_t j = 0; j < params::clause_copy_cache_start_size; j++) {
37 _m.make_copy_with_new_unique_vars(i, new_c, _vi, _ti);
38 cache[i].push_back(new_c);
39 }
40 }
41 number_of_copies_available = vector<size_t>(size, params::clause_copy_cache_start_size);
42 next_copy_index = vector<size_t>(size, 0);
43 stack.clear();
44}
45//---------------------------------------------------------------------------
47 Clause& _clause, const Matrix& _m, VariableIndex& _vi,
48 TermIndex& _ti) {
49 _clause = (cache[_index])[next_copy_index[_index]++];
50 stack.push_back(_index);
51 if (next_copy_index[_index] == number_of_copies_available[_index]) {
52 number_of_copies_available[_index] += params::clause_copy_cache_increment;
53 Clause new_c;
54 for (size_t i = 0; i < params::clause_copy_cache_increment; i++) {
55 _m.make_copy_with_new_unique_vars(_index, new_c, _vi, _ti);
56 cache[_index].push_back(new_c);
57 }
58 }
59}
60//---------------------------------------------------------------------------
62 size_t i = stack.back();
63 stack.pop_back();
64 next_copy_index[i]--;
65}
66//---------------------------------------------------------------------------
68 cout << "|";
69 for (size_t count : number_of_copies_available) {
70 cout << count << "|";
71 }
72 cout << endl;
73}
74//---------------------------------------------------------------------------
75ostream& operator<<(ostream& out, const ClauseCopyCache& _cache) {
76 size_t i = 0;
77 for (const vector<Clause>& vc : _cache.cache) {
78 out << "---------------------------------------------------------------" << endl;
79 out << "Cached clauses for clause: " << i << endl;
80 out << "Copies available: " << _cache.number_of_copies_available[i] << endl;
81 out << "---------------------------------------------------------------" << endl;
82 size_t j = 0;
83 for (const Clause& c : vc) {
84 out << c;
85 if (j++ == _cache.next_copy_index[i]) {
86 out << " <-";
87 }
88 out << endl;
89 }
90 i++;
91 }
92 return out;
93}
vector< vector< Clause > > cache
Cache containing some number of copies (with unique variables, not used anywhere else) of clauses fro...
vector< size_t > next_copy_index
Index of the next available copy of each clause.
vector< size_t > stack
Each time you supply a copy, remember the action so that you can backtrack.
void make_copy_with_new_variables(size_t, Clause &, const Matrix &, VariableIndex &, TermIndex &)
If there is a copy cached, replace the parameter with it. Otherwise, use the parameter to actually ma...
void backtrack()
Backtracking is just looking at the last copy supplied and undoing that action.
vector< size_t > number_of_copies_available
How many copies of each clause, in total, are currently available? At any given time some may be avai...
void reset(const Matrix &, VariableIndex &, TermIndex &)
This is for any actual initialisation, when you either (1) intially know what you're dealing with,...
size_t size
Keep track of how many clauses there are in the matrix.
void show_counts() const
Mostly for development. See how many copies you actually ended up with.
Representation of clauses.
Definition Clause.hpp:52
Representation of the Matrix within a proof.
Definition Matrix.hpp:74
void make_copy_with_new_unique_vars(size_t, Clause &, VariableIndex &, TermIndex &) const
Make a new copy of a clause in the matrix.
Definition Matrix.cpp:309
Look after terms, using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:54
Storage of named variables, and management of new, anonymous and unique variables.