yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ezsat.h
Go to the documentation of this file.
1 /*
2  * ezSAT -- A simple and easy to use CNF generator for SAT solvers
3  *
4  * Copyright (C) 2013 Clifford Wolf <clifford@clifford.at>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  */
19 
20 #ifndef EZSAT_H
21 #define EZSAT_H
22 
23 #include <set>
24 #include <map>
25 #include <vector>
26 #include <string>
27 #include <stdio.h>
28 #include <stdint.h>
29 
30 class ezSAT
31 {
32  // each token (terminal or non-terminal) is represented by an interger number
33  //
34  // the zero token:
35  // the number zero is not used as valid token number and is used to encode
36  // unused parameters for the functions.
37  //
38  // positive numbers are literals, with 1 = CONST_TRUE and 2 = CONST_FALSE;
39  //
40  // negative numbers are non-literal expressions. each expression is represented
41  // by an operator id and a list of expressions (literals or non-literals).
42 
43 public:
44  enum OpId {
46  };
47 
48  static const int CONST_TRUE;
49  static const int CONST_FALSE;
50 
51 private:
54 
56 
57  std::map<std::string, int> literalsCache;
58  std::vector<std::string> literals;
59 
60  std::map<std::pair<OpId, std::vector<int>>, int> expressionsCache;
61  std::vector<std::pair<OpId, std::vector<int>>> expressions;
62 
66  std::vector<std::vector<int>> cnfClauses, cnfClausesBackup;
67 
68  void add_clause(const std::vector<int> &args);
69  void add_clause(const std::vector<int> &args, bool argsPolarity, int a = 0, int b = 0, int c = 0);
70  void add_clause(int a, int b = 0, int c = 0);
71 
72  int bind_cnf_not(const std::vector<int> &args);
73  int bind_cnf_and(const std::vector<int> &args);
74  int bind_cnf_or(const std::vector<int> &args);
75 
76 protected:
77  void preSolverCallback();
78 
79 public:
82 
83  ezSAT();
84  virtual ~ezSAT();
85 
86  void keep_cnf() { flag_keep_cnf = true; }
88 
89  bool mode_keep_cnf() const { return flag_keep_cnf; }
90  bool mode_non_incremental() const { return flag_non_incremental; }
91 
92  // manage expressions
93 
94  int value(bool val);
95  int literal();
96  int literal(const std::string &name);
97  int frozen_literal();
98  int frozen_literal(const std::string &name);
99  int expression(OpId op, int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0);
100  int expression(OpId op, const std::vector<int> &args);
101 
102  void lookup_literal(int id, std::string &name) const;
103  const std::string &lookup_literal(int id) const;
104 
105  void lookup_expression(int id, OpId &op, std::vector<int> &args) const;
106  const std::vector<int> &lookup_expression(int id, OpId &op) const;
107 
108  int parse_string(const std::string &text);
109  std::string to_string(int id) const;
110 
111  int numLiterals() const { return literals.size(); }
112  int numExpressions() const { return expressions.size(); }
113 
114  int eval(int id, const std::vector<int> &values) const;
115 
116  // SAT solver interface
117  // If you are planning on using the solver API (and not simply create a CNF) you must use a child class
118  // of ezSAT that actually implements a solver backend, such as ezMiniSAT (see ezminisat.h).
119 
120  virtual bool solver(const std::vector<int> &modelExpressions, std::vector<bool> &modelValues, const std::vector<int> &assumptions);
121 
122  bool solve(const std::vector<int> &modelExpressions, std::vector<bool> &modelValues, const std::vector<int> &assumptions) {
123  return solver(modelExpressions, modelValues, assumptions);
124  }
125 
126  bool solve(const std::vector<int> &modelExpressions, std::vector<bool> &modelValues, int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
127  std::vector<int> assumptions;
128  if (a != 0) assumptions.push_back(a);
129  if (b != 0) assumptions.push_back(b);
130  if (c != 0) assumptions.push_back(c);
131  if (d != 0) assumptions.push_back(d);
132  if (e != 0) assumptions.push_back(e);
133  if (f != 0) assumptions.push_back(f);
134  return solver(modelExpressions, modelValues, assumptions);
135  }
136 
137  bool solve(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0) {
138  std::vector<int> assumptions, modelExpressions;
139  std::vector<bool> modelValues;
140  if (a != 0) assumptions.push_back(a);
141  if (b != 0) assumptions.push_back(b);
142  if (c != 0) assumptions.push_back(c);
143  if (d != 0) assumptions.push_back(d);
144  if (e != 0) assumptions.push_back(e);
145  if (f != 0) assumptions.push_back(f);
146  return solver(modelExpressions, modelValues, assumptions);
147  }
148 
149  void setSolverTimeout(int newTimeoutSeconds) {
150  solverTimeout = newTimeoutSeconds;
151  }
152 
154  return solverTimoutStatus;
155  }
156 
157  // manage CNF (usually only accessed by SAT solvers)
158 
159  virtual void clear();
160  virtual void freeze(int id);
161  virtual bool eliminated(int idx);
162  void assume(int id);
163  int bind(int id, bool auto_freeze = true);
164  int bound(int id) const;
165 
166  int numCnfVariables() const { return cnfVariableCount; }
167  int numCnfClauses() const { return cnfClausesCount; }
168  const std::vector<std::vector<int>> &cnf() const { return cnfClauses; }
169 
170  void consumeCnf();
171  void consumeCnf(std::vector<std::vector<int>> &cnf);
172 
173  // use this function to get the full CNF in keep_cnf mode
174  void getFullCnf(std::vector<std::vector<int>> &full_cnf) const;
175 
176  std::string cnfLiteralInfo(int idx) const;
177 
178  // simple helpers for build expressions easily
179 
180  struct _V {
181  int id;
182  std::string name;
183  _V(int id) : id(id) { }
184  _V(const char *name) : id(0), name(name) { }
185  _V(const std::string &name) : id(0), name(name) { }
186  int get(ezSAT *that) {
187  if (name.empty())
188  return id;
189  return that->frozen_literal(name);
190  }
191  };
192 
193  int VAR(_V a) {
194  return a.get(this);
195  }
196 
197  int NOT(_V a) {
198  return expression(OpNot, a.get(this));
199  }
200 
201  int AND(_V a = 0, _V b = 0, _V c = 0, _V d = 0, _V e = 0, _V f = 0) {
202  return expression(OpAnd, a.get(this), b.get(this), c.get(this), d.get(this), e.get(this), f.get(this));
203  }
204 
205  int OR(_V a = 0, _V b = 0, _V c = 0, _V d = 0, _V e = 0, _V f = 0) {
206  return expression(OpOr, a.get(this), b.get(this), c.get(this), d.get(this), e.get(this), f.get(this));
207  }
208 
209  int XOR(_V a = 0, _V b = 0, _V c = 0, _V d = 0, _V e = 0, _V f = 0) {
210  return expression(OpXor, a.get(this), b.get(this), c.get(this), d.get(this), e.get(this), f.get(this));
211  }
212 
213  int IFF(_V a, _V b = 0, _V c = 0, _V d = 0, _V e = 0, _V f = 0) {
214  return expression(OpIFF, a.get(this), b.get(this), c.get(this), d.get(this), e.get(this), f.get(this));
215  }
216 
217  int ITE(_V a, _V b, _V c) {
218  return expression(OpITE, a.get(this), b.get(this), c.get(this));
219  }
220 
221  void SET(_V a, _V b) {
222  assume(IFF(a.get(this), b.get(this)));
223  }
224 
225  // simple helpers for building expressions with bit vectors
226 
227  std::vector<int> vec_const(const std::vector<bool> &bits);
228  std::vector<int> vec_const_signed(int64_t value, int numBits);
229  std::vector<int> vec_const_unsigned(uint64_t value, int numBits);
230  std::vector<int> vec_var(int numBits);
231  std::vector<int> vec_var(std::string name, int numBits);
232  std::vector<int> vec_cast(const std::vector<int> &vec1, int toBits, bool signExtend = false);
233 
234  std::vector<int> vec_not(const std::vector<int> &vec1);
235  std::vector<int> vec_and(const std::vector<int> &vec1, const std::vector<int> &vec2);
236  std::vector<int> vec_or(const std::vector<int> &vec1, const std::vector<int> &vec2);
237  std::vector<int> vec_xor(const std::vector<int> &vec1, const std::vector<int> &vec2);
238 
239  std::vector<int> vec_iff(const std::vector<int> &vec1, const std::vector<int> &vec2);
240  std::vector<int> vec_ite(const std::vector<int> &vec1, const std::vector<int> &vec2, const std::vector<int> &vec3);
241  std::vector<int> vec_ite(int sel, const std::vector<int> &vec1, const std::vector<int> &vec2);
242 
243  std::vector<int> vec_count(const std::vector<int> &vec, int numBits, bool clip = true);
244  std::vector<int> vec_add(const std::vector<int> &vec1, const std::vector<int> &vec2);
245  std::vector<int> vec_sub(const std::vector<int> &vec1, const std::vector<int> &vec2);
246  std::vector<int> vec_neg(const std::vector<int> &vec);
247 
248  void vec_cmp(const std::vector<int> &vec1, const std::vector<int> &vec2, int &carry, int &overflow, int &sign, int &zero);
249 
250  int vec_lt_signed(const std::vector<int> &vec1, const std::vector<int> &vec2);
251  int vec_le_signed(const std::vector<int> &vec1, const std::vector<int> &vec2);
252  int vec_ge_signed(const std::vector<int> &vec1, const std::vector<int> &vec2);
253  int vec_gt_signed(const std::vector<int> &vec1, const std::vector<int> &vec2);
254 
255  int vec_lt_unsigned(const std::vector<int> &vec1, const std::vector<int> &vec2);
256  int vec_le_unsigned(const std::vector<int> &vec1, const std::vector<int> &vec2);
257  int vec_ge_unsigned(const std::vector<int> &vec1, const std::vector<int> &vec2);
258  int vec_gt_unsigned(const std::vector<int> &vec1, const std::vector<int> &vec2);
259 
260  int vec_eq(const std::vector<int> &vec1, const std::vector<int> &vec2);
261  int vec_ne(const std::vector<int> &vec1, const std::vector<int> &vec2);
262 
263  std::vector<int> vec_shl(const std::vector<int> &vec1, int shift, bool signExtend = false);
264  std::vector<int> vec_srl(const std::vector<int> &vec1, int shift);
265 
266  std::vector<int> vec_shr(const std::vector<int> &vec1, int shift, bool signExtend = false) { return vec_shl(vec1, -shift, signExtend); }
267  std::vector<int> vec_srr(const std::vector<int> &vec1, int shift) { return vec_srl(vec1, -shift); }
268 
269  std::vector<int> vec_shift(const std::vector<int> &vec1, int shift, int extend_left, int extend_right);
270  std::vector<int> vec_shift_right(const std::vector<int> &vec1, const std::vector<int> &vec2, bool vec2_signed, int extend_left, int extend_right);
271  std::vector<int> vec_shift_left(const std::vector<int> &vec1, const std::vector<int> &vec2, bool vec2_signed, int extend_left, int extend_right);
272 
273  void vec_append(std::vector<int> &vec, const std::vector<int> &vec1) const;
274  void vec_append_signed(std::vector<int> &vec, const std::vector<int> &vec1, int64_t value);
275  void vec_append_unsigned(std::vector<int> &vec, const std::vector<int> &vec1, uint64_t value);
276 
277  int64_t vec_model_get_signed(const std::vector<int> &modelExpressions, const std::vector<bool> &modelValues, const std::vector<int> &vec1) const;
278  uint64_t vec_model_get_unsigned(const std::vector<int> &modelExpressions, const std::vector<bool> &modelValues, const std::vector<int> &vec1) const;
279 
280  int vec_reduce_and(const std::vector<int> &vec1);
281  int vec_reduce_or(const std::vector<int> &vec1);
282 
283  void vec_set(const std::vector<int> &vec1, const std::vector<int> &vec2);
284  void vec_set_signed(const std::vector<int> &vec1, int64_t value);
285  void vec_set_unsigned(const std::vector<int> &vec1, uint64_t value);
286 
287  // helpers for generating ezSATbit and ezSATvec objects
288 
289  struct ezSATbit bit(_V a);
290  struct ezSATvec vec(const std::vector<int> &vec);
291 
292  // printing CNF and internal state
293 
294  void printDIMACS(FILE *f, bool verbose = false) const;
295  void printInternalState(FILE *f) const;
296 
297  // more sophisticated constraints (designed to be used directly with assume(..))
298 
299  int onehot(const std::vector<int> &vec, bool max_only = false);
300  int manyhot(const std::vector<int> &vec, int min_hot, int max_hot = -1);
301  int ordered(const std::vector<int> &vec1, const std::vector<int> &vec2, bool allow_equal = true);
302 };
303 
304 // helper classes for using operator overloading when generating complex expressions
305 
306 struct ezSATbit
307 {
309  int id;
310 
311  ezSATbit(ezSAT &sat, ezSAT::_V a) : sat(sat), id(sat.VAR(a)) { }
312 
313  ezSATbit operator ~() { return ezSATbit(sat, sat.NOT(id)); }
314  ezSATbit operator &(const ezSATbit &other) { return ezSATbit(sat, sat.AND(id, other.id)); }
315  ezSATbit operator |(const ezSATbit &other) { return ezSATbit(sat, sat.OR(id, other.id)); }
316  ezSATbit operator ^(const ezSATbit &other) { return ezSATbit(sat, sat.XOR(id, other.id)); }
317  ezSATbit operator ==(const ezSATbit &other) { return ezSATbit(sat, sat.IFF(id, other.id)); }
318  ezSATbit operator !=(const ezSATbit &other) { return ezSATbit(sat, sat.NOT(sat.IFF(id, other.id))); }
319 
320  operator int() const { return id; }
321  operator ezSAT::_V() const { return ezSAT::_V(id); }
322  operator std::vector<int>() const { return std::vector<int>(1, id); }
323 };
324 
325 struct ezSATvec
326 {
328  std::vector<int> vec;
329 
330  ezSATvec(ezSAT &sat, const std::vector<int> &vec) : sat(sat), vec(vec) { }
331 
332  ezSATvec operator ~() { return ezSATvec(sat, sat.vec_not(vec)); }
333  ezSATvec operator -() { return ezSATvec(sat, sat.vec_neg(vec)); }
334 
335  ezSATvec operator &(const ezSATvec &other) { return ezSATvec(sat, sat.vec_and(vec, other.vec)); }
336  ezSATvec operator |(const ezSATvec &other) { return ezSATvec(sat, sat.vec_or(vec, other.vec)); }
337  ezSATvec operator ^(const ezSATvec &other) { return ezSATvec(sat, sat.vec_xor(vec, other.vec)); }
338 
339  ezSATvec operator +(const ezSATvec &other) { return ezSATvec(sat, sat.vec_add(vec, other.vec)); }
340  ezSATvec operator -(const ezSATvec &other) { return ezSATvec(sat, sat.vec_sub(vec, other.vec)); }
341 
342  ezSATbit operator < (const ezSATvec &other) { return ezSATbit(sat, sat.vec_lt_unsigned(vec, other.vec)); }
343  ezSATbit operator <=(const ezSATvec &other) { return ezSATbit(sat, sat.vec_le_unsigned(vec, other.vec)); }
344  ezSATbit operator ==(const ezSATvec &other) { return ezSATbit(sat, sat.vec_eq(vec, other.vec)); }
345  ezSATbit operator !=(const ezSATvec &other) { return ezSATbit(sat, sat.vec_ne(vec, other.vec)); }
346  ezSATbit operator >=(const ezSATvec &other) { return ezSATbit(sat, sat.vec_ge_unsigned(vec, other.vec)); }
347  ezSATbit operator > (const ezSATvec &other) { return ezSATbit(sat, sat.vec_gt_unsigned(vec, other.vec)); }
348 
349  ezSATvec operator <<(int shift) { return ezSATvec(sat, sat.vec_shl(vec, shift)); }
350  ezSATvec operator >>(int shift) { return ezSATvec(sat, sat.vec_shr(vec, shift)); }
351 
352  operator std::vector<int>() const { return vec; }
353 };
354 
355 #endif
std::vector< int > vec_sub(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:843
_V(int id)
Definition: ezsat.h:183
const std::vector< std::vector< int > > & cnf() const
Definition: ezsat.h:168
std::vector< int > vec_const_signed(int64_t value, int numBits)
Definition: ezsat.cc:657
std::string cnfLiteralInfo(int idx) const
Definition: ezsat.cc:503
int vec_ge_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:912
void SET(_V a, _V b)
Definition: ezsat.h:221
int frozen_literal()
Definition: ezsat.cc:88
void lookup_expression(int id, OpId &op, std::vector< int > &args) const
Definition: ezsat.cc:218
void non_incremental()
Definition: ezsat.h:87
OpId
Definition: ezsat.h:44
int parse_string(const std::string &text)
Definition: ezsat.cc:232
int solverTimeout
Definition: ezsat.h:80
std::vector< int > vec_var(int numBits)
Definition: ezsat.cc:673
virtual bool solver(const std::vector< int > &modelExpressions, std::vector< bool > &modelValues, const std::vector< int > &assumptions)
Definition: ezsat.cc:639
int numCnfClauses() const
Definition: ezsat.h:167
virtual bool eliminated(int idx)
Definition: ezsat.cc:383
static const int CONST_FALSE
Definition: ezsat.h:49
void vec_append_signed(std::vector< int > &vec, const std::vector< int > &vec1, int64_t value)
Definition: ezsat.cc:1089
std::vector< int > vec_iff(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:736
int cnfClausesCount
Definition: ezsat.h:64
int eval(int id, const std::vector< int > &values) const
Definition: ezsat.cc:293
int vec_le_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:905
static std::string idx(std::string str)
Definition: test_autotb.cc:57
void add_clause(const std::vector< int > &args)
Definition: ezsat.cc:430
int NOT(_V a)
Definition: ezsat.h:197
void vec_cmp(const std::vector< int > &vec1, const std::vector< int > &vec2, int &carry, int &overflow, int &sign, int &zero)
Definition: ezsat.cc:873
int vec_lt_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:926
bool mode_keep_cnf() const
Definition: ezsat.h:89
std::vector< int > vec_count(const std::vector< int > &vec, int numBits, bool clip=true)
Definition: ezsat.cc:789
std::vector< std::string > literals
Definition: ezsat.h:58
void vec_set(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:1149
std::vector< int > vec_shift(const std::vector< int > &vec1, int shift, int extend_left, int extend_right)
Definition: ezsat.cc:993
int value(bool val)
Definition: ezsat.cc:68
void assume(int id)
Definition: ezsat.cc:388
int ITE(_V a, _V b, _V c)
Definition: ezsat.h:217
std::vector< int > vec_shl(const std::vector< int > &vec1, int shift, bool signExtend=false)
Definition: ezsat.cc:964
std::vector< std::pair< OpId, std::vector< int > > > expressions
Definition: ezsat.h:61
int AND(_V a=0, _V b=0, _V c=0, _V d=0, _V e=0, _V f=0)
Definition: ezsat.h:201
void consumeCnf()
Definition: ezsat.cc:606
std::vector< int > vec_or(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:718
void preSolverCallback()
Definition: ezsat.cc:632
int onehot(const std::vector< int > &vec, bool max_only=false)
Definition: ezsat.cc:1303
_V(const std::string &name)
Definition: ezsat.h:185
void vec_set_unsigned(const std::vector< int > &vec1, uint64_t value)
Definition: ezsat.cc:1167
bool sign(Lit p)
Definition: SolverTypes.h:66
std::vector< int > vec
Definition: ezsat.h:328
std::vector< int > vec_srl(const std::vector< int > &vec1, int shift)
Definition: ezsat.cc:979
int numCnfVariables() const
Definition: ezsat.h:166
int numExpressions() const
Definition: ezsat.h:112
void lookup_literal(int id, std::string &name) const
Definition: ezsat.cc:206
std::vector< int > cnfLiteralVariables
Definition: ezsat.h:65
Lit operator~(Lit p)
Definition: SolverTypes.h:64
std::string to_string(int id) const
Definition: ezsat.cc:237
std::map< std::pair< OpId, std::vector< int > >, int > expressionsCache
Definition: ezsat.h:60
uint64_t vec_model_get_unsigned(const std::vector< int > &modelExpressions, const std::vector< bool > &modelValues, const std::vector< int > &vec1) const
Definition: ezsat.cc:1126
int vec_gt_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:947
_V(const char *name)
Definition: ezsat.h:184
std::vector< int > vec_neg(const std::vector< int > &vec)
Definition: ezsat.cc:867
ezSATbit(ezSAT &sat, ezSAT::_V a)
Definition: ezsat.h:311
std::vector< int > vec_const_unsigned(uint64_t value, int numBits)
Definition: ezsat.cc:665
void vec_append_unsigned(std::vector< int > &vec, const std::vector< int > &vec1, uint64_t value)
Definition: ezsat.cc:1100
std::vector< int > vec_shr(const std::vector< int > &vec1, int shift, bool signExtend=false)
Definition: ezsat.h:266
int vec_ne(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:959
bool solve(const std::vector< int > &modelExpressions, std::vector< bool > &modelValues, const std::vector< int > &assumptions)
Definition: ezsat.h:122
bool cnfConsumed
Definition: ezsat.h:63
std::vector< int > vec_shift_left(const std::vector< int > &vec1, const std::vector< int > &vec2, bool vec2_signed, int extend_left, int extend_right)
Definition: ezsat.cc:1059
int VAR(_V a)
Definition: ezsat.h:193
void printInternalState(FILE *f) const
Definition: ezsat.cc:1263
Lit operator^(Lit p, bool b)
Definition: SolverTypes.h:65
void keep_cnf()
Definition: ezsat.h:86
void printDIMACS(FILE *f, bool verbose=false) const
Definition: ezsat.cc:1188
bool solve(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0)
Definition: ezsat.h:137
int bind_cnf_and(const std::vector< int > &args)
Definition: ezsat.cc:468
int64_t vec_model_get_signed(const std::vector< int > &modelExpressions, const std::vector< bool > &modelValues, const std::vector< int > &vec1) const
Definition: ezsat.cc:1111
std::vector< int > vec_shift_right(const std::vector< int > &vec1, const std::vector< int > &vec2, bool vec2_signed, int extend_left, int extend_right)
Definition: ezsat.cc:1016
int ordered(const std::vector< int > &vec1, const std::vector< int > &vec2, bool allow_equal=true)
Definition: ezsat.cc:1371
int vec_reduce_and(const std::vector< int > &vec1)
Definition: ezsat.cc:1139
std::vector< int > vec_cast(const std::vector< int > &vec1, int toBits, bool signExtend=false)
Definition: ezsat.cc:690
std::vector< int > vec_xor(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:727
int get(ezSAT *that)
Definition: ezsat.h:186
int bound(int id) const
Definition: ezsat.cc:494
int vec_reduce_or(const std::vector< int > &vec1)
Definition: ezsat.cc:1144
int vec_gt_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:919
virtual void freeze(int id)
Definition: ezsat.cc:379
bool solverTimoutStatus
Definition: ezsat.h:81
int bind_cnf_not(const std::vector< int > &args)
Definition: ezsat.cc:462
static const int CONST_TRUE
Definition: ezsat.h:48
virtual ~ezSAT()
Definition: ezsat.cc:64
std::vector< int > vec_add(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:819
int cnfVariableCount
Definition: ezsat.h:64
int literal()
Definition: ezsat.cc:73
void getFullCnf(std::vector< std::vector< int >> &full_cnf) const
Definition: ezsat.cc:625
ezSAT & sat
Definition: ezsat.h:327
std::vector< int > vec_ite(const std::vector< int > &vec1, const std::vector< int > &vec2, const std::vector< int > &vec3)
Definition: ezsat.cc:745
int manyhot(const std::vector< int > &vec, int min_hot, int max_hot=-1)
Definition: ezsat.cc:1333
ezSAT()
Definition: ezsat.cc:43
virtual void clear()
Definition: ezsat.cc:369
std::vector< int > vec_srr(const std::vector< int > &vec1, int shift)
Definition: ezsat.h:267
int XOR(_V a=0, _V b=0, _V c=0, _V d=0, _V e=0, _V f=0)
Definition: ezsat.h:209
void setSolverTimeout(int newTimeoutSeconds)
Definition: ezsat.h:149
int expression(OpId op, int a=0, int b=0, int c=0, int d=0, int e=0, int f=0)
Definition: ezsat.cc:102
bool getSolverTimoutStatus()
Definition: ezsat.h:153
bool solve(const std::vector< int > &modelExpressions, std::vector< bool > &modelValues, int a=0, int b=0, int c=0, int d=0, int e=0, int f=0)
Definition: ezsat.h:126
int vec_eq(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:954
int vec_lt_signed(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:898
int id
Definition: ezsat.h:309
int id
Definition: ezsat.h:181
int OR(_V a=0, _V b=0, _V c=0, _V d=0, _V e=0, _V f=0)
Definition: ezsat.h:205
bool flag_keep_cnf
Definition: ezsat.h:52
bool flag_non_incremental
Definition: ezsat.h:53
std::vector< int > vec_const(const std::vector< bool > &bits)
Definition: ezsat.cc:649
std::ostream & operator<<(std::ostream &os, const BigUnsigned &x)
int bind_cnf_or(const std::vector< int > &args)
Definition: ezsat.cc:481
std::vector< std::vector< int > > cnfClauses
Definition: ezsat.h:66
std::string id(RTLIL::IdString internal_id, bool may_rename=true)
ezSAT & sat
Definition: ezsat.h:308
int numLiterals() const
Definition: ezsat.h:111
std::map< std::string, int > literalsCache
Definition: ezsat.h:57
void vec_set_signed(const std::vector< int > &vec1, int64_t value)
Definition: ezsat.cc:1156
Definition: ezsat.h:30
int IFF(_V a, _V b=0, _V c=0, _V d=0, _V e=0, _V f=0)
Definition: ezsat.h:213
std::vector< std::vector< int > > cnfClausesBackup
Definition: ezsat.h:66
bool mode_non_incremental() const
Definition: ezsat.h:90
std::vector< int > vec_not(const std::vector< int > &vec1)
Definition: ezsat.cc:701
std::vector< int > cnfExpressionVariables
Definition: ezsat.h:65
int vec_ge_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:940
struct ezSATbit bit(_V a)
Definition: ezsat.cc:1178
bool non_incremental_solve_used_up
Definition: ezsat.h:55
void vec_append(std::vector< int > &vec, const std::vector< int > &vec1) const
Definition: ezsat.cc:1083
std::string name
Definition: ezsat.h:182
struct ezSATvec vec(const std::vector< int > &vec)
Definition: ezsat.cc:1183
int vec_le_unsigned(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:933
int bind(int id, bool auto_freeze=true)
Definition: ezsat.cc:520
std::vector< int > vec_and(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:709
ezSATvec(ezSAT &sat, const std::vector< int > &vec)
Definition: ezsat.h:330