spot 2.3.4

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
satsolver.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2013 Laboratoire de Recherche et Développement
3 // de l'Epita.
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 #pragma once
21
22 #include <spot/misc/common.hh>
23 #include <spot/misc/tmpfile.hh>
24 #include <vector>
25 #include <stdexcept>
26 #include <iosfwd>
27 #include <initializer_list>
28
29 struct PicoSAT; // forward
30
31 namespace spot
32 {
33 class printable;
34
43 class satsolver_command: formater
44 {
45 private:
46 const char* satsolver;
47
48 public:
49 satsolver_command();
50
52 bool command_given();
53
55 int run(printable* in, printable* out);
56
57 };
58
70 class SPOT_API satsolver
71 {
72 public:
76 satsolver();
77 ~satsolver();
78
80 void adjust_nvars(int nvars);
81
83 void set_nassumptions_vars(int nassumptions_vars);
84
86 void add(std::initializer_list<int> values);
87
89 void add(int v);
90
92 int get_nb_clauses() const;
93
95 int get_nb_vars() const;
96
98 std::pair<int, int> stats();
99
102 template<typename T>
103 void comment_rec(T single);
104
107 template<typename T, typename... Args>
108 void comment_rec(T first, Args... args);
109
112 template<typename T>
113 void comment(T single);
114
117 template<typename T, typename... Args>
118 void comment(T first, Args... args);
119
122 void assume(int lit);
123
124 typedef std::vector<bool> solution;
125 typedef std::pair<int, solution> solution_pair;
126
128 solution_pair get_solution();
129
130 private: // methods
132 void start();
133
135 void end_clause();
136
139 satsolver::solution
140 picosat_get_sol(int res);
141
143 satsolver::solution
144 satsolver_get_sol(const char* filename);
145
147 bool
148 xcnf_mode();
149
150 private: // variables
152 satsolver_command cmd_;
153
154 // cnf streams and associated clause counter.
155 // The next 2 pointers will be != nullptr if SPOT_SATSOLVER is given.
156 temporary_file* cnf_tmp_;
157 std::ostream* cnf_stream_;
158 int nclauses_;
159 int nvars_;
160 int nassumptions_vars_; // Surplus of vars (for 'assume' algorithm).
161
164 int nsols_;
165
167 PicoSAT* psat_;
168
169 // The next 2 pointers will be initialized if SPOT_XCNF env var
170 // is set. This recquires SPOT_SATSOLVER to be set as well.
171 std::ofstream* xcnf_tmp_;
172 std::ofstream* xcnf_stream_;
173 std::string path_;
174 };
175
177 SPOT_API std::vector<int>
178 satsolver_get_solution(const char* filename);
179 }
180
181 namespace spot
182 {
183 template<typename T>
184 void
185 satsolver::comment_rec(T single)
186 {
187 if (!psat_)
188 *cnf_stream_ << ' ' << single;
189 }
190
191 template<typename T, typename... Args>
192 void
193 satsolver::comment_rec(T first, Args... args)
194 {
195 if (!psat_)
196 {
197 *cnf_stream_ << ' ' << first;
198 comment_rec(args...);
199 }
200 }
201
202 template<typename T>
203 void
204 satsolver::comment(T single)
205 {
206 if (!psat_)
207 *cnf_stream_ << "c " << single;
208 }
209
210 template<typename T, typename... Args>
211 void
212 satsolver::comment(T first, Args... args)
213 {
214 if (!psat_)
215 {
216 *cnf_stream_ << "c " << first;
217 comment_rec(args...);
218 }
219 }
220
221 }
spot
Definition: graph.hh:33
spot::temporary_file
Temporary file name.
Definition: tmpfile.hh:49
spot::satsolver_command::command_given
bool command_given()
Return true if a satsolver is given, false otherwise.
spot::satsolver::comment_rec
void comment_rec(T single)
Add a comment. It should be used only in debug mode after providing a satsolver.
Definition: satsolver.hh:185
spot::satsolver_command
Interface with a given sat solver.
Definition: satsolver.hh:43
spot::satsolver::comment
void comment(T single)
Add a comment. It will start with "c ". It should be used only in debug mode after providing a satsol...
Definition: satsolver.hh:204
spot::printable
Definition: formater.hh:32
spot::satsolver
Interface with a SAT solver.
Definition: satsolver.hh:70
spot::formater
Definition: formater.hh:123
spot::satsolver_command::run
int run(printable *in, printable *out)
Run the given satsolver.

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.