CBMC
prop_conv_solver.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_SOLVERS_PROP_PROP_CONV_SOLVER_H
10 #define CPROVER_SOLVERS_PROP_PROP_CONV_SOLVER_H
11 
12 #include <map>
13 #include <string>
14 
15 #include <util/expr.h>
16 #include <util/message.h>
17 
20 
21 #include "prop.h"
22 #include "prop_conv.h"
23 #include "solver_resource_limits.h"
24 
25 class equal_exprt;
26 
28  public prop_convt,
30 {
31 public:
32  prop_conv_solvert(propt &_prop, message_handlert &message_handler)
33  : prop(_prop), log(message_handler)
34  {
35  }
36 
37  virtual ~prop_conv_solvert() = default;
38 
39  // non-iterative eager conversion
40  virtual void finish_eager_conversion();
41 
42  // overloading from decision_proceduret
44  void print_assignment(std::ostream &out) const override;
45  std::string decision_procedure_text() const override;
46  exprt get(const exprt &expr) const override;
47 
48  tvt l_get(literalt a) const override
49  {
50  return prop.l_get(a);
51  }
52 
53  exprt handle(const exprt &expr) override;
54 
55  void set_frozen(literalt);
56  void set_frozen(const bvt &);
57  void set_all_frozen();
58 
59  literalt convert(const exprt &expr) override;
60  bool is_in_conflict(const exprt &expr) const override;
61 
65  void set_to(const exprt &expr, bool value) override;
66 
67  void push() override;
68 
70  void push(const std::vector<exprt> &assumptions) override;
71 
72  void pop() override;
73 
74  bool use_cache = true;
75  bool equality_propagation = true;
76  bool freeze_all = false; // freezing variables (for incremental solving)
77 
78  virtual void clear_cache()
79  {
80  cache.clear();
81  }
82 
83  typedef std::map<irep_idt, literalt> symbolst;
84  typedef std::unordered_map<exprt, literalt, irep_hash> cachet;
85 
86  const cachet &get_cache() const
87  {
88  return cache;
89  }
90  const symbolst &get_symbols() const
91  {
92  return symbols;
93  }
94 
95  void set_time_limit_seconds(uint32_t lim) override
96  {
98  }
99 
100  std::size_t get_number_of_solver_calls() const override;
101 
103  {
104  return dynamic_cast<hardness_collectort *>(&prop);
105  }
106 
107 protected:
108  bool post_processing_done = false;
109 
113  virtual std::optional<bool> get_bool(const exprt &expr) const;
114 
115  virtual literalt convert_rest(const exprt &expr);
116  virtual literalt convert_bool(const exprt &expr);
117 
118  virtual bool set_equality_to_true(const equal_exprt &expr);
119 
120  // symbols
122 
123  virtual literalt get_literal(const irep_idt &symbol);
124 
125  // cache
127 
128  virtual void ignoring(const exprt &expr);
129 
131 
133 
134  static const char *context_prefix;
135 
138 
140  std::size_t context_literal_counter = 0;
141 
144  std::vector<size_t> context_size_stack;
145 
146 private:
149  void add_constraints_to_prop(const exprt &expr, bool value);
150 };
151 
152 #endif // CPROVER_SOLVERS_PROP_PROP_CONV_SOLVER_H
resultt
Result of running the decision procedure.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Equality.
Definition: std_expr.h:1361
Base class for all expressions.
Definition: expr.h:56
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
void pop() override
Pop whatever is on top of the stack.
virtual bool set_equality_to_true(const equal_exprt &expr)
virtual literalt convert_bool(const exprt &expr)
decision_proceduret::resultt dec_solve(const exprt &) override
Implementation of the decision procedure.
void set_frozen(literalt)
std::vector< size_t > context_size_stack
assumption_stack is segmented in contexts; Number of assumptions in each context on the stack
std::size_t context_literal_counter
To generate unique literal names for contexts.
std::size_t get_number_of_solver_calls() const override
Return the number of incremental solver calls.
virtual void clear_cache()
prop_conv_solvert(propt &_prop, message_handlert &message_handler)
virtual void finish_eager_conversion()
std::map< irep_idt, literalt > symbolst
virtual literalt get_literal(const irep_idt &symbol)
hardness_collectort * get_hardness_collector()
std::string decision_procedure_text() const override
Return a textual description of the decision procedure.
virtual void ignoring(const exprt &expr)
const symbolst & get_symbols() const
virtual ~prop_conv_solvert()=default
const cachet & get_cache() const
void set_time_limit_seconds(uint32_t lim) override
Set the limit for the solver to time out in seconds.
tvt l_get(literalt a) const override
Return value of literal l from satisfying assignment.
void add_constraints_to_prop(const exprt &expr, bool value)
Helper method used by set_to for adding the constraints to prop.
void push() override
Push a new context on the stack This context becomes a child context nested in the current context.
virtual std::optional< bool > get_bool(const exprt &expr) const
Get a boolean value from the model if the formula is satisfiable.
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
bvt assumption_stack
Assumptions on the stack.
virtual literalt convert_rest(const exprt &expr)
std::unordered_map< exprt, literalt, irep_hash > cachet
void set_to(const exprt &expr, bool value) override
For a Boolean expression expr, add the constraint 'current_context => expr' if value is true,...
exprt handle(const exprt &expr) override
Generate a handle, which is an expression that has the same value as the argument in any model that i...
static const char * context_prefix
bool is_in_conflict(const exprt &expr) const override
Returns true if an expression is in the final conflict leading to UNSAT.
void print_assignment(std::ostream &out) const override
Print satisfying assignment to out.
TO_BE_DOCUMENTED.
Definition: prop.h:25
virtual tvt l_get(literalt a) const =0
virtual void set_time_limit_seconds(uint32_t)
Definition: prop.h:120
Definition: threeval.h:20
Capability to check whether an expression is a reason for the solver returning UNSAT.
Capability to collect the statistics of the complexity of individual solver queries.
std::vector< literalt > bvt
Definition: literal.h:201
Solver capability to set resource limits.