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 std::string satcheck_zcoret::solver_text() const
33 {
34  return "ZCore";
35 }
36 
38 {
39  PRECONDITION(assumptions.empty());
40 
41  // We start counting at 1, thus there is one variable fewer.
42  {
43  std::string msg=
44  std::to_string(no_variables()-1)+" variables, "+
45  std::to_string(no_clauses())+" clauses";
46  log.statistics() << msg << messaget::eom;
47  }
48 
49  // get the core
50  std::string cnf_file="cnf.dimacs";
51  std::string core_file="unsat_core.cnf";
52  std::string trace_file="resolve_trace";
53  std::string output_file="cnf.out";
54 
55  {
56  std::ofstream out(cnf_file.c_str(), std::ios::out);
57  write_dimacs_cnf(out);
58  }
59 
60  // generate resolve_trace
61  system(std::string("zchaff_verify "+cnf_file+" > "+output_file).c_str());
62 
63  // get core
64  system(
65  std::string("zcore "+cnf_file+" "+trace_file+" >> "+output_file).c_str());
66 
67  in_core.clear();
68 
69  // read result
70  {
71  std::ifstream in(core_file.c_str());
72 
73  while(true)
74  {
75  std::string line;
76  if(!std::getline(in, line))
77  break;
78 
79  if(!(line.substr(0, 1)=="c" || line.substr(0, 1)=="p"))
80  {
81  const char *p=line.c_str();
82 
83  while(true)
84  {
85  int l=unsafe_str2int(p);
86  if(l==0)
87  break;
88 
89  if(l<0)
90  l=-l;
91 
92  in_core.insert(l);
93 
94  // next one
95  const char *q=strchr(p, ' ');
96  while(*q==' ') q++;
97  if(q==NULL)
98  break;
99  p=q;
100  }
101  }
102  }
103  }
104 
105  if(in_core.empty())
106  return P_ERROR;
107 
108  remove(cnf_file.c_str());
109  // remove(core_file.c_str());
110  remove(trace_file.c_str());
111  // remove(output_file.c_str());
112 
113  return P_UNSATISFIABLE;
114 }
size_t no_clauses() const override
virtual size_t no_variables() const override
Definition: cnf.h:42
virtual void write_dimacs_cnf(std::ostream &out)
Definition: dimacs_cnf.cpp:40
mstreamt & statistics() const
Definition: message.h:419
static eomt eom
Definition: message.h:297
resultt
Definition: prop.h:101
messaget log
Definition: prop.h:134
resultt do_prop_solve(const bvt &assumptions) override
tvt l_get(literalt a) const override
virtual ~satcheck_zcoret()
std::set< unsigned > in_core
std::string solver_text() const override
Definition: threeval.h:20
std::vector< literalt > bvt
Definition: literal.h:201
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
char * strchr(const char *src, int c)
Definition: string.c:958
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.