Skip to content

Commit fc46f2b

Browse files
Clean up and document decision_proceduret
Complete documentation and reorder methods to make the interface more readable.
1 parent a606b13 commit fc46f2b

File tree

2 files changed

+56
-31
lines changed

2 files changed

+56
-31
lines changed

src/solvers/prop/decision_procedure.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@ Author: Daniel Kroening, [email protected]
1414
decision_proceduret::~decision_proceduret()
1515
{
1616
}
17+
18+
literalt decision_proceduret::operator()(const exprt &expr)
19+
{
20+
return convert(expr);
21+
}
22+
23+
decision_proceduret::resultt decision_proceduret::operator()()
24+
{
25+
return dec_solve();
26+
}
27+
28+
void decision_proceduret::set_to_true(const exprt &expr)
29+
{
30+
set_to(expr, true);
31+
}
32+
33+
void decision_proceduret::set_to_false(const exprt &expr)
34+
{
35+
set_to(expr, false);
36+
}

src/solvers/prop/decision_procedure.h

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,54 +23,59 @@ class tvt;
2323
class decision_proceduret
2424
{
2525
public:
26-
virtual ~decision_proceduret();
26+
/// For a Boolean expression \p expr, add the constraint 'expr' if \p value
27+
/// is `true`, otherwise add 'not expr'
28+
virtual void set_to(const exprt &expr, bool value) = 0;
2729

28-
// get a value from satisfying instance if satisfiable
29-
// returns nil if not available
30-
virtual exprt get(const exprt &expr) const=0;
30+
/// For a Boolean expression \p expr, add the constraint 'expr'
31+
void set_to_true(const exprt &expr);
3132

32-
// specialized variant of get
33-
virtual tvt l_get(literalt) const = 0;
33+
/// For a Boolean expression \p expr, add the constraint 'not expr'
34+
void set_to_false(const exprt &expr);
3435

35-
// print satisfying assignment
36-
virtual void print_assignment(std::ostream &out) const=0;
36+
/// Convert a Boolean expression and return the corresponding literal
37+
virtual literalt convert(const exprt &expr) = 0;
3738

38-
// add constraints
39-
// the expression must be of Boolean type
40-
virtual void set_to(const exprt &expr, bool value)=0;
39+
/// Convert a Boolean expression and return the corresponding literal
40+
literalt operator()(const exprt &);
4141

42-
void set_to_true(const exprt &expr)
43-
{ set_to(expr, true); }
42+
/// Result of running the decision procedure
43+
enum class resultt
44+
{
45+
D_SATISFIABLE,
46+
D_UNSATISFIABLE,
47+
D_ERROR
48+
};
4449

45-
void set_to_false(const exprt &expr)
46-
{ set_to(expr, false); }
50+
/// Run the decision procedure to solve the problem
51+
resultt operator()();
4752

48-
// conversion to handle
49-
virtual literalt convert(const exprt &expr) = 0;
53+
/// Return \p expr with variables replaced by values from satisfying
54+
/// assignment if available.
55+
/// Return `nil` if not available
56+
virtual exprt get(const exprt &expr) const = 0;
5057

51-
literalt operator()(const exprt &expr)
52-
{
53-
return convert(expr);
54-
}
58+
/// Return value of literal \p l from satisfying assignment.
59+
/// Return tvt::UNKNOWN if not available
60+
virtual tvt l_get(literalt l) const = 0;
5561

56-
// solve the problem
57-
enum class resultt { D_SATISFIABLE, D_UNSATISFIABLE, D_ERROR };
62+
/// Print satisfying assignment to \p out
63+
virtual void print_assignment(std::ostream &out) const = 0;
5864

59-
resultt operator()()
60-
{
61-
return dec_solve();
62-
}
63-
64-
// return a textual description of the decision procedure
65-
virtual std::string decision_procedure_text() const=0;
65+
/// Return a textual description of the decision procedure
66+
virtual std::string decision_procedure_text() const = 0;
6667

67-
/// Returns the number of incremental solver calls
68+
/// Return the number of incremental solver calls
6869
virtual std::size_t get_number_of_solver_calls() const = 0;
6970

71+
virtual ~decision_proceduret();
72+
7073
protected:
74+
/// Run the decision procedure to solve the problem
7175
virtual resultt dec_solve() = 0;
7276
};
7377

78+
/// Push Boolean constraint \p src into decision procedure \p dest
7479
inline decision_proceduret &operator<<(
7580
decision_proceduret &dest,
7681
const exprt &src)

0 commit comments

Comments
 (0)