Doxygen Generated Documentation of Ben-Jose Trainable SAT Solver Library
batch_solver.h
1 
2 
3 /*************************************************************
4 
5 This file is part of ben-jose.
6 
7 ben-jose is free software: you can redistribute it and/or modify
8 it under the terms of the version 3 of the GNU General Public
9 License as published by the Free Software Foundation.
10 
11 ben-jose is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with ben-jose. If not, see <http://www.gnu.org/licenses/>.
18 
19 ------------------------------------------------------------
20 
21 Copyright (C) 2007-2012, 2014-2016. QUIROGA BELTRAN, Jose Luis.
22 Id (cedula): 79523732 de Bogota - Colombia.
23 See https://github.com/joseluisquiroga/ben-jose
24 
25 ben-jose is free software thanks to The Glory of Our Lord
26  Yashua Melej Hamashiaj.
27 Our Resurrected and Living, both in Body and Spirit,
28  Prince of Peace.
29 
30 ------------------------------------------------------------
31 
32 batch_solver.h
33 
34 Declaration of classes that batch solving.
35 
36 --------------------------------------------------------------*/
37 
38 #ifndef BATCH_SOLVER_H
39 #define BATCH_SOLVER_H
40 
41 //=================================================================
42 // configuration defs
43 
44 #define DO_FINAL_GETCHAR
45 #define PRINT_TOTALS_PERIOD 10.0
46 
47 //=================================================================
48 
49 #include "tools.h"
50 #include "util_funcs.h"
51 #include "ben_jose.h"
52 
53 
54 #define BATCH_CK(prm) DBG_CK(prm)
55 
56 #define LOG_NM_ERROR "error.log"
57 #define LOG_NM_RESULTS "results.log"
58 #define LOG_NM_STATS "stats.log"
59 #define LOG_NM_ASSIGS "assigs.log"
60 #define TEST_SUF ".test"
61 
62 #define INVALID_TEST_FILE "invalid_test_file"
63 
64 //=================================================================
65 // pre-configuration decl
66 
67 #define DO_PRINTS(prm) prm
68 
69 #define PRT_OUT_0(comm) \
70  DO_PRINTS( \
71  { \
72  bj_ostream& os = bj_out; \
73  comm; \
74  os.flush(); \
75  } \
76  ) \
77 
78 //--end_of_def
79 
80 #define PRT_OUT_1(comm)
81 
82 //=================================================================
83 // aux funcs
84 
85 inline
86 ch_string
87 get_log_name(ch_string f_nam, ch_string sufix){
88  ch_string lg_nm = f_nam + "_" + sufix;
89  return lg_nm;
90 }
91 
92 //=================================================================
93 // decl
94 
95 class batch_entry;
96 
97 DECLARE_PRINT_FUNCS(batch_entry)
98 
99 //=================================================================
100 // batch_entry
101 
102 #define cbool_to_str(vv) ((vv == 0)?("0"):("1"))
103 
104 class batch_entry {
105 public:
106  ch_string be_ff_nam;
107  bj_output_t be_out;
108  ch_string be_result_str;
109 
110  batch_entry(){
111  be_ff_nam = "";
112  bj_init_output(&be_out);
113  be_result_str = "invalud_result_str";
114  }
115 
116  ~batch_entry(){
117  }
118 
119  bj_ostream& print_batch_entry(bj_ostream& os, bool from_pt = false);
120 };
121 
122 //=================================================================
123 // batch_solver
124 
125 long get_free_mem_kb();
126 
127 class batch_solver {
128 public:
129  bool using_mem_ctrl;
130 
131  ch_string help_str;
132  ch_string version_str;
133 
134  ch_string result_titles_str;
135 
136  bool op_only_deduc;
137  bool op_write_proof;
138  bool op_test_result;
139  bool op_test_save;
140 
141  bool op_dbg_as_release;
142 
143  mem_size dbg_mem_at_start;
144 
145  bool dbg_skip_print_info;
146 
147  bj_ostr_stream error_stm;
148  long error_cod;
149 
150  ch_string input_file_nm;
151 
152  bool batch_log_on;
153  ch_string batch_name;
154  ch_string batch_log_errors_pth;
155  ch_string batch_log_results_pth;
156  ch_string batch_log_stats_pth;
157  ch_string batch_log_assigs_pth;
158 
159  integer batch_num_files;
160  integer batch_consec;
161  integer batch_num_unknown_satisf;
162  integer batch_num_yes_satisf;
163  integer batch_num_no_satisf;
164  integer batch_num_timeout;
165  integer batch_num_memout;
166  integer batch_num_error;
167 
168  avg_stat batch_stat_lits;
169  avg_stat batch_stat_laps;
170  avg_stat batch_stat_solve_tm;
171  avg_stat batch_stat_mem_used;
172 
173  avg_stat batch_stat_load_tm;
174  avg_stat batch_stat_num_cnf_saved;
175  avg_stat batch_stat_num_cnf_finds;
176  avg_stat batch_stat_quick_discards;
177 
178  double batch_start_time;
179  double batch_end_time;
180  timer batch_prt_totals_timer;
181 
182  row<batch_entry> batch_instances;
183  row<batch_entry> batch_test_entries;
184 
185  bool batch_test_has_errors;
186 
187  ch_string gg_file_name;
188 
189  ch_string bc_slvr_path;
190  bj_solver_t bc_solver;
191 
192  void init_batch_solver();
193  void finish_batch_solver();
194 
195  batch_solver();
196  ~batch_solver();
197 
198  void reset_global(){
199  reset_err_msg();
200  error_cod = -1;
201  }
202 
203  bool get_args(int argc, char** argv);
204  void set_input_name();
205 
206  batch_entry& get_curr_inst(){
207  long batch_idx = batch_consec - 1;
208  DBG_CK(batch_instances.is_valid_idx(batch_idx));
209  batch_entry& the_ans = batch_instances[batch_idx];
210  return the_ans;
211  }
212 
213  bool in_valid_inst(){
214  long batch_idx = batch_consec - 1;
215  return (batch_instances.is_valid_idx(batch_idx));
216  }
217 
218  ch_string init_log_name(ch_string sufix);
219 
220  ch_string get_file_name(bool& is_batch){
221  ch_string f_nam = gg_file_name;
222  is_batch = false;
223  if(batch_name.size() > 0){
224  is_batch = true;
225  f_nam = batch_name;
226  }
227  return f_nam;
228  }
229 
230  void reset_err_msg(){
231  error_stm.clear();
232  error_stm.str() = "";
233  error_stm.flush();
234  }
235 
236  double mem_percent_used();
237 
238  void print_final_assig();
239  void count_instance(batch_entry& inst_info);
240 
241  bj_ostream& print_mini_stats(bj_ostream& os);
242  bj_ostream& print_stats(bj_ostream& os, double current_secs = 0.0);
243 
244  bj_ostream& print_mem_used(bj_ostream& os);
245  bj_ostream& print_totals(bj_ostream& os, double curr_tm = 0.0);
246  bj_ostream& print_final_totals(bj_ostream& os);
247  void print_batch_consec();
248 
249  void log_error_message(const ch_string& msg_log);
250  void log_batch_info(ch_string& log_nm);
251  void print_end_msg();
252  void read_batch_file(row<batch_entry>& names);
253  void work_all_instances();
254  void do_all_instances();
255  void do_cnf_file();
256 
257  ch_string get_test_file_path();
258  void read_test_file(row<batch_entry>& test_entries, ch_string& file_nm_str);
259  void test_result_entries();
260  bool test_entry(batch_entry& rr, batch_entry& tt);
261 };
262 
263 //=================================================================
264 // print functions
265 
266 inline
267 bj_ostream&
268 batch_entry::print_batch_entry(bj_ostream& os, bool from_pt){
269  os << be_result_str;
270  return os;
271 }
272 
273 DEFINE_PRINT_FUNCS(batch_entry)
274 
275 //=================================================================
276 // global functions
277 
278 void chomp_string(ch_string& s1);
279 int solver_main(int argc, char** argv);
280 
281 
282 #endif // BATCH_SOLVER_H
283 
void * bj_solver_t
A ben-jose solver object is of this tyoe.
Definition: ben_jose.h:165
ben_jose API declaration.
void bj_init_output(bj_output_t *the_out)
Definition: ben_jose.cpp:49