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 _TOPLEVELGAUSS_H_
24 #define _TOPLEVELGAUSS_H_
25 
26 #include "xor.h"
27 #include "toplevelgaussabst.h"
28 #include <vector>
29 #include <set>
30 using std::vector;
31 using std::set;
32 
33 namespace CMSat {
34 
35 class Solver;
36 
37 class TopLevelGauss: public TopLevelGaussAbst
38 {
39 public:
40     explicit TopLevelGauss(Solver* _solver);
41     bool toplevelgauss(const vector<Xor>& _xors, vector<Lit>* _out_changed_occur) override;
42 
43     struct Stats
44     {
clearStats45         void clear()
46         {
47             Stats tmp;
48             *this = tmp;
49         }
50 
total_timeStats51         double total_time() const
52         {
53             return extractTime + blockCutTime;
54         }
55 
56         Stats& operator+=(const Stats& other);
57         void print_short(const Solver* solver) const;
58 
59         //Time
60         uint32_t numCalls = 0;
61         double extractTime = 0.0;
62         double blockCutTime = 0.0;
63 
64         //XOR stats
65         uint64_t numVarsInBlocks = 0;
66         uint64_t numBlocks = 0;
67 
68         //Usefulness stats
69         uint64_t time_outs = 0;
70         uint64_t newUnits = 0;
71         uint64_t newBins = 0;
72 
73         size_t zeroDepthAssigns = 0;
74     };
75 
76     Stats runStats;
77     Stats globalStats;
78     size_t mem_used() const override;
79 
80 private:
81     Solver* solver;
82     vector<Lit>* out_changed_occur; // may have changed the occur count of these literals
83 
84     bool extractInfo();
85     void cutIntoBlocks(const vector<size_t>& xorsToUse);
86     bool extractInfoFromBlock(const vector<uint32_t>& block, const size_t blockNum);
87     void move_xors_into_blocks();
88 
89     //Major calculated data and indexes to this data
90     vector<vector<uint32_t> > blocks; ///<Blocks of vars that are in groups of XORs
91     vector<uint32_t> varToBlock; ///<variable-> block index map
92 
93     //Temporaries for putting xors into matrix, and extracting info from matrix
94     vector<uint32_t> outerToInterVarMap;
95     vector<uint32_t> interToOUterVarMap;
96 
97     vector<Xor> xors;
98     vector<vector<uint32_t> > xors_in_blocks;
99 };
100 
101 }
102 
103 #endif // _TOPLEVELGAUSS_H_
104