Doxygen Generated Documentation of Ben-Jose Trainable SAT Solver Library
instance_info.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 instance_info.h
33 
34 all info to keep or return of an instance cnf to solve.
35 
36 --------------------------------------------------------------*/
37 
38 #ifndef INSTANCE_INF_H
39 #define INSTANCE_INF_H
40 
41 #include "bj_big_number.h"
42 #include "tools.h"
43 #include "ch_string.h"
44 #include "ben_jose.h"
45 
46 
47 //=================================================================
48 // defs
49 
50 #define INSTANCE_CK(prm) DBG_CK(prm)
51 
52 #define INVALID_PATH "invalid_path"
53 #define INVALID_RESULT_STR "invalid_result_str"
54 
55 //=================================================================
56 // decl
57 
58 class instance_info;
59 
60 DECLARE_PRINT_FUNCS(instance_info)
61 
62 //=================================================================
63 // consecutive
64 
65 //typedef long consecutive_t;
66 typedef bj_big_int_t consecutive_t;
67 
68 #define INVALID_CONSECUTIVE -1
69 
70 #define INVALID_QUANTON_ID 0
71 #define INVALID_POLARITY 0
72 #define INVALID_LAYER -1
73 
74 //======================================================================
75 // instance_exception
76 
77 typedef enum {
78  inx_bad_eq_op,
79  inx_bad_creat,
80  inx_bad_lit
81 } in_ex_cod_t;
82 
83 class instance_exception : public top_exception {
84 public:
85  instance_exception(long the_id = 0) : top_exception(the_id)
86  {}
87 };
88 
89 //=================================================================
90 // instance_info
97 private:
98  instance_info& operator = (instance_info& other){
99  throw instance_exception(inx_bad_eq_op);
100  }
101 
102  instance_info(instance_info& other){
103  throw instance_exception(inx_bad_creat);
104  }
105 
106 public:
107  bool ist_with_assig;
108 
109  long ist_id;
110 
111  ch_string ist_file_path;
112 
113  row<char> ist_data;
114 
115  long ist_num_vars;
116  long ist_num_ccls;
117  row<long> ist_ccls;
118 
119  double ist_in_timeout;
120  double ist_in_memout;
121 
122  bj_output_t ist_out;
123 
124  avg_stat ist_num_variants_stat;
125  row<long> ist_assig;
126 
127  ch_string ist_last_proof_path;
128 
129  ch_string ist_result_titles_str;
130  ch_string ist_result_str;
131 
132  ch_string ist_err_assrt_str;
133  ch_string ist_err_stack_str;
134 
135  instance_info(){
136  init_instance_info(true);
137  }
138 
139  void init_instance_info(bool reset_lims = false, bool free_mem = true){
140  ist_with_assig = false;
141 
142  ist_id = -1;
143 
144  ist_file_path = INVALID_PATH;
145 
146  ist_data.clear(free_mem, free_mem);
147 
148  ist_num_vars = 0;
149  ist_num_ccls = 0;
150  ist_ccls.clear(free_mem, free_mem);
151 
152  if(reset_lims){
153  ist_in_timeout = -1;
154  ist_in_memout = -1;
155  }
156 
157  init_output(ist_out);
158 
159  ist_assig.clear(free_mem, free_mem);
160 
161  ist_last_proof_path = INVALID_PATH;
162 
163  ist_result_titles_str = INVALID_RESULT_STR;
164  ist_result_str = INVALID_RESULT_STR;
165 
166  ist_err_assrt_str = "no_assert_string_found";
167  ist_err_stack_str = "no_stack_string_found";
168  }
169 
171  static
172  void init_output(bj_output_t& out){
173  out.bjo_result = bjr_unknown_satisf;
174 
175  out.bjo_solve_time = 0.0;
176  out.bjo_num_vars = 0;
177  out.bjo_num_ccls = 0;
178  out.bjo_num_lits = 0;
179 
180  out.bjo_num_laps = 0.0;
181  out.bjo_num_recoils = 0.0;
182 
183  out.bjo_load_time = 0.0;
184  out.bjo_num_cnf_saved = 0.0;
185  out.bjo_num_cnf_finds = 0.0;
186  out.bjo_quick_discards = 0.0;
187 
188  out.bjo_error = bje_no_error;
189  out.bjo_err_char = 0;
190  out.bjo_err_line = -1;
191  out.bjo_err_pos = -1;
192  out.bjo_err_num_decl_cls = -1;
193  out.bjo_err_num_decl_vars = -1;
194  out.bjo_err_num_read_cls = -1;
195  out.bjo_err_bad_lit = -1;
196 
197  out.bjo_dbg_enabled = 0;
198  out.bjo_dbg_never_write = 0;
199  out.bjo_dbg_never_find = 0;
200  out.bjo_dbg_min_trainable = 0;
201  out.bjo_dbg_as_release = 0;
202  }
203 
204  ch_string& get_f_nam(){
205  return ist_file_path;
206  }
207 
208  bool is_read(){
209  return (! ist_data.is_empty());
210  }
211 
212  bool is_parsed(){
213  bool c1 = ! ist_ccls.is_empty();
214  bool c2 = (ist_num_vars >= 0);
215  bool c3 = (ist_num_ccls >= 0);
216  bool is_p = (c1 && c2 && c3);
217  return is_p;
218  }
219 
220  bj_output_t& get_out_info(){
221  return ist_out;
222  }
223 
224  void set_result_titles_str();
225  void set_result_str();
226  void parse_result_str(ch_string& rslt_str);
227 
228  static
229  bj_ostream& print_headers(bj_ostream& os);
230 
231  bj_ostream& print_instance_info(bj_ostream& os, bool from_pt = false);
232 };
233 
234 
235 //=================================================================
236 // funcs
237 
238 
239 inline
240 bj_ostream&
241 instance_info::print_headers(bj_ostream& os){
242  ch_string sep = RESULT_FIELD_SEP;
243  os << "file_path" << sep;
244  os << "solve_time" << sep;
245  os << "result" << sep;
246  os << "#vars" << sep;
247  os << "#ccls" << sep;
248  os << "#lits" << sep;
249  os << "#laps" << sep;
250  return os;
251 }
252 
253 inline
254 ch_string
255 as_satisf_str(bj_satisf_val_t vv){
256  ch_string sf_str = RES_UNKNOWN_STR;
257  switch(vv){
258  case bjr_unknown_satisf:
259  sf_str = RES_UNKNOWN_STR;
260  break;
261  case bjr_yes_satisf:
262  sf_str = RES_YES_SATISF_STR;
263  break;
264  case bjr_no_satisf:
265  sf_str = RES_NO_SATISF_STR;
266  break;
267  case bjr_error:
268  sf_str = RES_ERROR_STR;
269  break;
270  }
271  return sf_str;
272 }
273 
274 inline
276 as_satisf_val(ch_string str_ln){
278  if(str_ln == RES_UNKNOWN_STR){
279  the_val = bjr_unknown_satisf;
280  } else if(str_ln == RES_YES_SATISF_STR){
281  the_val = bjr_yes_satisf;
282  } else if(str_ln == RES_NO_SATISF_STR){
283  the_val = bjr_no_satisf;
284  } else if(str_ln == RES_ERROR_STR){
285  the_val = bjr_error;
286  }
287  return the_val;
288 }
289 
290 inline
291 bj_ostream&
292 instance_info::print_instance_info(bj_ostream& os, bool from_pt){
293  set_result_str();
294  os << ist_result_str;
295  return os;
296 }
297 
298 DEFINE_PRINT_FUNCS(instance_info)
299 
300 
301 #endif // INSTANCE_INF_H
302 
303 
Error result.
Definition: ben_jose.h:81
Class that holds an instance data.
Definition: instance_info.h:96
ben_jose API declaration.
bj_satisf_val_t
Posible final results of the solving process.
Definition: ben_jose.h:77
static void init_output(bj_output_t &out)
init and output
Definition: instance_info.h:172
#define RES_UNKNOWN_STR
String to print a bjr_unknown_satisf result.
Definition: ben_jose.h:61
No error.
Definition: ben_jose.h:91
Unsatisfiable CNF.
Definition: ben_jose.h:80
Unknown result.
Definition: ben_jose.h:78
Satisfiable CNF.
Definition: ben_jose.h:79