Skip to content

Commit aaa46e7

Browse files
Count number of solver calls in propt and prop_convt
Useful for logging statistics
1 parent ddbefaa commit aaa46e7

28 files changed

+236
-132
lines changed

src/solvers/prop/prop.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ bvt propt::new_variables(std::size_t width)
2525
result[i]=new_variable();
2626
return result;
2727
}
28+
29+
propt::resultt propt::prop_solve()
30+
{
31+
++number_of_solver_calls;
32+
return do_prop_solve();
33+
}
34+
35+
std::size_t propt::get_number_of_solver_calls() const
36+
{
37+
return number_of_solver_calls;
38+
}

src/solvers/prop/prop.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class propt
9595
// solving
9696
virtual const std::string solver_text()=0;
9797
enum class resultt { P_SATISFIABLE, P_UNSATISFIABLE, P_ERROR };
98-
virtual resultt prop_solve()=0;
98+
resultt prop_solve();
9999

100100
// satisfying assignment
101101
virtual tvt l_get(literalt a) const=0;
@@ -117,11 +117,16 @@ class propt
117117
log.warning() << "CPU limit ignored (not implemented)" << messaget::eom;
118118
}
119119

120+
std::size_t get_number_of_solver_calls() const;
121+
120122
protected:
123+
virtual resultt do_prop_solve() = 0;
124+
121125
// to avoid a temporary for lcnf(...)
122126
bvt lcnf_bv;
123127

124128
messaget log;
129+
std::size_t number_of_solver_calls = 0;
125130
};
126131

127132
#endif // CPROVER_SOLVERS_PROP_PROP_H

src/solvers/prop/prop_conv.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,8 @@ void prop_conv_solvert::print_assignment(std::ostream &out) const
512512
for(const auto &symbol : symbols)
513513
out << symbol.first << " = " << prop.l_get(symbol.second) << '\n';
514514
}
515+
516+
std::size_t prop_conv_solvert::get_number_of_solver_calls() const
517+
{
518+
return prop.get_number_of_solver_calls();
519+
}

src/solvers/prop/prop_conv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class prop_convt:public decision_proceduret
5555

5656
// Resource limits:
5757
virtual void set_time_limit_seconds(uint32_t) {}
58+
59+
/// Returns the number of incremental solver calls
60+
virtual std::size_t get_number_of_solver_calls() const = 0;
5861
};
5962

6063
//
@@ -122,6 +125,8 @@ class prop_conv_solvert:public prop_convt
122125
prop.set_time_limit_seconds(lim);
123126
}
124127

128+
std::size_t get_number_of_solver_calls() const override;
129+
125130
protected:
126131
virtual void post_process();
127132

src/solvers/sat/cnf_clause_list.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ class cnf_clause_listt:public cnft
2626
cnf_clause_listt() { }
2727
virtual ~cnf_clause_listt() { }
2828

29-
virtual void lcnf(const bvt &bv);
29+
void lcnf(const bvt &bv) override;
3030

31-
virtual const std::string solver_text()
31+
const std::string solver_text() override
3232
{ return "CNF clause list"; }
3333

34-
virtual tvt l_get(literalt) const
34+
tvt l_get(literalt) const override
3535
{
3636
return tvt::unknown();
3737
}
3838

39-
virtual resultt prop_solve() { return resultt::P_ERROR; }
40-
41-
virtual size_t no_clauses() const { return clauses.size(); }
39+
size_t no_clauses() const override
40+
{
41+
return clauses.size();
42+
}
4243

4344
typedef std::list<bvt> clausest;
4445

@@ -73,6 +74,11 @@ class cnf_clause_listt:public cnft
7374
}
7475

7576
protected:
77+
resultt do_prop_solve() override
78+
{
79+
return resultt::P_ERROR;
80+
}
81+
7682
clausest clauses;
7783
};
7884

@@ -89,7 +95,7 @@ class cnf_clause_list_assignmentt:public cnf_clause_listt
8995
return assignment;
9096
}
9197

92-
virtual tvt l_get(literalt literal) const
98+
tvt l_get(literalt literal) const override
9399
{
94100
if(literal.is_true())
95101
return tvt(true);

src/solvers/sat/dimacs_cnf.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ class dimacs_cnf_dumpt:public cnft
4646
explicit dimacs_cnf_dumpt(std::ostream &_out);
4747
virtual ~dimacs_cnf_dumpt() { }
4848

49-
virtual const std::string solver_text()
49+
const std::string solver_text() override
5050
{
5151
return "DIMACS CNF Dumper";
5252
}
5353

54-
virtual void lcnf(const bvt &bv);
55-
56-
virtual resultt prop_solve()
57-
{
58-
return resultt::P_ERROR;
59-
}
54+
void lcnf(const bvt &bv) override;
6055

61-
virtual tvt l_get(literalt) const
56+
tvt l_get(literalt) const override
6257
{
6358
return tvt::unknown();
6459
}
6560

66-
virtual size_t no_clauses() const
61+
size_t no_clauses() const override
6762
{
6863
return 0;
6964
}
7065

7166
protected:
67+
resultt do_prop_solve() override
68+
{
69+
return resultt::P_ERROR;
70+
}
71+
7272
std::ostream &out;
7373
};
7474

