19#include <unordered_map>
54 result ^= constraint->hash();
79 const std::vector<const Array*> &objects,
80 std::vector< std::vector<unsigned char> > &values,
96 ref<Expr> negatedQuery = Expr::createIsZero(originalQuery);
99 if (originalQuery.
compare(negatedQuery) < 0) {
100 negationUsed =
false;
101 return originalQuery;
116 cache_map::iterator it =
cache.find(ce);
118 if (it !=
cache.end()) {
119 result = (negationUsed ?
120 IncompleteSolver::negatePartialValidity(it->second) :
136 (negationUsed ? IncompleteSolver::negatePartialValidity(result) : result);
138 cache.insert(std::make_pair(ce, cachedResult));
144 bool tmp, cacheHit =
cacheLookup(query, cachedResult);
147 switch(cachedResult) {
148 case IncompleteSolver::MustBeTrue:
149 result = Solver::True;
152 case IncompleteSolver::MustBeFalse:
153 result = Solver::False;
156 case IncompleteSolver::TrueOrFalse:
157 result = Solver::Unknown;
160 case IncompleteSolver::MayBeTrue: {
166 result = Solver::True;
170 result = Solver::Unknown;
174 case IncompleteSolver::MayBeFalse: {
180 result = Solver::False;
184 result = Solver::Unknown;
188 default: assert(0 &&
"unreachable");
199 cachedResult = IncompleteSolver::MustBeTrue;
break;
201 cachedResult = IncompleteSolver::MustBeFalse;
break;
203 cachedResult = IncompleteSolver::TrueOrFalse;
break;
217 if (cacheHit && cachedResult != IncompleteSolver::MayBeTrue) {
219 isValid = (cachedResult == IncompleteSolver::MustBeTrue);
230 cachedResult = IncompleteSolver::MustBeTrue;
231 }
else if (cacheHit) {
234 assert(cachedResult == IncompleteSolver::MayBeTrue);
235 cachedResult = IncompleteSolver::TrueOrFalse;
237 cachedResult = IncompleteSolver::MayBeFalse;
SolverRunStatus getOperationStatusCode()
getOperationStatusCode - get the status of the last solver operation
bool computeInitialValues(const Query &query, const std::vector< const Array * > &objects, std::vector< std::vector< unsigned char > > &values, bool &hasSolution)
bool computeTruth(const Query &, bool &isValid)
ref< Expr > canonicalizeQuery(ref< Expr > originalQuery, bool &negationUsed)
std::unordered_map< CacheEntry, IncompleteSolver::PartialValidity, CacheEntryHash > cache_map
bool computeValidity(const Query &, Solver::Validity &result)
void setCoreSolverTimeout(time::Span timeout)
bool cacheLookup(const Query &query, IncompleteSolver::PartialValidity &result)
bool computeValue(const Query &query, ref< Expr > &result)
void cacheInsert(const Query &query, IncompleteSolver::PartialValidity result)
Inserts the given query, result pair into the cache.
char * getConstraintLog(const Query &)
virtual unsigned hash() const
Returns the pre-computed hash of the current expression.
SolverImpl - Abstract base clase for solver implementations.
virtual void setCoreSolverTimeout(time::Span timeout)
virtual bool computeTruth(const Query &query, bool &isValid)=0
virtual bool computeInitialValues(const Query &query, const std::vector< const Array * > &objects, std::vector< std::vector< unsigned char > > &values, bool &hasSolution)=0
virtual bool computeValue(const Query &query, ref< Expr > &result)=0
virtual char * getConstraintLog(const Query &query)
virtual bool computeValidity(const Query &query, Solver::Validity &result)
virtual SolverRunStatus getOperationStatusCode()=0
getOperationStatusCode - get the status of the last solver operation
int compare(const ref &rhs) const
Statistic queryCacheMisses
Solver * createCachingSolver(Solver *s)
unsigned operator()(const CacheEntry &ce) const
ConstraintSet constraints
bool operator==(const CacheEntry &b) const
CacheEntry(const ConstraintSet &c, ref< Expr > q)
CacheEntry(const CacheEntry &ce)
const ConstraintSet & constraints
Query negateExpr() const
negateExpr - Return a copy of the query with the expression negated.