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 #include "cnf.h"
24 #include "propby.h"
25 #include "solvertypes.h"
26 #include <vector>
27 #include <set>
28 #include "propengine.h"
29 #include "mystack.h"
30 
31 
32 using std::vector;
33 using std::set;
34 
35 namespace CMSat {
36 
37 class HyperEngine : public PropEngine {
38 public:
39     HyperEngine(const SolverConf *_conf, Solver* solver, std::atomic<bool>* _must_interrupt_inter);
40     ~HyperEngine() override;
41     size_t mem_used() const;
42 
43     bool use_depth_trick = true;
44     bool perform_transitive_reduction = true;
45     bool timedOutPropagateFull = false;
46     Lit propagate_bfs(
47         const uint64_t earlyAborTOut = std::numeric_limits<uint64_t>::max()
48     );
49     set<BinaryClause> needToAddBinClause;       ///<We store here hyper-binary clauses to be added at the end of propagateFull()
50     set<BinaryClause> uselessBin;
51 
52     ///Add hyper-binary clause given this bin clause
53     void  add_hyper_bin(Lit p);
54 
55     ///Add hyper-binary clause given this large clause
56     void  add_hyper_bin(Lit p, const Clause& cl);
57 
58     void  enqueue_with_acestor_info(const Lit p, const Lit ancestor, const bool redStep);
59 
60 private:
61     Lit   analyzeFail(PropBy propBy);
62     Lit   remove_which_bin_due_to_trans_red(Lit conflict, Lit thisAncestor, const bool thisStepRed);
63     void  remove_bin_clause(Lit lit);
64     bool  is_ancestor_of(
65         const Lit conflict
66         , Lit thisAncestor
67         , const bool thisStepRed
68         , const bool onlyIrred
69         , const Lit lookingForAncestor
70     );
71 
72     //Find lowest common ancestor, once 'currAncestors' has been filled
73     Lit deepest_common_ancestor();
74 
75     PropResult prop_bin_with_ancestor_info(
76         const Lit p
77         , const Watched* k
78         , PropBy& confl
79     );
80 
81     PropResult prop_normal_cl_with_ancestor_info(
82         Watched* i
83         , Watched*& j
84         , const Lit p
85         , PropBy& confl
86     );
87 
88     vector<Lit> currAncestors;
89 };
90 
91 }
92