-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevalMiniSAT.cpp
More file actions
49 lines (40 loc) · 1.37 KB
/
evalMiniSAT.cpp
File metadata and controls
49 lines (40 loc) · 1.37 KB
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
#include <iostream>
#include <filesystem>
#include <chrono>
#include <minisat/core/Solver.h>
#include <minisat/core/Dimacs.h>
#include <zlib.h>
namespace fs = std::filesystem;
int main() {
std::string dir = "cnfFiles/examples";
std::vector<std::string> files;
for (auto& entry : fs::directory_iterator(dir)) {
if (entry.path().extension() == ".cnf") {
files.push_back(entry.path().string());
}
}
std::sort(files.begin(), files.end());
double totalSolveTime = 0.0;
for (const auto& filepath : files) {
std::cout << "=== " << filepath << " ===" << std::endl;
Minisat::Solver solver;
gzFile in = gzopen(filepath.c_str(), "rb");
if (in == NULL) {
std::cerr << "Skipping " << filepath << std::endl;
continue;
}
Minisat::parse_DIMACS(in, solver);
gzclose(in);
auto start = std::chrono::high_resolution_clock::now();
bool sat = solver.solve();
auto end = std::chrono::high_resolution_clock::now();
double elapsed = std::chrono::duration<double>(end - start).count();
totalSolveTime += elapsed;
std::cout << "Result: " << (sat ? "SAT" : "UNSAT") << std::endl;
std::cout << "Iterations: " << solver.decisions << std::endl;
std::cout << "Time: " << elapsed << "s" << std::endl;
std::cout << std::endl;
}
std::cout << "=== Total solver time: " << totalSolveTime << "s ===" << std::endl;
return 0;
}