CBMC
satcheck_zcore.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "satcheck_zcore.h"
10 
11 #include <fstream>
12 
13 #include <util/invariant.h>
14 #include <util/string2int.h>
15 
16 #include <cstring>
17 
19 {
20 }
21 
23 {
24 }
25 
27 {
30 }
31 
32 const std::string satcheck_zcoret::solver_text()
33 {
34  return "ZCore";
35 }
36 
38 {
39  // We start counting at 1, thus there is one variable fewer.
40  {
41  std::string msg=
42  std::to_string(no_variables()-1)+" variables, "+
43  std::to_string(no_clauses())+" clauses";
44  log.statistics() << msg << messaget::eom;
45  }
46 
47  // get the core
48  std::string cnf_file="cnf.dimacs";
49  std::string core_file="unsat_core.cnf";
50  std::string trace_file="resolve_trace";
51  std::string output_file="cnf.out";
52 
53  {
54  std::ofstream out(cnf_file.c_str(), std::ios::out);
55  write_dimacs_cnf(out);
56  }
57 
58  // generate resolve_trace
59  system(std::string("zchaff_verify "+cnf_file+" > "+output_file).c_str());
60 
61  // get core
62  system(
63  std::string("zcore "+cnf_file+" "+trace_file+" >> "+output_file).c_str());
64 
65  in_core.clear();
66 
67  // read result
68  {
69  std::ifstream in(core_file.c_str());
70 
71  while(true)
72  {
73  std::string line;
74  if(!std::getline(in, line))
75  break;
76 
77  if(!(line.substr(0, 1)=="c" || line.substr(0, 1)=="p"))
78  {
79  const char *p=line.c_str();
80 
81  while(true)
82  {
83  int l=unsafe_str2int(p);
84  if(l==0)
85  break;
86 
87  if(l<0)
88  l=-l;
89 
90  in_core.insert(l);
91 
92  // next one
93  const char *q=strchr(p, ' ');
94  while(*q==' ') q++;
95  if(q==NULL)
96  break;
97  p=q;
98  }
99  }
100  }
101  }
102 
103  if(in_core.empty())
104  return P_ERROR;
105 
106  remove(cnf_file.c_str());
107  // remove(core_file.c_str());
108  remove(trace_file.c_str());
109  // remove(output_file.c_str());
110 
111  return P_UNSATISFIABLE;
112 }
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:503
dimacs_cnft::write_dimacs_cnf
virtual void write_dimacs_cnf(std::ostream &out)
Definition: dimacs_cnf.cpp:40
satcheck_zcoret::do_prop_solve
resultt do_prop_solve() override
Definition: satcheck_zcore.cpp:37
invariant.h
satcheck_zcore.h
to_string
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Definition: string_constraint.cpp:58
messaget::eom
static eomt eom
Definition: message.h:297
satcheck_zcoret::solver_text
const std::string solver_text() override
Definition: satcheck_zcore.cpp:32
satcheck_zcoret::in_core
std::set< unsigned > in_core
Definition: satcheck_zcore.h:34
cnf_clause_listt::no_clauses
size_t no_clauses() const override
Definition: cnf_clause_list.h:42
satcheck_zcoret::~satcheck_zcoret
virtual ~satcheck_zcoret()
Definition: satcheck_zcore.cpp:22
string2int.h
satcheck_zcoret::l_get
tvt l_get(literalt a) const override
Definition: satcheck_zcore.cpp:26
propt::resultt
resultt
Definition: prop.h:97
tvt
Definition: threeval.h:19
satcheck_zcoret::satcheck_zcoret
satcheck_zcoret()
Definition: satcheck_zcore.cpp:18
literalt
Definition: literal.h:25
tvt::tv_enumt::TV_UNKNOWN
@ TV_UNKNOWN
propt::log
messaget log
Definition: prop.h:128
cnft::no_variables
virtual size_t no_variables() const override
Definition: cnf.h:42
messaget::statistics
mstreamt & statistics() const
Definition: message.h:419