41 #include "bj_stream.h" 42 #include "print_macros.h" 44 #include "top_exception.h" 50 #define DIMACS_DBG(prm) DBG(prm) 52 #define DIMACS_H_CK(prm) DBG_CK(prm) 54 #define MAX_DIMACS_HEADER_SZ 4096 59 DECLARE_PRINT_FUNCS(dima_dims)
69 #define first_char(pt_ch_in) (*((char*)pt_ch_in)) 85 class dimacs_exception :
public top_exception{
96 dimacs_exception(
long the_id,
char vv = 0,
long ll = -1,
long pp = -1) :
127 void update_with_sz(
long cls_sz){
129 dd_tot_lits += cls_sz;
130 if(cls_sz == 2){ dd_tot_twolits++; }
134 long max_abs_of(row<long>& all_lits){
136 for(
long aa = 0; aa < all_lits.size(); aa++){
137 long vv = abs_long(all_lits[aa]);
145 void init_dima_dims(
long ini_val = 0){
146 dd_tot_ccls = ini_val;
147 dd_tot_vars = ini_val;
148 dd_tot_lits = ini_val;
149 dd_tot_twolits = ini_val;
152 bool is_dd_virgin(
long ini_val = 0){
153 bool c1 = (dd_tot_ccls == ini_val);
154 bool c2 = (dd_tot_vars == ini_val);
155 bool c3 = (dd_tot_lits == ini_val);
156 bool c4 = (dd_tot_twolits == ini_val);
158 bool vv = (c1 && c2 && c3 && c4);
162 bj_ostream& print_dima_dims(bj_ostream& os,
bool from_pt =
false){
164 os <<
" tc=" << dd_tot_ccls;
165 os <<
" tv=" << dd_tot_vars;
166 os <<
" tl=" << dd_tot_lits;
167 os <<
" tt=" << dd_tot_twolits;
183 nid_bits(
long sz = 0){
196 void init_nid_bits(
long sz = 0){
198 nb_pos.fill(
false, sz,
false);
199 nb_neg.fill(
false, sz,
false);
202 void append_nid_bits(
long n_sz){
203 nb_pos.fill(
false, n_sz,
true);
204 nb_neg.fill(
false, n_sz,
true);
208 DIMACS_H_CK(nb_set_count == 0);
209 DIMACS_H_CK(nb_pos.size() == nb_neg.size());
211 long n_sz = nb_pos.size() + 1;
212 nb_pos.fill(
false, n_sz,
true);
213 nb_neg.fill(
false, n_sz,
true);
217 DIMACS_H_CK(nb_pos.size() == nb_neg.size());
218 return nb_pos.size();
221 bool is_true(
long nid){
222 DIMACS_H_CK(nb_pos.is_valid_idx(abs_long(nid)));
223 DIMACS_H_CK(nb_neg.is_valid_idx(abs_long(nid)));
234 void reset(
long nid){
235 DIMACS_H_CK(is_true(nid));
236 DIMACS_H_CK(! is_true(-nid));
240 nb_neg[-nid] =
false;
246 DIMACS_H_CK(! is_true(nid));
247 DIMACS_H_CK(! is_true(-nid));
256 bool any_true(
long nid){
257 return (is_true(nid) || is_true(-nid));
263 reset_all(nid_bits& bts, row<long>& rr_all,
long first_ii = 0,
long last_ii = -1){
264 long the_sz = rr_all.size();
265 if((last_ii < 0) || (last_ii > the_sz)){
268 if((first_ii < 0) || (first_ii > last_ii)){
271 for(
long aa = first_ii; aa < last_ii; aa++){
272 long nid = rr_all[aa];
279 set_all(nid_bits& bts, row<long>& rr_all,
long first_ii = 0,
long last_ii = -1){
280 long the_sz = rr_all.size();
281 if((last_ii < 0) || (last_ii > the_sz)){
284 if((first_ii < 0) || (first_ii > last_ii)){
287 for(
long aa = first_ii; aa < last_ii; aa++){
288 long nid = rr_all[aa];
303 fx_lit_already_in_clause,
304 fx_clause_has_both_lit,
306 fx_clause_has_one_lit,
310 #define RANDOM_INIT false 311 #define FIRST_LIT_IDX 1 313 #define EMPTY_CNF_COMMENT "c the cnf is empty\n" 315 class dimacs_loader {
317 dimacs_loader& operator = (dimacs_loader& other){
318 throw dimacs_exception(dix_bad_eq_op);
321 dimacs_loader(dimacs_loader& other){
322 throw dimacs_exception(dix_bad_creat);
326 typedef std::istream::pos_type ld_pos_t;
332 ch_string ld_file_name;
334 bj_ostr_stream ld_err_msg;
336 bool ld_allow_empty_cnfs;
340 long ld_max_in_ccl_sz;
343 row<char> ld_content;
344 const char* ld_cursor;
351 long ld_parsed_twolits;
357 row<integer> ld_fixes;
362 row_row_long_t ld_rr_lits1;
363 row_row_long_t ld_rr_lits2;
367 long ld_nud_added_ccls;
368 long ld_nud_added_vars;
369 long ld_nud_added_lits;
370 long ld_nud_added_twolits;
377 dimacs_loader(
brain* the_brn){
378 init_dimacs_loader(the_brn);
382 init_dimacs_loader();
385 brain* get_dbg_brn(){
386 brain* the_brn = NULL;
387 DBG(the_brn = ld_pt_brn);
391 solver* get_dbg_slv();
393 void set_dbg_brn(
brain* the_brn){
394 DBG(ld_pt_brn = the_brn);
398 void init_dimacs_loader(
brain* the_brn = NULL);
400 bj_ostr_stream& dimacs_err_msg(
long num_line,
char ch_err, ch_string msg);
402 void read_problem_decl(
const char*& pt_in,
long& num_var,
long& num_ccl,
long& line);
403 void skip_cnf_decl(
const char*& pt_in,
long line);
406 bool parse_clause(row<integer>& lits);
408 void verif_num_ccls(ch_string& f_nam,
long num_decl_ccls,
long num_read_ccls);
410 bool fix_lits(row_long_t& lits,
bool& add_it);
412 bool fixappend_lits(row_long_t& lits, row_long_t& prepared);
414 void add_lits(row_long_t& lits, row_long_t& prepared,
bool is_orig);
415 void append_rr_lits(row_row_long_t& rr_lits, row<long>& prepared);
417 void three_lits(row_long_t& lits, row_long_t& prepared);
419 void lits_opps(row<long>& r_lits);
421 void calc_f_lit_equal_or(
long d_nio, row_long_t& or_lits,
422 row_row_long_t& rr_nios);
424 void calc_f_lit_equal_and(
long d_nio, row_long_t& and_lits,
425 row_row_long_t& rr_nios);
427 long calc_f_lit_equal_or_of_ands(
long in_lit, row<long>& ccl_lits,
428 row_row_long_t& rr_lits);
430 void load_file(ch_string& f_nam);
432 void parse_all_ccls(row<long>& inst_ccls);
433 void finish_parse(row<long>& inst_ccls);
434 void parse_content(row<long>& inst_ccls);
436 void parse_file(ch_string& f_nam, row<long>& inst_ccls,
bool allow_empty =
false);
438 long get_cursor_pos();
440 ch_string calc_content_sha();
446 DEFINE_PRINT_FUNCS(dima_dims)
Class that holds all data used to solve a particular CNF instance.
Definition: brain.h:3085