1 /******************************************
2 Copyright (c) 2016, Mate Soos
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 ***********************************************/
22 
23 #ifndef CLAUSECLEANER_H
24 #define CLAUSECLEANER_H
25 
26 #include "constants.h"
27 #include "watched.h"
28 #include "watcharray.h"
29 #include "clause.h"
30 #include "xor.h"
31 #include <vector>
32 using std::vector;
33 
34 namespace CMSat {
35 
36 class Solver;
37 
38 /**
39 @brief Cleans clauses from false literals & removes satisfied clauses
40 */
41 class ClauseCleaner
42 {
43     public:
44         ClauseCleaner(Solver* solver);
45 
46         void clean_implicit_clauses();
47         void remove_and_clean_all();
48         bool clean_xor_clauses(vector<Xor>& xors);
49         bool clean_clause(Clause& c);
50         bool full_clean(Clause& cl);
51 
52     private:
53         bool clean_one_xor(Xor& x);
54 
55         //Implicit cleaning
56         struct ImplicitData
57         {
58             uint64_t remNonLBin = 0;
59             uint64_t remLBin = 0;
60 
61             //We can only attach these in delayed mode, otherwise we would
62             //need to manipulate the watchlist we are going through
63             vector<BinaryClause> toAttach;
64 
65             void update_solver_stats(Solver* solver);
66         };
67         ImplicitData impl_data;
68         void clean_implicit_watchlist(
69             watch_subarray& watch_list
70             , const Lit lit
71         );
72         void clean_binary_implicit(
73            Watched& ws
74             , Watched*& j
75             , const Lit lit
76         );
77 
78         void clean_clauses_pre();
79         void clean_clauses_post();
80         void clean_clauses_inter(vector<ClOffset>& cs);
81 
82         bool satisfied(const Watched& watched, Lit lit);
83         vector<ClOffset> delayed_free;
84 
85         Solver* solver;
86 };
87 
88 } //end namespace
89 
90 #endif //CLAUSECLEANER_H
91