CBMC
cnf_clause_list.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: CNF Generation
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_SOLVERS_SAT_CNF_CLAUSE_LIST_H
13 #define CPROVER_SOLVERS_SAT_CNF_CLAUSE_LIST_H
14 
15 #include <list>
16 
17 #include <util/threeval.h>
18 
19 #include "cnf.h"
20 
21 // CNF given as a list of clauses
22 
23 class cnf_clause_listt:public cnft
24 {
25 public:
26  explicit cnf_clause_listt(message_handlert &message_handler)
27  : cnft(message_handler)
28  {
29  }
30  virtual ~cnf_clause_listt() { }
31 
32  void lcnf(const bvt &bv) override;
33 
34  std::string solver_text() const override
35  { return "CNF clause list"; }
36 
37  tvt l_get(literalt) const override
38  {
39  return tvt::unknown();
40  }
41 
42  size_t no_clauses() const override
43  {
44  return clauses.size();
45  }
46 
47  typedef std::list<bvt> clausest;
48 
49  clausest &get_clauses() { return clauses; }
50 
51  void copy_to(cnft &cnf) const
52  {
54  for(clausest::const_iterator
55  it=clauses.begin();
56  it!=clauses.end();
57  it++)
58  cnf.lcnf(*it);
59  }
60 
61  static size_t hash_clause(const bvt &bv)
62  {
63  size_t result=0;
64  for(bvt::const_iterator it=bv.begin(); it!=bv.end(); it++)
65  result=((result<<2)^it->get())-result;
66 
67  return result;
68  }
69 
70  size_t hash() const
71  {
72  size_t result=0;
73  for(clausest::const_iterator it=clauses.begin(); it!=clauses.end(); it++)
74  result=((result<<2)^hash_clause(*it))-result;
75 
76  return result;
77  }
78 
79 protected:
80  resultt do_prop_solve(const bvt &) override
81  {
82  return resultt::P_ERROR;
83  }
84 
86 };
87 
88 // CNF given as a list of clauses
89 // PLUS an assignment to the variables
90 
92 {
93 public:
94  explicit cnf_clause_list_assignmentt(message_handlert &message_handler)
95  : cnf_clause_listt(message_handler)
96  {
97  }
98 
99  typedef std::vector<tvt> assignmentt;
100 
102  {
103  return assignment;
104  }
105 
106  tvt l_get(literalt literal) const override
107  {
108  if(literal.is_true())
109  return tvt(true);
110  if(literal.is_false())
111  return tvt(false);
112 
113  unsigned v=literal.var_no();
114 
115  if(v==0 || v>=assignment.size())
116  return tvt::unknown();
117 
118  tvt r=assignment[v];
119  return literal.sign()?!r:r;
120  }
121 
122  virtual void copy_assignment_from(const propt &prop);
123  void print_assignment(std::ostream &out) const;
124 
125 protected:
127 };
128 
129 #endif // CPROVER_SOLVERS_SAT_CNF_CLAUSE_LIST_H
tvt l_get(literalt literal) const override
virtual void copy_assignment_from(const propt &prop)
std::vector< tvt > assignmentt
cnf_clause_list_assignmentt(message_handlert &message_handler)
void print_assignment(std::ostream &out) const
tvt l_get(literalt) const override
std::list< bvt > clausest
virtual ~cnf_clause_listt()
size_t no_clauses() const override
resultt do_prop_solve(const bvt &) override
static size_t hash_clause(const bvt &bv)
cnf_clause_listt(message_handlert &message_handler)
void copy_to(cnft &cnf) const
std::string solver_text() const override
size_t hash() const
void lcnf(const bvt &bv) override
clausest & get_clauses()
Definition: cnf.h:18
virtual void set_no_variables(size_t no)
Definition: cnf.h:43
size_t _no_variables
Definition: cnf.h:57
bool is_true() const
Definition: literal.h:156
bool sign() const
Definition: literal.h:88
var_not var_no() const
Definition: literal.h:83
bool is_false() const
Definition: literal.h:161
TO_BE_DOCUMENTED.
Definition: prop.h:25
void lcnf(literalt l0, literalt l1)
Definition: prop.h:58
resultt
Definition: prop.h:101
Definition: threeval.h:20
static tvt unknown()
Definition: threeval.h:33
CNF Generation, via Tseitin.
static int8_t r
Definition: irep_hash.h:60
std::vector< literalt > bvt
Definition: literal.h:201