ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
SimpSolver.h
Go to the documentation of this file.
1/************************************************************************************[SimpSolver.h]
2Copyright (c) 2006, Niklas Een, Niklas Sorensson
3Copyright (c) 2007-2010, Niklas Sorensson
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6associated documentation files (the "Software"), to deal in the Software without restriction,
7including without limitation the rights to use, copy, modify, merge, publish, distribute,
8sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all copies or
12substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19**************************************************************************************************/
20
21#ifndef Minisat_SimpSolver_h
22#define Minisat_SimpSolver_h
23
24#include "sat/bsat2/Queue.h"
25#include "sat/bsat2/Solver.h"
26
28
29namespace Minisat {
30
31//=================================================================================================
32
33
34class SimpSolver : public Solver {
35 public:
36 // Constructor/Destructor:
37 //
38 SimpSolver();
40
41 // Problem specification:
42 //
43 Var newVar (bool polarity = true, bool dvar = true);
44 bool addClause (const vec<Lit>& ps);
45 bool addEmptyClause(); // Add the empty clause to the solver.
46 bool addClause (Lit p); // Add a unit clause to the solver.
47 bool addClause (Lit p, Lit q); // Add a binary clause to the solver.
48 bool addClause (Lit p, Lit q, Lit r); // Add a ternary clause to the solver.
49 bool addClause_( vec<Lit>& ps);
50 bool substitute(Var v, Lit x); // Replace all occurences of v with x (may cause a contradiction).
51
52 // Variable mode:
53 //
54 void setFrozen (Var v, bool b); // If a variable is frozen it will not be eliminated.
55 bool isEliminated(Var v) const;
56
57 // Solving:
58 //
59 bool solve (const vec<Lit>& assumps, bool do_simp = true, bool turn_off_simp = false);
60 lbool solveLimited(const vec<Lit>& assumps, bool do_simp = true, bool turn_off_simp = false);
61 bool solve ( bool do_simp = true, bool turn_off_simp = false);
62 bool solve (Lit p , bool do_simp = true, bool turn_off_simp = false);
63 bool solve (Lit p, Lit q, bool do_simp = true, bool turn_off_simp = false);
64 bool solve (Lit p, Lit q, Lit r, bool do_simp = true, bool turn_off_simp = false);
65 bool eliminate (bool turn_off_elim = false); // Perform variable elimination based simplification.
66
67 // Memory managment:
68 //
69 virtual void garbageCollect();
70
71
72 // Generate a (possibly simplified) DIMACS file:
73 //
74#if 0
75 void toDimacs (const char* file, const vec<Lit>& assumps);
76 void toDimacs (const char* file);
77 void toDimacs (const char* file, Lit p);
78 void toDimacs (const char* file, Lit p, Lit q);
79 void toDimacs (const char* file, Lit p, Lit q, Lit r);
80#endif
81
82 // Mode of operation:
83 //
84 int grow; // Allow a variable elimination step to grow by a number of clauses (default to zero).
85 int clause_lim; // Variables are not eliminated if it produces a resolvent with a length above this limit.
86 // -1 means no limit.
87 int subsumption_lim; // Do not check if subsumption against a clause larger than this. -1 means no limit.
88 double simp_garbage_frac; // A different limit for when to issue a GC during simplification (Also see 'garbage_frac').
89
90 bool use_asymm; // Shrink clauses by asymmetric branching.
91 bool use_rcheck; // Check if a clause is already implied. Prett costly, and subsumes subsumptions :)
92 bool use_elim; // Perform variable elimination.
93
94 // Statistics:
95 //
96 int merges;
99
100 protected:
101
102 // Helper structures:
103 //
104 struct ElimLt {
106 explicit ElimLt(const vec<int>& no) : n_occ(no) {}
107
108 // TODO: are 64-bit operations here noticably bad on 32-bit platforms? Could use a saturating
109 // 32-bit implementation instead then, but this will have to do for now.
110 uint64_t cost (Var x) const { return (uint64_t)n_occ[toInt(mkLit(x))] * (uint64_t)n_occ[toInt(~mkLit(x))]; }
111 bool operator()(Var x, Var y) const { return cost(x) < cost(y); }
112
113 // TODO: investigate this order alternative more.
114 // bool operator()(Var x, Var y) const {
115 // int c_x = cost(x);
116 // int c_y = cost(y);
117 // return c_x < c_y || c_x == c_y && x < y; }
118 };
119
122 explicit ClauseDeleted(const ClauseAllocator& _ca) : ca(_ca) {}
123 bool operator()(const CRef& cr) const { return ca[cr].mark() == 1; } };
124
125 // Solver state:
126 //
140
141 // Temporaries:
142 //
144
145 // Main internal methods:
146 //
147 lbool solve_ (bool do_simp = true, bool turn_off_simp = false);
148 bool asymm (Var v, CRef cr);
149 bool asymmVar (Var v);
150 void updateElimHeap (Var v);
151 void gatherTouchedClauses ();
152 bool merge (const Clause& _ps, const Clause& _qs, Var v, vec<Lit>& out_clause);
153 bool merge (const Clause& _ps, const Clause& _qs, Var v, int& size);
154 bool backwardSubsumptionCheck (bool verbose = false);
155 bool eliminateVar (Var v);
156 void extendModel ();
157
158 void removeClause (CRef cr);
159 bool strengthenClause (CRef cr, Lit l);
160 void cleanUpClauses ();
161 bool implied (const vec<Lit>& c);
162 void relocAll (ClauseAllocator& to);
163};
164
165
166//=================================================================================================
167// Implementation of inline methods:
168
169
170inline bool SimpSolver::isEliminated (Var v) const { return eliminated[v]; }
173 // if (!frozen[v] && !isEliminated(v) && value(v) == l_Undef)
174 if (elim_heap.inHeap(v) || (!frozen[v] && !isEliminated(v) && value(v) == l_Undef))
175 elim_heap.update(v); }
176
177
178inline bool SimpSolver::addClause (const vec<Lit>& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); }
179inline bool SimpSolver::addEmptyClause() { add_tmp.clear(); return addClause_(add_tmp); }
180inline bool SimpSolver::addClause (Lit p) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); }
181inline bool SimpSolver::addClause (Lit p, Lit q) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp); }
182inline bool SimpSolver::addClause (Lit p, Lit q, Lit r) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp); }
183inline void SimpSolver::setFrozen (Var v, bool b) { frozen[v] = (char)b; if (use_simplification && !b) { updateElimHeap(v); } }
184
185inline bool SimpSolver::solve ( bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); return solve_(do_simp, turn_off_simp) == l_True; }
186inline bool SimpSolver::solve (Lit p , bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); return solve_(do_simp, turn_off_simp) == l_True; }
187inline bool SimpSolver::solve (Lit p, Lit q, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_(do_simp, turn_off_simp) == l_True; }
188inline bool SimpSolver::solve (Lit p, Lit q, Lit r, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_(do_simp, turn_off_simp) == l_True; }
189inline bool SimpSolver::solve (const vec<Lit>& assumps, bool do_simp, bool turn_off_simp){
190 budgetOff(); assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp) == l_True; }
191
192inline lbool SimpSolver::solveLimited (const vec<Lit>& assumps, bool do_simp, bool turn_off_simp){
193 assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp); }
194
195//=================================================================================================
196}
197
199
200#endif
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
ABC_NAMESPACE_IMPL_START typedef signed char value
bool addClause(const vec< Lit > &ps)
Definition SimpSolver.h:178
lbool solveLimited(const vec< Lit > &assumps, bool do_simp=true, bool turn_off_simp=false)
Definition SimpSolver.h:192
bool substitute(Var v, Lit x)
OccLists< Var, vec< CRef >, ClauseDeleted > occurs
Definition SimpSolver.h:132
void removeClause(CRef cr)
Queue< CRef > subsumption_queue
Definition SimpSolver.h:135
bool implied(const vec< Lit > &c)
bool eliminate(bool turn_off_elim=false)
bool strengthenClause(CRef cr, Lit l)
bool eliminateVar(Var v)
Var newVar(bool polarity=true, bool dvar=true)
void updateElimHeap(Var v)
Definition SimpSolver.h:171
vec< uint32_t > elimclauses
Definition SimpSolver.h:129
bool asymm(Var v, CRef cr)
bool merge(const Clause &_ps, const Clause &_qs, Var v, vec< Lit > &out_clause)
bool addClause_(vec< Lit > &ps)
vec< char > frozen
Definition SimpSolver.h:136
bool isEliminated(Var v) const
Definition SimpSolver.h:170
virtual void garbageCollect()
bool backwardSubsumptionCheck(bool verbose=false)
vec< char > eliminated
Definition SimpSolver.h:137
vec< char > touched
Definition SimpSolver.h:130
Heap< ElimLt > elim_heap
Definition SimpSolver.h:134
void relocAll(ClauseAllocator &to)
void setFrozen(Var v, bool b)
Definition SimpSolver.h:183
void toDimacs(FILE *f, const vec< Lit > &assumps)
Definition Solver.cpp:833
void budgetOff()
Definition Solver.h:344
vec< Lit > add_tmp
Definition Solver.h:202
bool solve()
Definition Solver.h:353
vec< char > polarity
Definition Solver.h:181
lbool solve_()
Definition Solver.cpp:753
vec< Lit > assumptions
Definition Solver.h:189
void copyTo(vec< T > &copy) const
Definition Vec.h:92
Cube * p
Definition exorList.c:222
Definition Alg.h:28
int toInt(Var v)
Definition SolverTypes.h:67
RegionAllocator< uint32_t >::Ref CRef
Lit mkLit(Var var, bool sign=false)
Definition SolverTypes.h:60
const ClauseAllocator & ca
Definition SimpSolver.h:121
ClauseDeleted(const ClauseAllocator &_ca)
Definition SimpSolver.h:122
bool operator()(const CRef &cr) const
Definition SimpSolver.h:123
ElimLt(const vec< int > &no)
Definition SimpSolver.h:106
uint64_t cost(Var x) const
Definition SimpSolver.h:110
const vec< int > & n_occ
Definition SimpSolver.h:105
bool operator()(Var x, Var y) const
Definition SimpSolver.h:111
Definition file.h:23
#define assert(ex)
Definition util_old.h:213