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 _SEARCHHIST_H_ 24 #define _SEARCHHIST_H_ 25 26 #include <cstdint> 27 #include "avgcalc.h" 28 #include "boundedqueue.h" 29 #include <iostream> 30 using std::cout; 31 using std::endl; 32 33 namespace CMSat { 34 35 //History 36 struct SearchHist { 37 //About the search 38 uint32_t num_conflicts_this_restart = 0; 39 AvgCalc<uint32_t> branchDepthHist; ///< Avg branch depth in current restart 40 AvgCalc<uint32_t> branchDepthDeltaHist; 41 42 AvgCalc<uint32_t> backtrackLevelHistLT; 43 AvgCalc<uint32_t> trailDepthHistLT; 44 45 bqueue<uint32_t> trailDepthHistLonger; ///<total depth, incl. props, decisions and assumps 46 AvgCalc<uint32_t> trailDepthDeltaHist; ///<for THIS restart only 47 48 //About the confl generated 49 bqueue<uint32_t> glueHist; ///< Conflict glue history (this restart only) 50 AvgCalc<uint32_t> glueHistLT; ///< Conflict glue history (all restarts) 51 AvgCalc<uint32_t> glueHistLTLimited; //As before, but ONLY glue-based restart, max 50 glue 52 53 AvgCalc<uint32_t> conflSizeHist; ///< Conflict size history (this restart only) 54 AvgCalc<uint32_t> conflSizeHistLT; ///< Conflict size history (all restarts) 55 AvgCalc<uint32_t> numResolutionsHistLT; 56 57 #if defined(STATS_NEEDED) || defined(FINAL_PREDICTOR) 58 bqueue<uint32_t> backtrackLevelHist; 59 AvgCalc<uint32_t> overlapHistLT; 60 AvgCalc<uint32_t> antec_data_sum_sizeHistLT; 61 AvgCalc<uint32_t> numResolutionsHist; ///< Number of resolutions during conflict analysis of THIS restart 62 AvgCalc<uint32_t> decisionLevelHistLT; 63 bqueue<uint32_t> branchDepthHistQueue; 64 bqueue<uint32_t> trailDepthHist; 65 #endif 66 mem_usedSearchHist67 size_t mem_used() const 68 { 69 uint64_t used = sizeof(SearchHist); 70 used += sizeof(AvgCalc<uint32_t>)*16; 71 used += sizeof(AvgCalc<bool>)*4; 72 used += sizeof(AvgCalc<size_t>)*2; 73 used += sizeof(AvgCalc<double, double>)*2; 74 used += glueHist.usedMem(); 75 used += trailDepthHistLonger.usedMem(); 76 #if defined(STATS_NEEDED) || defined(FINAL_PREDICTOR) 77 used += backtrackLevelHist.usedMem(); 78 used += branchDepthHistQueue.usedMem(); 79 #endif 80 81 return used; 82 } 83 clearSearchHist84 void clear() 85 { 86 //About the search 87 num_conflicts_this_restart = 0; 88 branchDepthHist.clear(); 89 branchDepthDeltaHist.clear(); 90 trailDepthDeltaHist.clear(); 91 92 //conflict generated 93 glueHist.clear(); 94 conflSizeHist.clear(); 95 96 #if defined(STATS_NEEDED) || defined(FINAL_PREDICTOR) 97 numResolutionsHist.clear(); 98 trailDepthHist.clear(); 99 branchDepthHistQueue.clear(); 100 #endif 101 } 102 reset_glue_hist_sizeSearchHist103 void reset_glue_hist_size(size_t shortTermHistorySize) 104 { 105 glueHist.clearAndResize(shortTermHistorySize); 106 #if defined(STATS_NEEDED) || defined(FINAL_PREDICTOR) 107 backtrackLevelHist.clearAndResize(shortTermHistorySize); 108 trailDepthHist.clearAndResize(shortTermHistorySize); 109 branchDepthHistQueue.clearAndResize(shortTermHistorySize); 110 #endif 111 } 112 setSizeSearchHist113 void setSize(const size_t shortTermHistorySize, const size_t blocking_trail_hist_size) 114 { 115 glueHist.clearAndResize(shortTermHistorySize); 116 trailDepthHistLonger.clearAndResize(blocking_trail_hist_size); 117 #if defined(STATS_NEEDED) || defined(FINAL_PREDICTOR) 118 backtrackLevelHist.clearAndResize(shortTermHistorySize); 119 trailDepthHist.clearAndResize(shortTermHistorySize); 120 branchDepthHistQueue.clearAndResize(shortTermHistorySize); 121 #endif 122 } 123 printSearchHist124 void print() const 125 { 126 cout 127 << " glue" 128 << " " 129 #ifdef STATS_NEEDED 130 << std::right << glueHist.getLongtTerm().avgPrint(1, 5) 131 #endif 132 << "/" << std::left << glueHistLT.avgPrint(1, 5) 133 134 << " confllen" 135 << " " << std::right << conflSizeHist.avgPrint(1, 5) 136 << "/" << std::left << conflSizeHistLT.avgPrint(1, 5) 137 138 << " branchd" 139 << " " << std::right << branchDepthHist.avgPrint(1, 5) 140 << " branchdd" 141 142 << " " << std::right << branchDepthDeltaHist.avgPrint(1, 4) 143 144 #ifdef STATS_NEEDED 145 << " traild" 146 << " " << std::right << trailDepthHist.getLongtTerm().avgPrint(0, 7) 147 #endif 148 149 << " traildd" 150 << " " << std::right << trailDepthDeltaHist.avgPrint(0, 5) 151 ; 152 153 cout << std::right; 154 } 155 }; 156 157 } //end namespace 158 159 #endif //_SEARCHHIST_H_ 160