CBMC
qbf_skizzo.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 "qbf_skizzo.h"
10 
11 #include <cstdlib>
12 #include <fstream>
13 
14 #include <util/invariant.h>
15 
17  : qdimacs_cnft(message_handler)
18 {
19  // skizzo crashes on broken lines
20  break_lines=false;
21 }
22 
24 {
25 }
26 
28 {
30 }
31 
32 std::string qbf_skizzot::solver_text() const
33 {
34  return "Skizzo";
35 }
36 
38 {
39  // sKizzo crashes on empty instances
40  if(no_clauses()==0)
42 
43  {
44  log.status() << "Skizzo: " << no_variables() << " variables, "
45  << no_clauses() << " clauses" << messaget::eom;
46  }
47 
48  std::string qbf_tmp_file="sKizzo.qdimacs";
49  std::string result_tmp_file="sKizzo.out";
50 
51  {
52  std::ofstream out(qbf_tmp_file.c_str());
53 
54  // write it
55  write_qdimacs_cnf(out);
56  }
57 
58  std::string options;
59 
60  // solve it
61  int res=system((
62  "sKizzo "+qbf_tmp_file+options+" > "+result_tmp_file).c_str());
63  CHECK_RETURN(0==res);
64 
65  bool result=false;
66 
67  // read result
68  {
69  std::ifstream in(result_tmp_file.c_str());
70 
71  bool result_found=false;
72  while(in)
73  {
74  std::string line;
75 
76  std::getline(in, line);
77 
78  if(!line.empty() && line[line.size() - 1] == '\r')
79  line.resize(line.size()-1);
80 
81  if(line=="The instance evaluates to TRUE.")
82  {
83  result=true;
84  result_found=true;
85  break;
86  }
87  else if(line=="The instance evaluates to FALSE.")
88  {
89  result=false;
90  result_found=true;
91  break;
92  }
93  }
94 
95  if(!result_found)
96  {
97  log.error() << "Skizzo failed: unknown result" << messaget::eom;
98  return resultt::P_ERROR;
99  }
100  }
101 
102  if(result)
103  {
104  log.status() << "Skizzo: TRUE" << messaget::eom;
105  return resultt::P_SATISFIABLE;
106  }
107  else
108  {
109  log.status() << "Skizzo: FALSE" << messaget::eom;
111  }
112 
113  return resultt::P_ERROR;
114 }
size_t no_clauses() const override
virtual size_t no_variables() const override
Definition: cnf.h:42
bool break_lines
Definition: dimacs_cnf.h:42
mstreamt & error() const
Definition: message.h:391
mstreamt & status() const
Definition: message.h:406
static eomt eom
Definition: message.h:289
resultt
Definition: prop.h:101
messaget log
Definition: prop.h:134
virtual resultt prop_solve()
Definition: qbf_skizzo.cpp:37
std::string solver_text() const override
Definition: qbf_skizzo.cpp:32
tvt l_get(literalt a) const override
Definition: qbf_skizzo.cpp:27
qbf_skizzot(message_handlert &message_handler)
Definition: qbf_skizzo.cpp:16
~qbf_skizzot() override
Definition: qbf_skizzo.cpp:23
virtual void write_qdimacs_cnf(std::ostream &out)
Definition: qdimacs_cnf.cpp:15
Definition: threeval.h:20
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:495
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525