Skip to content

Commit 4af7aa1

Browse files
authored
Merge pull request #4218 from peterschrammel/count-solver-calls
Add counting number of solver calls
2 parents 59fce5a + 36feadd commit 4af7aa1

33 files changed

+233
-131
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
@@ -97,7 +97,7 @@ class propt
9797
// solving
9898
virtual const std::string solver_text()=0;
9999
enum class resultt { P_SATISFIABLE, P_UNSATISFIABLE, P_ERROR };
100-
virtual resultt prop_solve()=0;
100+
resultt prop_solve();
101101

102102
// satisfying assignment
103103
virtual tvt l_get(literalt a) const=0;
@@ -119,11 +119,16 @@ class propt
119119
log.warning() << "CPU limit ignored (not implemented)" << messaget::eom;
120120
}
121121

122+
std::size_t get_number_of_solver_calls() const;
123+
122124
protected:
125+
virtual resultt do_prop_solve() = 0;
126+
123127
// to avoid a temporary for lcnf(...)
124128
bvt lcnf_bv;
125129

126130
messaget log;
131+
std::size_t number_of_solver_calls = 0;
127132
};
128133

129134
#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
@@ -29,19 +29,20 @@ class cnf_clause_listt:public cnft
2929
}
3030
virtual ~cnf_clause_listt() { }
3131

32-
virtual void lcnf(const bvt &bv);
32+
void lcnf(const bvt &bv) override;
3333

34-
virtual const std::string solver_text()
34+
const std::string solver_text() override
3535
{ return "CNF clause list"; }
3636

37-
virtual tvt l_get(literalt) const
37+
tvt l_get(literalt) const override
3838
{
3939
return tvt::unknown();
4040
}
4141

42-
virtual resultt prop_solve() { return resultt::P_ERROR; }
43-
44-
virtual size_t no_clauses() const { return clauses.size(); }
42+
size_t no_clauses() const override
43+
{
44+
return clauses.size();
45+
}
4546

4647
typedef std::list<bvt> clausest;
4748

@@ -76,6 +77,11 @@ class cnf_clause_listt:public cnft
7677
}
7778

7879
protected:
80+
resultt do_prop_solve() override
81+
{
82+
return resultt::P_ERROR;
83+
}
84+
7985
clausest clauses;
8086
};
8187

@@ -97,7 +103,7 @@ class cnf_clause_list_assignmentt:public cnf_clause_listt
97103
return assignment;
98104
}
99105

100-
virtual tvt l_get(literalt literal) const
106+
tvt l_get(literalt literal) const override
101107
{
102108
if(literal.is_true())
103109
return tvt(true);

src/solvers/sat/dimacs_cnf.h

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

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

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

60-
virtual tvt l_get(literalt) const
55+
tvt l_get(literalt) const override
6156
{
6257
return tvt::unknown();
6358
}
6459

65-
virtual size_t no_clauses() const
60+
size_t no_clauses() const override
6661
{
6762
return 0;
6863
}
6964

7065
protected:
66+
resultt do_prop_solve() override
67+
{
68+
return resultt::P_ERROR;
69+
}
70+
7171
std::ostream &out;
7272
};
7373

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
@@ -48,18 +48,18 @@ class pbs_dimacs_cnft:public dimacs_cnft
4848

4949
bool pbs_solve();
5050

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

5553
// dummy functions
5654

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

6260
protected:
61+
resultt do_prop_solve() override;
62+
6363
std::set<int> assigned;
6464
};
6565

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
satcheck_glucose_baset(T *, message_handlert &message_handler);
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
explicit satcheck_glucose_no_simplifiert(message_handlert &message_handler);
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
explicit satcheck_glucose_simplifiert(message_handlert &message_handler);
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)