cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
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
18
qbf_qube_coret::qbf_qube_coret
(
message_handlert
&message_handler)
19
:
qdimacs_coret
(message_handler)
20
{
21
break_lines
=
false
;
22
qbf_tmp_file
=
"qube.qdimacs"
;
23
}
24
25
qbf_qube_coret::~qbf_qube_coret
()
26
{
27
}
28
29
std::string
qbf_qube_coret::solver_text
()
const
30
{
31
return
"QuBE w/ toplevel assignments"
;
32
}
33
34
propt::resultt
qbf_qube_coret::prop_solve
()
35
{
36
if
(
no_clauses
()==0)
37
return
resultt::P_SATISFIABLE
;
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
;
128
return
resultt::P_UNSATISFIABLE
;
129
}
130
}
131
132
bool
qbf_qube_coret::is_in_core
(
literalt
)
const
133
{
134
UNIMPLEMENTED
;
135
}
136
137
qdimacs_coret::modeltypet
qbf_qube_coret::m_get
(
literalt
)
const
138
{
139
UNIMPLEMENTED
;
140
}
arith_tools.h
numeric_cast_v
Target numeric_cast_v(const mp_integer &arg)
Convert an mp_integer to integral type Target An invariant will fail if the conversion is not possibl...
Definition
arith_tools.h:135
cnf_clause_listt::no_clauses
size_t no_clauses() const override
Definition
cnf_clause_list.h:42
cnft::no_variables
virtual size_t no_variables() const override
Definition
cnf.h:42
dimacs_cnft::break_lines
bool break_lines
Definition
dimacs_cnf.h:42
literalt
Definition
literal.h:26
message_handlert
Definition
message.h:27
messaget::eom
static eomt eom
Definition
message.h:289
propt::resultt
resultt
Definition
prop.h:101
propt::resultt::P_UNSATISFIABLE
@ P_UNSATISFIABLE
Definition
prop.h:101
propt::resultt::P_SATISFIABLE
@ P_SATISFIABLE
Definition
prop.h:101
propt::resultt::P_ERROR
@ P_ERROR
Definition
prop.h:101
propt::log
messaget log
Definition
prop.h:134
qbf_qube_coret::solver_text
std::string solver_text() const override
Definition
qbf_qube_core.cpp:29
qbf_qube_coret::qbf_qube_coret
qbf_qube_coret(message_handlert &message_handler)
Definition
qbf_qube_core.cpp:18
qbf_qube_coret::assignment
assignmentt assignment
Definition
qbf_qube_core.h:23
qbf_qube_coret::prop_solve
virtual resultt prop_solve()
Definition
qbf_qube_core.cpp:34
qbf_qube_coret::~qbf_qube_coret
~qbf_qube_coret() override
Definition
qbf_qube_core.cpp:25
qbf_qube_coret::m_get
modeltypet m_get(literalt a) const override
Definition
qbf_qube_core.cpp:137
qbf_qube_coret::is_in_core
bool is_in_core(literalt l) const override
Definition
qbf_qube_core.cpp:132
qbf_qube_coret::qbf_tmp_file
std::string qbf_tmp_file
Definition
qbf_qube_core.h:20
qdimacs_cnft::write_qdimacs_cnf
virtual void write_qdimacs_cnf(std::ostream &out)
Definition
qdimacs_cnf.cpp:15
qdimacs_coret::qdimacs_coret
qdimacs_coret(message_handlert &message_handler)
Definition
qdimacs_core.h:22
qdimacs_coret::modeltypet
modeltypet
Definition
qdimacs_core.h:30
qbf_qube_core.h
mp_integer
BigInt mp_integer
Definition
smt_terms.h:17
invariant.h
CHECK_RETURN
#define CHECK_RETURN(CONDITION)
Definition
invariant.h:495
UNIMPLEMENTED
#define UNIMPLEMENTED
Definition
invariant.h:558
solvers
qbf
qbf_qube_core.cpp
Generated by
1.17.0