spot  2.11.6
satsolver.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2013, 2017-2018, 2020, 2022 Laboratoire de Recherche
3 // et Développement 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 
44  {
45  private:
46  const char* satsolver;
47 
48  public:
50 
52  bool command_given();
53 
55  int run(printable* in, printable* out);
56 
57  };
58 
70  class SPOT_API satsolver
71  {
72  public:
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() const;
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 requires SPOT_SATSOLVER to be set as well.
171  std::ofstream* xcnf_tmp_;
172  std::ofstream* xcnf_stream_;
173  std::string path_;
174  };
175 
176  template<typename T>
177  void
179  {
180  if (!psat_)
181  *cnf_stream_ << ' ' << single;
182  }
183 
184  template<typename T, typename... Args>
185  void
186  satsolver::comment_rec(T first, Args... args)
187  {
188  if (!psat_)
189  {
190  *cnf_stream_ << ' ' << first;
191  comment_rec(args...);
192  }
193  }
194 
195  template<typename T>
196  void
198  {
199  if (!psat_)
200  *cnf_stream_ << "c " << single;
201  }
202 
203  template<typename T, typename... Args>
204  void
205  satsolver::comment(T first, Args... args)
206  {
207  if (!psat_)
208  {
209  *cnf_stream_ << "c " << first;
210  comment_rec(args...);
211  }
212  }
213 
214 }
Definition: formater.hh:113
Definition: formater.hh:31
Interface with a given sat solver.
Definition: satsolver.hh:44
bool command_given()
Return true if a satsolver is given, false otherwise.
int run(printable *in, printable *out)
Run the given satsolver.
Interface with a SAT solver.
Definition: satsolver.hh:71
std::pair< int, int > stats() const
Returns std::pair<nvars, nclauses>;.
void add(std::initializer_list< int > values)
Add a list of lit. to the current clause.
void add(int v)
Add a single lit. to the current clause.
solution_pair get_solution()
Return std::vector<solving_return_code, solution>.
satsolver()
Construct the sat solver and itinialize variables. If no satsolver is provided through SPOT_SATSOLVER...
int get_nb_vars() const
Get the current number of variables.
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:197
void comment_rec(T single)
Add a comment. It should be used only in debug mode after providing a satsolver.
Definition: satsolver.hh:178
void set_nassumptions_vars(int nassumptions_vars)
Declare the number of vars reserved for assumptions.
int get_nb_clauses() const
Get the current number of clauses.
void assume(int lit)
Assume a litteral value. Must only be used with distributed picolib.
void adjust_nvars(int nvars)
Adjust the number of variables used in the cnf formula.
Temporary file name.
Definition: tmpfile.hh:50
Definition: automata.hh:27

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Feb 27 2015 10:00:07 for spot by doxygen 1.9.1