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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/******************************************
Copyright (C) 2009-2020 Authors of CryptoMiniSat, see AUTHORS file
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
***********************************************/
#ifndef SCCFINDER_H
#define SCCFINDER_H
#include "clause.h"
#include <stack>
#include <set>
namespace CMSat {
class Solver;
class SCCFinder {
public:
explicit SCCFinder(Solver* _solver);
bool performSCC(uint64_t* bogoprops_given = NULL);
const std::set<BinaryXor>& get_binxors() const;
size_t get_num_binxors_found() const;
void clear_binxors();
struct Stats
{
void clear()
{
Stats _tmp;
*this = _tmp;
}
uint64_t numCalls = 0;
double cpu_time = 0.0;
uint64_t foundXors = 0;
uint64_t foundXorsNew = 0;
uint64_t bogoprops = 0;
Stats& operator+=(const Stats& other)
{
numCalls += other.numCalls;
cpu_time += other.cpu_time;
foundXors += other.foundXors;
foundXorsNew += other.foundXorsNew;
bogoprops += other.bogoprops;
return *this;
}
void print() const
{
cout << "c ----- SCC STATS --------" << endl;
print_stats_line("c time"
, cpu_time
, float_div(cpu_time, numCalls)
, "per call"
);
print_stats_line("c called"
, numCalls
, float_div(foundXorsNew, numCalls)
, "new found per call"
);
print_stats_line("c found"
, foundXorsNew
, stats_line_percent(foundXorsNew, foundXors)
, "% of all found"
);
print_stats_line("c bogoprops"
, bogoprops
, "% of all found"
);
cout << "c ----- SCC STATS END --------" << endl;
}
void print_short(Solver* solver) const;
};
const Stats& get_stats() const;
size_t mem_used() const;
bool depth_warning_triggered() const;
private:
void tarjan(const uint32_t vertex);
bool depth_warning_issued;
void doit(const Lit lit, const uint32_t vertex);
void add_bin_xor_in_tmp();
//temporaries
uint32_t globalIndex;
vector<uint32_t> index;
vector<uint32_t> lowlink;
std::stack<uint32_t, vector<uint32_t> > stack;
vector<char> stackIndicator;
vector<uint32_t> tmp;
uint32_t depth;
Solver* solver;
std::set<BinaryXor> binxors;
//Stats
Stats runStats;
Stats globalStats;
};
inline void SCCFinder::doit(const Lit lit, const uint32_t vertex) {
// Was successor v' visited?
if (index[lit.toInt()] == std::numeric_limits<uint32_t>::max()) {
tarjan(lit.toInt());
depth--;
lowlink[vertex] = std::min(lowlink[vertex], lowlink[lit.toInt()]);
} else if (stackIndicator[lit.toInt()]) {
lowlink[vertex] = std::min(lowlink[vertex], lowlink[lit.toInt()]);
}
}
inline bool SCCFinder::depth_warning_triggered() const
{
return depth_warning_issued;
}
inline const SCCFinder::Stats& SCCFinder::get_stats() const
{
return globalStats;
}
inline const std::set<BinaryXor>& SCCFinder::get_binxors() const
{
return binxors;
}
inline size_t SCCFinder::get_num_binxors_found() const
{
return binxors.size();
}
inline void SCCFinder::clear_binxors()
{
binxors.clear();
}
} //end namespaceC
#endif //SCCFINDER_H