src/solvers/sat/pbs_dimacs_cnf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool pbs_dimacs_cnft::pbs_solve()
205205
return satisfied;
206206
}
207207

208-
propt::resultt pbs_dimacs_cnft::prop_solve()
208+
propt::resultt pbs_dimacs_cnft::do_prop_solve()
209209
{
210210
std::ofstream file("temp.cnf");
211211

src/solvers/sat/pbs_dimacs_cnf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ class pbs_dimacs_cnft:public dimacs_cnft
4747

4848
bool pbs_solve();
4949

50-
virtual resultt prop_solve();
51-
52-
virtual tvt l_get(literalt a) const;
50+
tvt l_get(literalt a) const override;
5351

5452
// dummy functions
5553

56-
virtual const std::string solver_text()
54+
const std::string solver_text() override
5755
{
5856
return "PBS - Pseudo Boolean/CNF Solver and Optimizer";
5957
}
6058

6159
protected:
60+
resultt do_prop_solve() override;
61+
6262
std::set<int> assigned;
6363
};
6464

src/solvers/sat/satcheck_booleforce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void satcheck_booleforce_baset::lcnf(const bvt &bv)
7979
clause_counter++;
8080
}
8181

82-
propt::resultt satcheck_booleforce_baset::prop_solve()
82+
propt::resultt satcheck_booleforce_baset::do_prop_solve()
8383
{
8484
PRECONDITION(status == SAT || status == INIT);
8585

src/solvers/sat/satcheck_booleforce.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ class satcheck_booleforce_baset:public cnf_solvert
2020
public:
2121
virtual ~satcheck_booleforce_baset();
2222

23-
virtual const std::string solver_text();
24-
virtual resultt prop_solve();
25-
virtual tvt l_get(literalt a) const;
23+
const std::string solver_text() override;
24+
tvt l_get(literalt a) const override;
2625

27-
virtual void lcnf(const bvt &bv);
26+
void lcnf(const bvt &bv) override;
27+
28+
protected:
29+
resultt do_prop_solve() override;
2830
};
2931

3032
class satcheck_booleforcet:public satcheck_booleforce_baset

src/solvers/sat/satcheck_cadical.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void satcheck_cadicalt::lcnf(const bvt &bv)
6565
clause_counter++;
6666
}
6767

68-
propt::resultt satcheck_cadicalt::prop_solve()
68+
propt::resultt satcheck_cadicalt::do_prop_solve()
6969
{
7070
INVARIANT(status != statust::ERROR, "there cannot be an error");
7171

src/solvers/sat/satcheck_cadical.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ class satcheck_cadicalt:public cnf_solvert
2323
satcheck_cadicalt();
2424
virtual ~satcheck_cadicalt();
2525

26-
virtual const std::string solver_text() override;
27-
virtual resultt prop_solve() override;
28-
virtual tvt l_get(literalt a) const override;
29-
30-
virtual void lcnf(const bvt &bv) override;
31-
virtual void set_assignment(literalt a, bool value) override;
32-
33-
virtual void set_assumptions(const bvt &_assumptions) override;
34-
virtual bool has_set_assumptions() const override { return false; }
35-
virtual bool has_is_in_conflict() const override { return false; }
36-
virtual bool is_in_conflict(literalt a) const override;
26+
const std::string solver_text() override;
27+
tvt l_get(literalt a) const override;
28+
29+
void lcnf(const bvt &bv) override;
30+
void set_assignment(literalt a, bool value) override;
31+
32+
void set_assumptions(const bvt &_assumptions) override;
33+
bool has_set_assumptions() const override
34+
{
35+
return false;
36+
}
37+
bool has_is_in_conflict() const override
38+
{
39+
return false;
40+
}
41+
bool is_in_conflict(literalt a) const override;
3742

3843
protected:
44+
resultt do_prop_solve() override;
45+
3946
// NOLINTNEXTLINE(readability/identifiers)
4047
CaDiCaL::Solver * solver;
4148
};

src/solvers/sat/satcheck_glucose.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ void satcheck_glucose_baset<T>::lcnf(const bvt &bv)
131131
}
132132
}
133133

