Skip to content

Commit b06e291

Browse files
committed
Better stats printing for oracle
Fixing
1 parent 0622b81 commit b06e291

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/oracle/oracle.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "oracle.h"
2424
#include "constants.h"
2525

26+
#include <cstdint>
2627
#include <iostream>
2728
#include "utils.h"
2829
using std::cout;
@@ -109,15 +110,26 @@ void Oracle::ClearSolCache() {
109110

110111
bool Oracle::SatByCache(const vector<Lit>& assumps) {
111112
const uint32_t mult = vars+1;
113+
if (stats.total_cache_lookups % 1000 == 199 && verb >= 3) {
114+
cout << "c o [oracle] cache"
115+
<< " usefulness: "
116+
<< std::setprecision(0) << std::fixed << (double)stats.cache_useful/(double)stats.total_cache_lookups*100.0 << "%"
117+
<< std::setprecision(2)
118+
<< " elements in cache: " << sol_cache.size()/mult
119+
<< " cache size distrib for lookup: " << cache_lookup[0].size() << " -- " << cache_lookup[1].size()
120+
<< endl;
121+
}
122+
123+
stats.total_cache_lookups++;
112124
assert(sol_cache.size()%mult == 0);
113125

114126
if (cache_lookup_frequencies.empty()) {
115127
cache_lookup_frequencies.resize(vars+1, 0);
116128
}
117-
assert(cache_lookup_frequencies.size() == vars+1);
129+
assert(cache_lookup_frequencies.size() == (uint32_t)vars+1);
118130

119131
for (const Lit& l : assumps) cache_lookup_frequencies[VarOf(l)]++;
120-
if ((stats.sat_by_cache_calls % 1000 == 999)) {
132+
if ((stats.total_cache_lookups % 1000 == 999)) {
121133
vector<uint32_t> occs_int(mult, 0);
122134
const uint64_t sz = sol_cache.size();
123135
for (uint64_t i = 0; i < sz; i+=mult) {
@@ -179,14 +191,7 @@ bool Oracle::SatByCache(const vector<Lit>& assumps) {
179191
if (ok) return true;
180192
}
181193
}
182-
stats.sat_by_cache_calls++;
183194
stats.mems += checks/20;
184-
if (stats.sat_by_cache_calls % 100 == 99 && verb >= 3) {
185-
cout << "c o [oracle]-cache found: " << found << " cache var: " << cache_lookup_var
186-
<< "orig sz: " << sol_cache.size()/mult
187-
<< " cache size: " << cache_lookup[0].size() << " -- " << cache_lookup[1].size()
188-
<< endl;
189-
}
190195

191196
// Not in the cache
192197
return false;

src/oracle/oracle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct Stats {
7979
int64_t restarts = 0;
8080
int64_t cache_useful = 0;
8181
int64_t cache_added = 0;
82-
int64_t sat_by_cache_calls = 0;
82+
int64_t total_cache_lookups = 0;
8383
void Print() const;
8484
};
8585

src/oracle_use.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ THE SOFTWARE.
3434
#include "time_mem.h"
3535
#include "varreplacer.h"
3636
#include "distillerbin.h"
37+
#include <iomanip>
3738

3839
using namespace CMSat;
3940

@@ -276,9 +277,9 @@ bool Solver::oracle_vivif(int fast, bool& backbone_found) {
276277
<< " T-remain: " << stats_line_percent(tot_bin_mems-oracle_bin_mems_used, tot_bin_mems) << "%"
277278
<< " T: " << std::setprecision(2) << (end_bin_tme - start_bin_time));
278279

279-
verb_print(1, "[oracle-vivif-bin]"
280-
<< " cache-used: " << oracle.getStats().cache_useful
281-
<< " cache-added: " << oracle.getStats().cache_added
280+
verb_print(1, "[oracle-vivif] cache usefulness: "
281+
<< std::setprecision(0) << std::fixed << (double)oracle.getStats().cache_useful/(double)oracle.getStats().total_cache_lookups*100.0 << "%"
282+
<< std::setprecision(2)
282283
<< " total T: " << std::setprecision(2) << (cpuTime() - start_vivif_time));
283284
return solver->okay();
284285
}
@@ -597,14 +598,20 @@ bool Solver::oracle_sparsify(bool fast)
597598

598599
//cout << "New cls size: " << clauses.size() << endl;
599600
//Subsume();
601+
//
602+
auto safe_div = [](uint32_t a, uint32_t b) {
603+
if (b == 0) return 0.0;
604+
return (double)a/(double)b*100.0;
605+
};
600606

601607
verb_print(1, "[oracle-sparsify] removed: " << removed
602608
<< " of which bin: " << removed_bin
603609
<< " tot considered: " << tot_cls
604610
<< " ccnr useful: " << ccnr_useful
605611
<< " oracle uknown: " << unknown
606-
<< " cache-used: " << oracle.getStats().cache_useful
607-
<< " cache-added: " << oracle.getStats().cache_added
612+
<< " cache useful: " << std::setprecision(0) << std::fixed
613+
<< safe_div(oracle.getStats().cache_useful, oracle.getStats().total_cache_lookups)*100.0 << "%"
614+
<< std::setprecision(2)
608615
<< " learnt-units: " << oracle.getStats().learned_units
609616
<< " T: " << (cpuTime()-my_time) << " buildT: " << build_time);
610617

0 commit comments

Comments
 (0)