sat-solver/SkeletonSolver.h
00001 /*
00002  * SkeletonSolver.h
00003  *
00004  *  Created on: Jul 29, 2009
00005  *      Author: tdillig
00006  */
00007 
00008 #ifndef SKELETONSOLVER_H_
00009 #define SKELETONSOLVER_H_
00010 
00011 #include <vector>
00012 #include <map>
00013 #include <set>
00014 #include <unordered_map>
00015 using namespace std;
00016 
00017 
00018 #include "SatSolver.h"
00019 #include "SolverTypes.h"
00020 #include "Vec.h"
00021 
00022 #define FALSE_CLAUSE ((vec<minisat::Lit>*)((0) | 1))
00023 #define STACK_DELIMITER ((vec<minisat::Lit>*)NULL)
00024 
00025 class CNode;
00026 
00027 class SkeletonSolver {
00028         map<CNode*, minisat::Var> node_to_var_map;
00029         map<minisat::Var, CNode*> var_to_node_map;
00030 
00031         /*
00032          * Every push adds a set of clauses, and the set of clauses
00033          * added by every different push are delimited by STACK_DELIMITER.
00034          */
00035         vector<vec<minisat::Lit>* > stack;
00036 
00037         /*
00038          * i'th entry of the vector contains the set of minisat literals
00039          * that have the appropriate clauses associated with them so that
00040          * we do not need to re-insert their clauses.
00041          */
00042         vector<set<int> > vars_stack;
00043 
00044         set<int> permanent_vars;
00045 
00046         /*
00047          * permanant_clauses cannot be popped and result from
00048          * calls to add().
00049          */
00050         vector<vec<minisat::Lit>*> permanent_clauses;
00051 
00052         /*
00053          * The next variable number we can assign to a new variable.
00054          * Variable numbers are consecutive.
00055          */
00056         unsigned int next_var;
00057 
00058         /*
00059          * Number of false clauses pushed on the stack.
00060          */
00061         unsigned short int num_false_clauses;
00062 
00063         /*
00064          * The solver that was used after the last sat query.
00065          */
00066         minisat::Solver* last_solver;
00067 
00068         /*
00069          * Ivars for printing stats.
00070          */
00071         int cnf_time;
00072         int solve_time;
00073         int num_sat_queries;
00074 
00075 
00076 
00077 public:
00078         SkeletonSolver();
00079         void push(CNode* node);
00080         void pop();
00081         bool sat();
00082 
00083         /*
00084          * If a node is added to the SkeletonSolver, it cannot be popped.
00085          */
00086         void add(CNode* node);
00087 
00088         /*
00089          * Makes a conjunct out of the literals consistent with
00090          * the model found by the sat solver.
00091          */
00092         CNode* make_conjunct_from_sat_assignment(set<CNode*>& relevant_leaves);
00093 
00094         string stats_to_string();
00095         ~SkeletonSolver();
00096 
00097 private:
00098         void cnode_to_clause_set(CNode* node, vec<minisat::Lit>* antecedent,
00099                         bool use_stack);
00100         void print_stack();
00101 
00102         string model_to_string(minisat::Solver& s);
00103 
00104 };
00105 
00106 #endif /* SKELETONSOLVER_H_ */