CBMC
qbf_qube_core.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: CM Wintersteiger
6 
7 \*******************************************************************/
8 
9 #include "qbf_qube_core.h"
10 
11 #include <cstdlib>
12 #include <cstring>
13 #include <fstream>
14 
15 #include <util/arith_tools.h>
16 #include <util/invariant.h>
17 
19  : qdimacs_coret(message_handler)
20 {
21  break_lines=false;
22  qbf_tmp_file="qube.qdimacs";
23 }
24 
26 {
27 }
28 
29 std::string qbf_qube_coret::solver_text() const
30 {
31  return "QuBE w/ toplevel assignments";
32 }
33 
35 {
36  if(no_clauses()==0)
38 
39  {
40  log.status() << "QuBE: " << no_variables() << " variables, " << no_clauses()
41  << " clauses" << messaget::eom;
42  }
43 
44  std::string result_tmp_file="qube.out";
45 
46  {
47  std::ofstream out(qbf_tmp_file.c_str());
48 
49  // write it
50  break_lines=false;
51  write_qdimacs_cnf(out);
52  }
53 
54  std::string options;
55 
56  // solve it
57  int res=system((
58  "QuBE "+options+" "+qbf_tmp_file+" > "+result_tmp_file).c_str());
59  CHECK_RETURN(0==res);
60 
61  bool result=false;
62 
63  // read result
64  {
65  std::ifstream in(result_tmp_file.c_str());
66 
67  bool result_found=false;
68  while(in)
69  {
70  std::string line;
71 
72  std::getline(in, line);
73 
74  if(!line.empty() && line[line.size() - 1] == '\r')
75  line.resize(line.size()-1);
76 
77  if(line[0]=='V')
78  {
79  mp_integer b(line.substr(2).c_str());
80  if(b<0)
81  assignment[numeric_cast_v<std::size_t>(b.negate())] = false;
82  else
83  assignment[numeric_cast_v<std::size_t>(b)] = true;
84  }
85  else if(line=="s cnf 1")
86  {
87  result=true;
88  result_found=true;
89  break;
90  }
91  else if(line=="s cnf 0")
92  {
93  result=false;
94  result_found=true;
95  break;
96  }
97  }
98 
99  if(!result_found)
100  {
101  log.error() << "QuBE failed: unknown result" << messaget::eom;
102  return resultt::P_ERROR;
103  }
104  }
105 
106  int remove_result=remove(result_tmp_file.c_str());
107  if(remove_result!=0)
108  {
109  log.error() << "Remove failed: " << std::strerror(errno) << messaget::eom;
110  return resultt::P_ERROR;
111  }
112 
113  remove_result=remove(qbf_tmp_file.c_str());
114  if(remove_result!=0)
115  {
116  log.error() << "Remove failed: " << std::strerror(errno) << messaget::eom;
117  return resultt::P_ERROR;
118  }
119 
120  if(result)
121  {
122  log.status() << "QuBE: TRUE" << messaget::eom;
123  return resultt::P_SATISFIABLE;
124  }
125  else
126  {
127  log.status() << "QuBE: FALSE" << messaget::eom;
129  }
130 }
131 
133 {
135 }
136 
138 {
140 }
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
std::string solver_text() const override
qbf_qube_coret(message_handlert &message_handler)
assignmentt assignment
Definition: qbf_qube_core.h:23
virtual resultt prop_solve()
~qbf_qube_coret() override
modeltypet m_get(literalt a) const override
bool is_in_core(literalt l) const override
std::string qbf_tmp_file
Definition: qbf_qube_core.h:20
virtual void write_qdimacs_cnf(std::ostream &out)
Definition: qdimacs_cnf.cpp:15
BigInt mp_integer
Definition: smt_terms.h:17
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:495
#define UNIMPLEMENTED
Definition: invariant.h:558
char * strerror(int errnum)
Definition: string.c:1014