134-
template<typename T>
135-
propt::resultt satcheck_glucose_baset<T>::prop_solve()
134+
template <typename T>
135+
propt::resultt satcheck_glucose_baset<T>::do_prop_solve()
136136
{
137137
PRECONDITION(status != statust::ERROR);
138138

src/solvers/sat/satcheck_glucose.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,30 @@ class satcheck_glucose_baset:public cnf_solvert
3030
explicit satcheck_glucose_baset(T *);
3131
virtual ~satcheck_glucose_baset();
3232

33-
virtual resultt prop_solve();
34-
virtual tvt l_get(literalt a) const;
33+
tvt l_get(literalt a) const override;
3534

36-
virtual void lcnf(const bvt &bv);
37-
virtual void set_assignment(literalt a, bool value);
35+
void lcnf(const bvt &bv) override;
36+
void set_assignment(literalt a, bool value) override;
3837

3938
// extra MiniSat feature: solve with assumptions
40-
virtual void set_assumptions(const bvt &_assumptions);
39+
void set_assumptions(const bvt &_assumptions) override;
4140

4241
// extra MiniSat feature: default branching decision
4342
void set_polarity(literalt a, bool value);
4443

45-
virtual bool is_in_conflict(literalt a) const;
46-
virtual bool has_set_assumptions() const { return true; }
47-
virtual bool has_is_in_conflict() const { return true; }
44+
bool is_in_conflict(literalt a) const override;
45+
bool has_set_assumptions() const override
46+
{
47+
return true;
48+
}
49+
bool has_is_in_conflict() const override
50+
{
51+
return true;
52+
}
4853

4954
protected:
55+
resultt do_prop_solve() override;
56+
5057
T *solver;
5158

5259
void add_variables();
@@ -58,16 +65,16 @@ class satcheck_glucose_no_simplifiert:
5865
{
5966
public:
6067
satcheck_glucose_no_simplifiert();
61-
virtual const std::string solver_text();
68+
const std::string solver_text() override;
6269
};
6370

6471
class satcheck_glucose_simplifiert:
6572
public satcheck_glucose_baset<Glucose::SimpSolver>
6673
{
6774
public:
6875
satcheck_glucose_simplifiert();
69-
virtual const std::string solver_text();
70-
virtual void set_frozen(literalt a);
76+
const std::string solver_text() override;
77+
void set_frozen(literalt a) override;
7178
bool is_eliminated(literalt a) const;
7279
};
7380

src/solvers/sat/satcheck_ipasir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void satcheck_ipasirt::lcnf(const bvt &bv)
9393
clause_counter++;
9494
}
9595

96-
propt::resultt satcheck_ipasirt::prop_solve()
96+
propt::resultt satcheck_ipasirt::do_prop_solve()
9797
{
9898
INVARIANT(status!=statust::ERROR, "there cannot be an error");
9999

src/solvers/sat/satcheck_ipasir.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,31 @@ class satcheck_ipasirt:public cnf_solvert
2222
virtual ~satcheck_ipasirt() override;
2323

2424
/// This method returns the description produced by the linked SAT solver
25-
virtual const std::string solver_text() override;
26-
27-
virtual resultt prop_solve() override;
25+
const std::string solver_text() override;
2826

2927
/// This method returns the truth value for a literal of the current SAT model
30-
virtual tvt l_get(literalt a) const override final;
28+
tvt l_get(literalt a) const override final;
3129

32-
virtual void lcnf(const bvt &bv) override final;
30+
void lcnf(const bvt &bv) override final;
3331

3432
/* This method is not supported, and currently not called anywhere in CBMC */
35-
virtual void set_assignment(literalt a, bool value) override;
33+
void set_assignment(literalt a, bool value) override;
3634

37-
virtual void set_assumptions(const bvt &_assumptions) override;
35+
void set_assumptions(const bvt &_assumptions) override;
3836

39-
virtual bool is_in_conflict(literalt a) const override;
40-
virtual bool has_set_assumptions() const override final { return true; }
41-
virtual bool has_is_in_conflict() const override final { return true; }
37+
bool is_in_conflict(literalt a) const override;
38+
bool has_set_assumptions() const override final
39+
{
40+
return true;
41+
}
42+
bool has_is_in_conflict() const override final
43+
{
44+
return true;
45+
}
4246

4347
protected:
48+
resultt do_prop_solve() override;
49+
4450
void *solver;
4551

4652
bvt assumptions;

src/solvers/sat/satcheck_lingeling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void satcheck_lingelingt::lcnf(const bvt &bv)
6363
clause_counter++;
6464
}
6565

66-
propt::resultt satcheck_lingelingt::prop_solve()
66+
propt::resultt satcheck_lingelingt::do_prop_solve()
6767
{
6868
PRECONDITION(status != ERROR);
6969

0 commit comments

Comments
 (0)