Orbiter 2022
Combinatorial Objects
file_io.cpp
Go to the documentation of this file.
1/*
2 * file_io.cpp
3 *
4 * Created on: Apr 21, 2019
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11using namespace std;
12
13#include <cstdio>
14#include <sys/types.h>
15#ifdef SYSTEMUNIX
16#include <unistd.h>
17#endif
18#include <fcntl.h>
19
20
21
22namespace orbiter {
23namespace layer1_foundations {
24namespace orbiter_kernel_system {
25
26#define MY_OWN_BUFSIZE 1000000
27
29{
30
31}
32
34{
35
36}
37
38void file_io::concatenate_files(const char *fname_in_mask, int N,
39 const char *fname_out, const char *EOF_marker, int f_title_line,
40 int &cnt_total,
41 vector<int> missing_idx,
42 int verbose_level)
43{
44 int f_v = (verbose_level >= 1);
45 char fname[1000];
46 char *buf;
47 int h, cnt;
48
49 if (f_v) {
50 cout << "concatenate_files " << fname_in_mask
51 << " N=" << N << " fname_out=" << fname_out << endl;
52 }
53
54 //missing_idx = NEW_int(N);
56 cnt_total = 0;
57 {
58 ofstream fp_out(fname_out);
59 for (h = 0; h < N; h++) {
60 sprintf(fname, fname_in_mask, h);
61 if (file_size(fname) < 0) {
62 cout << "concatenate_files input file does not exist: " << fname << " skipping" << endl;
63 //missing_idx[nb_missing++] = h;
64 missing_idx.push_back(h);
65 }
66 else {
67 ifstream fp(fname);
68
69 cnt = 0;
70 while (TRUE) {
71 if (fp.eof()) {
72 cout << "Encountered End-of-file without having seem EOF "
73 "marker, perhaps the file is corrupt. "
74 "I was trying to read the file " << fname << endl;
75 missing_idx.push_back(h);
76 break;
77 }
78
79 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
80 cout << "Read: " << buf << endl;
81 if (strncmp(buf, EOF_marker, strlen(EOF_marker)) == 0) {
82 break;
83 }
84 if (f_title_line) {
85 if (h == 0 || cnt) {
86 fp_out << buf << endl;
87 }
88 }
89 else {
90 fp_out << buf << endl;
91 }
92 cnt++;
93 }
94 cnt_total += cnt;
95 }
96 } // next h
97 fp_out << EOF_marker << " " << cnt_total << endl;
98 }
99 cout << "Written file " << fname_out << " of size "
100 << file_size(fname_out) << endl;
101 FREE_char(buf);
102 cout << "There are " << missing_idx.size() << " missing files, they are:" << endl;
103 for (h = 0; h < (int) missing_idx.size(); h++) {
104 sprintf(fname, fname_in_mask, missing_idx[h]);
105 cout << h << " : " << missing_idx[h] << " : " << fname << endl;
106 }
107
108 if (f_v) {
109 cout << "concatenate_files done" << endl;
110 }
111}
112
113void file_io::concatenate_files_into(const char *fname_in_mask, int N,
114 ofstream &fp_out, const char *EOF_marker, int f_title_line,
115 int &cnt_total,
116 vector<int> &missing_idx,
117 int verbose_level)
118{
119 int f_v = (verbose_level >= 1);
120 char fname[1000];
121 char *buf;
122 int h, cnt;
123
124 if (f_v) {
125 cout << "file_io::concatenate_files_into " << fname_in_mask
126 << " N=" << N << " into an open file" << endl;
127 }
128
129 //missing_idx = NEW_int(N);
131 cnt_total = 0;
132 {
133 //ofstream fp_out(fname_out);
134 for (h = 0; h < N; h++) {
135 sprintf(fname, fname_in_mask, h);
136
137 fp_out << "# start of file " << fname << endl;
138
139 if (file_size(fname) < 0) {
140 cout << "file_io::concatenate_files_into "
141 "input file does not exist: " << fname << " skipping" << endl;
142 //missing_idx[nb_missing++] = h;
143 missing_idx.push_back(h);
144 }
145 else {
146 ifstream fp(fname);
147
148 cnt = 0;
149 while (TRUE) {
150 if (fp.eof()) {
151 cout << "Encountered End-of-file without having seem EOF "
152 "marker, perhaps the file is corrupt. "
153 "I was trying to read the file " << fname << endl;
154 missing_idx.push_back(h);
155 break;
156 }
157
158 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
159 //cout << "Read: " << buf << endl;
160 if (strncmp(buf, EOF_marker, strlen(EOF_marker)) == 0) {
161 break;
162 }
163 if (f_title_line) {
164 if (h == 0 || cnt) {
165 fp_out << buf << endl;
166 }
167 }
168 else {
169 fp_out << buf << endl;
170 }
171 cnt++;
172 }
173 cnt_total += cnt;
174 }
175 fp_out << "# end of file " << fname << endl;
176 } // next h
177 //fp_out << EOF_marker << " " << cnt_total << endl;
178 }
179 FREE_char(buf);
180 cout << "There are " << missing_idx.size() << " missing files, they are:" << endl;
181 for (h = 0; h < (int) missing_idx.size(); h++) {
182 sprintf(fname, fname_in_mask, missing_idx[h]);
183 cout << h << " : " << missing_idx[h] << " : " << fname << endl;
184 }
185
186 if (f_v) {
187 cout << "file_io::concatenate_files_into done" << endl;
188 }
189}
190
192 std::string &fname, int orbit_at_level,
193 long int *&candidates, int &nb_candidates, int verbose_level)
194{
195 int f_v = (verbose_level >= 1);
196 int f_vv = (verbose_level >= 2);
197 int nb, cand_first, i;
198
199
200 if (f_v) {
201 cout << "file_io::poset_classification_read_candidates_of_orbit" << endl;
202 cout << "verbose_level=" << verbose_level << endl;
203 cout << "orbit_at_level=" << orbit_at_level << endl;
204 }
205
206 if (file_size(fname) <= 0) {
207 cout << "file_io::poset_classification_read_candidates_of_orbit file "
208 << fname << " does not exist" << endl;
209 exit(1);
210 }
211
212 {
213 ifstream fp(fname, ios::binary);
214 fp.read((char *) &nb, sizeof(int));
215 if (orbit_at_level >= nb) {
216 cout << "file_io::poset_classification_read_candidates_of_orbit "
217 "orbit_at_level >= nb" << endl;
218 cout << "orbit_at_level=" << orbit_at_level << endl;
219 cout << "nb=" << nb << endl;
220 exit(1);
221 }
222 if (f_vv) {
223 cout << "seeking position "
224 << (1 + orbit_at_level * 2) * sizeof(int) << endl;
225 }
226 fp.seekg((1 + orbit_at_level * 2) * sizeof(int), ios::beg);
227 fp.read((char *) &nb_candidates, sizeof(int));
228 if (f_vv) {
229 cout << "nb_candidates=" << nb_candidates << endl;
230 }
231 fp.read((char *) &cand_first, sizeof(int));
232 if (f_v) {
233 cout << "cand_first=" << cand_first << endl;
234 }
235 candidates = NEW_lint(nb_candidates);
236
237 int *candidates0;
238 candidates0 = NEW_int(nb_candidates);
239 fp.seekg((1 + nb * 2 + cand_first) * sizeof(int), ios::beg);
240 for (i = 0; i < nb_candidates; i++) {
241 fp.read((char *) &candidates0[i], sizeof(int));
242 candidates[i] = candidates0[i];
243 }
244 FREE_int(candidates0);
245
246 }
247
248 if (f_v) {
249 cout << "file_io::poset_classification_read_candidates_of_orbit done" << endl;
250 }
251}
252
253
255 int level, int orbit_at_level, int level_of_candidates_file,
256 long int *S,
257 void (*early_test_func_callback)(long int *S, int len,
258 long int *candidates, int nb_candidates,
259 long int *good_candidates, int &nb_good_candidates,
260 void *data, int verbose_level),
261 void *early_test_func_callback_data,
262 long int *&candidates,
263 int &nb_candidates,
264 int verbose_level)
265{
266 int f_v = (verbose_level >= 1);
267 int h, orbit_idx;
268 long int *candidates1 = NULL;
269 int nb_candidates1;
270
271 if (f_v) {
272 cout << "read_candidates_for_one_orbit_from_file" << endl;
273 cout << "level=" << level
274 << " orbit_at_level=" << orbit_at_level
275 << " level_of_candidates_file="
276 << level_of_candidates_file << endl;
277 }
278
279 orbit_idx = find_orbit_index_in_data_file(prefix,
280 level_of_candidates_file, S,
281 verbose_level);
282
283 if (f_v) {
284 cout << "read_candidates_for_one_orbit_from_file "
285 "orbit_idx=" << orbit_idx << endl;
286 }
287
288 if (f_v) {
289 cout << "read_orbit_rep_and_candidates_from_files "
290 "before generator_read_candidates_of_orbit" << endl;
291 }
292 string fname2;
293
294 char str[1000];
295 fname2.assign(prefix);
296 sprintf(str, "_lvl_%d_candidates.bin", level_of_candidates_file);
297 fname2.append(str);
298
300 fname2, orbit_idx,
301 candidates1, nb_candidates1, verbose_level - 1);
302
303
304 for (h = level_of_candidates_file; h < level; h++) {
305
306 long int *candidates2;
307 int nb_candidates2;
308
309 if (f_v) {
310 cout << "read_orbit_rep_and_candidates_from_files_"
311 "and_process testing candidates at level " << h
312 << " number of candidates = " << nb_candidates1 << endl;
313 }
314 candidates2 = NEW_lint(nb_candidates1);
315
316 (*early_test_func_callback)(S, h + 1,
317 candidates1, nb_candidates1,
318 candidates2, nb_candidates2,
319 early_test_func_callback_data, 0 /*verbose_level - 1*/);
320
321 if (f_v) {
322 cout << "read_orbit_rep_and_candidates_from_files_"
323 "and_process number of candidates at level "
324 << h + 1 << " reduced from " << nb_candidates1
325 << " to " << nb_candidates2 << " by "
326 << nb_candidates1 - nb_candidates2 << endl;
327 }
328
329 Lint_vec_copy(candidates2, candidates1, nb_candidates2);
330 nb_candidates1 = nb_candidates2;
331
332 FREE_lint(candidates2);
333 }
334
335 candidates = candidates1;
336 nb_candidates = nb_candidates1;
337
338 if (f_v) {
339 cout << "read_candidates_for_one_orbit_from_file done" << endl;
340 }
341}
342
343
344
346 int level_of_candidates_file, long int *starter,
347 int verbose_level)
348{
349 int f_v = (verbose_level >= 1);
350 string fname;
351 char str[1000];
352 int orbit_idx;
353
354 if (f_v) {
355 cout << "find_orbit_index_in_data_file" << endl;
356 }
357
358 fname.assign(prefix);
359 sprintf(str, "_lvl_%d", level_of_candidates_file);
360 fname.append(str);
361
362 if (file_size(fname) <= 0) {
363 cout << "find_orbit_index_in_data_file file "
364 << fname << " does not exist" << endl;
365 exit(1);
366 }
367 ifstream f(fname);
369 int a, i, cnt;
370 long int *S;
371 char buf[MY_OWN_BUFSIZE];
372 int len, str_len;
373 char *p_buf;
374
375 S = NEW_lint(level_of_candidates_file);
376
377 cnt = 0;
378 f.getline(buf, MY_OWN_BUFSIZE, '\n'); // skip the first line
379
380 orbit_idx = 0;
381
382 while (TRUE) {
383 if (f.eof()) {
384 break;
385 }
386 f.getline(buf, MY_OWN_BUFSIZE, '\n');
387 //cout << "Read line " << cnt << "='" << buf << "'" << endl;
388 str_len = strlen(buf);
389 if (str_len == 0) {
390 cout << "read_orbit_rep_and_candidates_from_files "
391 "str_len == 0" << endl;
392 exit(1);
393 }
394
395 // check for comment line:
396 if (buf[0] == '#')
397 continue;
398
399 p_buf = buf;
400 ST.s_scan_int(&p_buf, &a);
401 if (a == -1) {
402 break;
403 }
404 len = a;
405 if (a != level_of_candidates_file) {
406 cout << "a != level_of_candidates_file" << endl;
407 cout << "a=" << a << endl;
408 cout << "level_of_candidates_file="
409 << level_of_candidates_file << endl;
410 exit(1);
411 }
412 for (i = 0; i < len; i++) {
413 ST.s_scan_lint(&p_buf, &S[i]);
414 }
415 for (i = 0; i < level_of_candidates_file; i++) {
416 if (S[i] != starter[i]) {
417 break;
418 }
419 }
420 if (i == level_of_candidates_file) {
421 // We found the representative that matches the prefix:
422 orbit_idx = cnt;
423 break;
424 }
425 else {
426 cnt++;
427 }
428 }
429 FREE_lint(S);
430 if (f_v) {
431 cout << "find_orbit_index_in_data_file done" << endl;
432 }
433 return orbit_idx;
434}
435
436
438 int nb_rows, int nb_cols, std::string &fname)
439{
440 int i, j, d;
441
442 {
443 ofstream fp(fname);
444 fp << nb_rows << " " << nb_cols << endl;
445 for (i = 0; i < nb_rows; i++) {
446 d = 0;
447 for (j = 0; j < nb_cols; j++) {
448 if (Inc[i * nb_cols + j]) {
449 d++;
450 }
451 }
452 fp << d;
453 for (j = 0; j < nb_cols; j++) {
454 if (Inc[i * nb_cols + j]) {
455 fp << " " << j;
456 }
457 }
458 fp << endl;
459 }
460 }
461 cout << "write_exact_cover_problem_to_file written file "
462 << fname << " of size " << file_size(fname) << endl;
463}
464
465#define BUFSIZE_READ_SOLUTION_FILE ONE_MILLION
466
467void file_io::read_solution_file(std::string &fname,
468 int *Inc, int nb_rows, int nb_cols,
469 int *&Solutions, int &sol_length, int &nb_sol,
470 int verbose_level)
471// sol_length must be constant
472{
473 int f_v = (verbose_level >= 1);
474 int nb, nb_max, i, j, a, nb_sol1;
475 int *x, *y;
477
478 if (f_v) {
479 cout << "file_io::read_solution_file" << endl;
480 }
481 x = NEW_int(nb_cols);
482 y = NEW_int(nb_rows);
483 if (f_v) {
484 cout << "file_io::read_solution_file reading file " << fname
485 << " of size " << file_size(fname) << endl;
486 }
487 if (file_size(fname) <= 0) {
488 cout << "file_io::read_solution_file "
489 "There is something wrong with the file "
490 << fname << endl;
491 exit(1);
492 }
493 char *buf;
494 char *p_buf;
496 nb_sol = 0;
497 nb_max = 0;
498 {
499 ifstream f(fname);
500
501 while (!f.eof()) {
502 f.getline(buf, BUFSIZE_READ_SOLUTION_FILE, '\n');
503 p_buf = buf;
504 if (strlen(buf)) {
505 if (buf[0] == '#') {
506 continue;
507 }
508 for (j = 0; j < nb_cols; j++) {
509 x[j] = 0;
510 }
511 ST.s_scan_int(&p_buf, &nb);
512 if (nb_sol == 0) {
513 nb_max = nb;
514 }
515 else {
516 if (nb != nb_max) {
517 cout << "file_io::read_solution_file "
518 "solutions have different length" << endl;
519 exit(1);
520 }
521 }
522 //cout << "buf='" << buf << "' nb=" << nb << endl;
523
524 for (i = 0; i < nb_rows; i++) {
525 y[i] = 0;
526 }
527 for (i = 0; i < nb_rows; i++) {
528 for (j = 0; j < nb_cols; j++) {
529 y[i] += Inc[i * nb_cols + j] * x[j];
530 }
531 }
532 for (i = 0; i < nb_rows; i++) {
533 if (y[i] != 1) {
534 cout << "file_io::read_solution_file "
535 "Not a solution!" << endl;
536 Int_vec_print_fully(cout, y, nb_rows);
537 cout << endl;
538 exit(1);
539 }
540 }
541 nb_sol++;
542 }
543 }
544 }
545 if (f_v) {
546 cout << "file_io::read_solution_file: Counted " << nb_sol
547 << " solutions in " << fname
548 << " starting to read now." << endl;
549 }
550 sol_length = nb_max;
551 Solutions = NEW_int(nb_sol * sol_length);
552 nb_sol1 = 0;
553 {
554 ifstream f(fname);
555
556 while (!f.eof()) {
557 f.getline(buf, BUFSIZE_READ_SOLUTION_FILE, '\n');
558 p_buf = buf;
559 if (strlen(buf)) {
560 for (j = 0; j < nb_cols; j++) {
561 x[j] = 0;
562 }
563 ST.s_scan_int(&p_buf, &nb);
564 //cout << "buf='" << buf << "' nb=" << nb << endl;
565
566 for (i = 0; i < sol_length; i++) {
567 ST.s_scan_int(&p_buf, &a);
568 Solutions[nb_sol1 * sol_length + i] = a;
569 }
570 nb_sol1++;
571 }
572 }
573 }
574 if (f_v) {
575 cout << "file_io::read_solution_file: Read " << nb_sol
576 << " solutions from file " << fname << endl;
577 }
578 FREE_int(x);
579 FREE_int(y);
580 FREE_char(buf);
581 if (f_v) {
582 cout << "file_io::read_solution_file done" << endl;
583 }
584}
585
587 std::string &fname,
588 int &nb_solutions, int &solution_size,
589 int verbose_level)
590{
591 int f_v = (verbose_level >= 1);
592 char *buf;
594 int s;
595
596 if (f_v) {
597 cout << "file_io::count_number_of_solutions_in_file_and_get_solution_size " << fname << endl;
598 cout << "trying to read file " << fname << " of size "
599 << file_size(fname) << endl;
600 }
601
602 nb_solutions = 0;
603 if (file_size(fname) < 0) {
604 cout << "file_io::count_number_of_solutions_in_file_and_get_solution_size file "
605 << fname << " does not exist" << endl;
606 exit(1);
607 //return;
608 }
609
611
612
613
614 solution_size = -1;
615 {
616 ifstream fp(fname);
617 char *p_buf;
618 int line_number = 1;
619
620
621 while (TRUE) {
622 if (fp.eof()) {
623 cout << "file_io::count_number_of_solutions_in_file_and_get_solution_size "
624 "eof, break" << endl;
625 break;
626 }
627 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
628 //cout << "read line '" << buf << "'" << endl;
629 if (strlen(buf) == 0) {
630 cout << "file_io::count_number_of_solutions_in_file_and_get_solution_size "
631 "line " << line_number << " empty line" << endl;
632 exit(1);
633 }
634 if (buf[0] == '#') {
635 line_number++;
636 continue;
637 }
638
639 p_buf = buf;
640 ST.s_scan_int(&p_buf, &s);
641 if (solution_size == -1) {
642 solution_size = s;
643 }
644 else {
645 if (s != -1) {
646 if (solution_size != s) {
647 cout << "file_io::count_number_of_solutions_in_file_and_get_solution_size "
648 "solution_size is not constant" << endl;
649 cout << "solution_size=" << solution_size << endl;
650 cout << "s=" << s << endl;
651 cout << "line " << line_number << endl;
652 exit(1);
653 }
654 }
655 }
656
657 if (strncmp(buf, "-1", 2) == 0) {
658 break;
659 }
660 nb_solutions++;
661 line_number++;
662 }
663 }
664 FREE_char(buf);
665 if (f_v) {
666 cout << "file_io::count_number_of_solutions_in_file_and_get_solution_size " << fname << endl;
667 cout << "nb_solutions = " << nb_solutions << endl;
668 }
669}
670
672 int &nb_solutions,
673 int verbose_level)
674{
675 int f_v = (verbose_level >= 1);
676 char *buf;
677
678 if (f_v) {
679 cout << "count_number_of_solutions_in_file " << fname << endl;
680 cout << "trying to read file " << fname << " of size "
681 << file_size(fname) << endl;
682 }
683
684 nb_solutions = 0;
685 if (file_size(fname) < 0) {
686 cout << "count_number_of_solutions_in_file file "
687 << fname << " does not exist" << endl;
688 exit(1);
689 //return;
690 }
691
693
694
695
696 {
697
698 ifstream fp(fname);
699
700
701 while (TRUE) {
702 if (fp.eof()) {
703 cout << "count_number_of_solutions_in_file "
704 "eof, break" << endl;
705 break;
706 }
707 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
708 //cout << "read line '" << buf << "'" << endl;
709 if (strlen(buf) == 0) {
710 cout << "count_number_of_solutions_in_file "
711 "empty line" << endl;
712 exit(1);
713 }
714 if (buf[0] == '#') {
715 continue;
716 }
717
718 if (strncmp(buf, "-1", 2) == 0) {
719 break;
720 }
721 nb_solutions++;
722 }
723 }
724 FREE_char(buf);
725 if (f_v) {
726 cout << "count_number_of_solutions_in_file " << fname << endl;
727 cout << "nb_solutions = " << nb_solutions << endl;
728 }
729}
730
732 int *&nb_solutions, int *&case_nb, int &nb_cases,
733 int verbose_level)
734{
735 int f_v = (verbose_level >= 1);
736 char *buf;
737 //int nb_sol;
738 int N = 1000;
739 int i;
740 int the_case;
741 int the_case_count = 0;
742
743 if (f_v) {
744 cout << "count_number_of_solutions_in_file_by_case "
745 << fname << endl;
746 cout << "trying to read file " << fname << " of size "
747 << file_size(fname) << endl;
748 }
749
750 nb_solutions = NEW_int(N);
751 case_nb = NEW_int(N);
752 nb_cases = 0;
753 if (file_size(fname) < 0) {
754 cout << "count_number_of_solutions_in_file_by_case file "
755 << fname << " does not exist" << endl;
756 exit(1);
757 //return;
758 }
759
761
762
763
764 {
765 ifstream fp(fname);
766
767
768 //nb_sol = 0;
769 the_case = -1;
770 while (TRUE) {
771 if (fp.eof()) {
772 cout << "count_number_of_solutions_in_file_by_case "
773 "eof, break" << endl;
774 break;
775 }
776 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
777 //cout << "read line '" << buf << "'" << endl;
778 if (strlen(buf) == 0) {
779 cout << "count_number_of_solutions_in_file_by_case "
780 "empty line, break" << endl;
781 break;
782 }
783
784 if (strncmp(buf, "# start case", 12) == 0) {
785 the_case = atoi(buf + 13);
786 the_case_count = 0;
787 cout << "count_number_of_solutions_in_file_by_case "
788 "read start case " << the_case << endl;
789 }
790 else if (strncmp(buf, "# end case", 10) == 0) {
791 if (nb_cases == N) {
792 int *nb_solutions1;
793 int *case_nb1;
794
795 nb_solutions1 = NEW_int(N + 1000);
796 case_nb1 = NEW_int(N + 1000);
797 for (i = 0; i < N; i++) {
798 nb_solutions1[i] = nb_solutions[i];
799 case_nb1[i] = case_nb[i];
800 }
801 FREE_int(nb_solutions);
802 FREE_int(case_nb);
803 nb_solutions = nb_solutions1;
804 case_nb = case_nb1;
805 N += 1000;
806 }
807 nb_solutions[nb_cases] = the_case_count;
808 case_nb[nb_cases] = the_case;
809 nb_cases++;
810 //cout << "count_number_of_solutions_in_file_by_case "
811 //"read end case " << the_case << endl;
812 the_case = -1;
813 }
814 else {
815 if (the_case >= 0) {
816 the_case_count++;
817 }
818 }
819
820 }
821 }
822 FREE_char(buf);
823 if (f_v) {
824 cout << "count_number_of_solutions_in_file_by_case "
825 << fname << endl;
826 cout << "nb_cases = " << nb_cases << endl;
827 }
828}
829
830
832 int &nb_solutions, int *&Solutions, int &solution_size,
833 int verbose_level)
834{
835 int f_v = (verbose_level >= 1);
836
837 if (f_v) {
838 cout << "read_solutions_from_file_and_get_solution_size" << endl;
839 cout << "read_solutions_from_file_and_get_solution_size trying to read file "
840 << fname << " of size " << file_size(fname) << endl;
841 }
842
843 if (file_size(fname) < 0) {
844 cout << "file_io::read_solutions_from_file_and_get_solution_size "
845 "the file " << fname << " does not exist" << endl;
846 return;
847 }
848
850 nb_solutions, solution_size,
851 verbose_level - 2);
852
853 if (f_v) {
854 cout << "file_io::read_solutions_from_file_and_get_solution_size, reading "
855 << nb_solutions << " solutions of size " << solution_size << endl;
856 }
857
858 Solutions = NEW_int(nb_solutions * solution_size);
859
861 char *buf;
862 char *p_buf;
863 int i, a, nb_sol;
864
866 nb_sol = 0;
867 {
868 ifstream f(fname);
869
870 while (!f.eof()) {
871 f.getline(buf, MY_OWN_BUFSIZE, '\n');
872 if (strlen(buf) && buf[0] == '#') {
873 continue;
874 }
875 p_buf = buf;
876 //cout << "buf='" << buf << "' nb=" << nb << endl;
877 ST.s_scan_int(&p_buf, &a);
878
879 if (a == -1) {
880 break;
881 }
882 if (a != solution_size) {
883 cout << "file_io::read_solutions_from_file_and_get_solution_size "
884 "a != solution_size" << endl;
885 exit(1);
886 }
887 for (i = 0; i < solution_size; i++) {
888 ST.s_scan_int(&p_buf, &a);
889 Solutions[nb_sol * solution_size + i] = a;
890 }
891 nb_sol++;
892 }
893 }
894 if (nb_sol != nb_solutions) {
895 cout << "file_io::read_solutions_from_file_and_get_solution_size "
896 "nb_sol != nb_solutions" << endl;
897 exit(1);
898 }
899 FREE_char(buf);
900
901 if (f_v) {
902 cout << "file_io::read_solutions_from_file_and_get_solution_size" << endl;
903 }
904}
905
906
907void file_io::read_solutions_from_file(std::string &fname,
908 int &nb_solutions, int *&Solutions, int solution_size,
909 int verbose_level)
910{
911 int f_v = (verbose_level >= 1);
912 char *buf;
913 char *p_buf;
914 int i, a, nb_sol;
916
917 if (f_v) {
918 cout << "read_solutions_from_file" << endl;
919 cout << "read_solutions_from_file trying to read file "
920 << fname << " of size " << file_size(fname) << endl;
921 cout << "read_solutions_from_file solution_size="
922 << solution_size << endl;
923 }
924
925 if (file_size(fname) < 0) {
926 cout << "file_io::read_solutions_from_file the file " << fname << " does not exist" << endl;
927 return;
928 }
929
931
933 nb_solutions,
934 verbose_level - 2);
935 if (f_v) {
936 cout << "read_solutions_from_file, reading "
937 << nb_solutions << " solutions" << endl;
938 }
939
940
941
942 Solutions = NEW_int(nb_solutions * solution_size);
943
944 nb_sol = 0;
945 {
946 ifstream f(fname);
947
948 while (!f.eof()) {
949 f.getline(buf, MY_OWN_BUFSIZE, '\n');
950 p_buf = buf;
951 //cout << "buf='" << buf << "' nb=" << nb << endl;
952 ST.s_scan_int(&p_buf, &a);
953
954 if (a == -1) {
955 break;
956 }
957 if (a != solution_size) {
958 cout << "read_solutions_from_file "
959 "a != solution_size" << endl;
960 exit(1);
961 }
962 for (i = 0; i < solution_size; i++) {
963 ST.s_scan_int(&p_buf, &a);
964 Solutions[nb_sol * solution_size + i] = a;
965 }
966 nb_sol++;
967 }
968 }
969 if (nb_sol != nb_solutions) {
970 cout << "read_solutions_from_file "
971 "nb_sol != nb_solutions" << endl;
972 exit(1);
973 }
974 FREE_char(buf);
975 if (f_v) {
976 cout << "read_solutions_from_file done" << endl;
977 }
978}
979
980
982 std::vector<std::vector<int> > &Solutions, int solution_size,
983 int verbose_level)
984{
985 int f_v = (verbose_level >= 1);
986 char *buf;
987 char *p_buf;
988 vector<int> one_solution;
990 int i, a;
991
992 if (f_v) {
993 cout << "read_solutions_from_file_size_is_known" << endl;
994 cout << "read_solutions_from_file_size_is_known trying to read file "
995 << fname << " of size " << file_size(fname) << endl;
996 cout << "read_solutions_from_file_size_is_known solution_size="
997 << solution_size << endl;
998 }
999
1000 if (file_size(fname.c_str()) < 0) {
1001 cout << "file_io::read_solutions_from_file_size_is_known the file " << fname << " does not exist" << endl;
1002 return;
1003 }
1004
1005 buf = NEW_char(MY_OWN_BUFSIZE);
1006
1007 one_solution.resize(solution_size);
1008
1009 {
1010 ifstream f(fname);
1011
1012 while (!f.eof()) {
1013 f.getline(buf, MY_OWN_BUFSIZE, '\n');
1014 p_buf = buf;
1015 //cout << "buf='" << buf << "' nb=" << nb << endl;
1016 ST.s_scan_int(&p_buf, &a);
1017
1018 if (a == -1) {
1019 break;
1020 }
1021
1022 one_solution[0] = a;
1023 for (i = 1; i < solution_size; i++) {
1024 ST.s_scan_int(&p_buf, &a);
1025 one_solution[i] = a;
1026 }
1027 Solutions.push_back(one_solution);
1028 }
1029 }
1030 FREE_char(buf);
1031 if (f_v) {
1032 cout << "read_solutions_from_file_size_is_known done" << endl;
1033 }
1034}
1035
1036
1038 int *nb_solutions, int *case_nb, int nb_cases,
1039 int **&Solutions, int solution_size,
1040 int verbose_level)
1041{
1042 int f_v = (verbose_level >= 1);
1043 char *buf;
1044 //int nb_sol;
1045 int i;
1046 int nb_case1;
1047 int the_case;
1048 int the_case_count = 0;
1050
1051 if (f_v) {
1052 cout << "read_solutions_from_file_by_case" << endl;
1053 cout << "read_solutions_from_file_by_case trying to read file "
1054 << fname << " of size " << file_size(fname) << endl;
1055 cout << "read_solutions_from_file_by_case solution_size="
1056 << solution_size << endl;
1057 }
1058
1059 if (file_size(fname) < 0) {
1060 return;
1061 }
1062
1063 buf = NEW_char(MY_OWN_BUFSIZE);
1064
1065 Solutions = NEW_pint(nb_cases);
1066
1067 {
1068 ifstream fp(fname);
1069
1070
1071 //nb_sol = 0;
1072 nb_case1 = 0;
1073 the_case = -1;
1074 while (TRUE) {
1075 if (fp.eof()) {
1076 break;
1077 }
1078 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
1079 //cout << "read line '" << buf << "'" << endl;
1080 if (strlen(buf) == 0) {
1081 cout << "read_solutions_from_file_by_case "
1082 "empty line, break" << endl;
1083 break;
1084 }
1085
1086 if (strncmp(buf, "# start case", 12) == 0) {
1087 the_case = atoi(buf + 13);
1088 the_case_count = 0;
1089 if (the_case != case_nb[nb_case1]) {
1090 cout << "read_solutions_from_file_by_case "
1091 "the_case != case_nb[nb_case1]" << endl;
1092 exit(1);
1093 }
1094 Solutions[nb_case1] =
1095 NEW_int(nb_solutions[nb_case1] * solution_size);
1096 cout << "read_solutions_from_file_by_case "
1097 "read start case " << the_case << endl;
1098 }
1099 else if (strncmp(buf, "# end case", 10) == 0) {
1100 if (the_case_count != nb_solutions[nb_case1]) {
1101 cout << "read_solutions_from_file_by_case "
1102 "the_case_count != nb_solutions[nb_case1]" << endl;
1103 exit(1);
1104 }
1105 cout << "read_solutions_from_file_by_case "
1106 "read end case " << the_case << endl;
1107 nb_case1++;
1108 the_case = -1;
1109 }
1110 else {
1111 if (the_case >= 0) {
1112 char *p_buf;
1113 int sz, a;
1114
1115 //cout << "read_solutions_from_file_by_case "
1116 //"reading solution " << the_case_count
1117 //<< " for case " << the_case << endl;
1118 p_buf = buf;
1119 ST.s_scan_int(&p_buf, &sz);
1120 if (sz != solution_size) {
1121 cout << "read_solutions_from_file_by_case "
1122 "sz != solution_size" << endl;
1123 exit(1);
1124 }
1125 for (i = 0; i < sz; i++) {
1126 ST.s_scan_int(&p_buf, &a);
1127 Solutions[nb_case1][the_case_count * solution_size + i] = a;
1128 }
1129 the_case_count++;
1130 }
1131 }
1132 }
1133 }
1134 FREE_char(buf);
1135 if (f_v) {
1136 cout << "read_solutions_from_file_by_case done" << endl;
1137 }
1138}
1139
1140void file_io::copy_file_to_ostream(ostream &ost, const char *fname)
1141{
1142 //char buf[MY_OWN_BUFSIZE];
1143
1144 {
1145 ifstream fp(fname);
1146
1147#if 0
1148 while (TRUE) {
1149 if (fp.eof()) {
1150 break;
1151 }
1152 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
1153
1154#if 0
1155 // check for comment line:
1156 if (buf[0] == '#')
1157 continue;
1158#endif
1159
1160 ost << buf << endl;
1161 }
1162#endif
1163 while (TRUE) {
1164 char c;
1165 fp.get(c);
1166 if (fp.eof()) {
1167 break;
1168 }
1169 ost << c;
1170 }
1171 }
1172
1173}
1174
1175void file_io::int_vec_write_csv(int *v, int len,
1176 std::string &fname, const char *label)
1177{
1178 int i;
1179
1180 {
1181 ofstream f(fname);
1182
1183 f << "Case," << label << endl;
1184 for (i = 0; i < len; i++) {
1185 f << i << "," << v[i] << endl;
1186 }
1187 f << "END" << endl;
1188 }
1189}
1190
1191void file_io::lint_vec_write_csv(long int *v, int len,
1192 std::string &fname, const char *label)
1193{
1194 int i;
1195
1196 {
1197 ofstream f(fname);
1198
1199 f << "Case," << label << endl;
1200 for (i = 0; i < len; i++) {
1201 f << i << "," << v[i] << endl;
1202 }
1203 f << "END" << endl;
1204 }
1205}
1206
1207void file_io::int_vecs_write_csv(int *v1, int *v2, int len,
1208 std::string &fname, const char *label1, const char *label2)
1209{
1210 int i;
1211
1212 {
1213 ofstream f(fname);
1214
1215 f << "Case," << label1 << "," << label2 << endl;
1216 for (i = 0; i < len; i++) {
1217 f << i << "," << v1[i] << "," << v2[i] << endl;
1218 }
1219 f << "END" << endl;
1220 }
1221}
1222
1223void file_io::int_vecs3_write_csv(int *v1, int *v2, int *v3, int len,
1224 std::string &fname,
1225 const char *label1, const char *label2, const char *label3)
1226{
1227 int i;
1228
1229 {
1230 ofstream f(fname);
1231
1232 f << "Case," << label1 << "," << label2 << "," << label3 << endl;
1233 for (i = 0; i < len; i++) {
1234 f << i << "," << v1[i] << "," << v2[i] << "," << v3[i] << endl;
1235 }
1236 f << "END" << endl;
1237 }
1238}
1239
1240void file_io::int_vec_array_write_csv(int nb_vecs, int **Vec, int len,
1241 std::string &fname, const char **column_label)
1242{
1243 int i, j;
1244
1245 cout << "int_vec_array_write_csv nb_vecs=" << nb_vecs << endl;
1246 cout << "column labels:" << endl;
1247 for (j = 0; j < nb_vecs; j++) {
1248 cout << j << " : " << column_label[j] << endl;
1249 }
1250
1251 {
1252 ofstream f(fname);
1253
1254 f << "Row";
1255 for (j = 0; j < nb_vecs; j++) {
1256 f << "," << column_label[j];
1257 }
1258 f << endl;
1259 for (i = 0; i < len; i++) {
1260 f << i;
1261 for (j = 0; j < nb_vecs; j++) {
1262 f << "," << Vec[j][i];
1263 }
1264 f << endl;
1265 }
1266 f << "END" << endl;
1267 }
1268}
1269
1270void file_io::lint_vec_array_write_csv(int nb_vecs, long int **Vec, int len,
1271 std::string &fname, const char **column_label)
1272{
1273 int i, j;
1274
1275 cout << "lint_vec_array_write_csv nb_vecs=" << nb_vecs << endl;
1276 cout << "column labels:" << endl;
1277 for (j = 0; j < nb_vecs; j++) {
1278 cout << j << " : " << column_label[j] << endl;
1279 }
1280
1281 {
1282 ofstream f(fname);
1283
1284 f << "Row";
1285 for (j = 0; j < nb_vecs; j++) {
1286 f << "," << column_label[j];
1287 }
1288 f << endl;
1289 for (i = 0; i < len; i++) {
1290 f << i;
1291 for (j = 0; j < nb_vecs; j++) {
1292 f << "," << Vec[j][i];
1293 }
1294 f << endl;
1295 }
1296 f << "END" << endl;
1297 }
1298}
1299
1300void file_io::int_matrix_write_csv(std::string &fname, int *M, int m, int n)
1301{
1302 int i, j;
1303
1304 {
1305 ofstream f(fname);
1306
1307 f << "Row";
1308 for (j = 0; j < n; j++) {
1309 f << ",C" << j;
1310 }
1311 f << endl;
1312 for (i = 0; i < m; i++) {
1313 f << i;
1314 for (j = 0; j < n; j++) {
1315 f << "," << M[i * n + j];
1316 }
1317 f << endl;
1318 }
1319 f << "END" << endl;
1320 }
1321}
1322
1323void file_io::lint_matrix_write_csv(std::string &fname, long int *M, int m, int n)
1324{
1325 int i, j;
1326
1327 {
1328 ofstream f(fname);
1329
1330 f << "Row";
1331 for (j = 0; j < n; j++) {
1332 f << ",C" << j;
1333 }
1334 f << endl;
1335 for (i = 0; i < m; i++) {
1336 f << i;
1337 for (j = 0; j < n; j++) {
1338 f << "," << M[i * n + j];
1339 }
1340 f << endl;
1341 }
1342 f << "END" << endl;
1343 }
1344}
1345
1346void file_io::lint_matrix_write_csv_override_headers(std::string &fname, std::string *headers, long int *M, int m, int n)
1347{
1348 int i, j;
1349
1350 {
1351 ofstream f(fname);
1352
1353 f << "Row";
1354 for (j = 0; j < n; j++) {
1355 f << "," << headers[j];
1356 }
1357 f << endl;
1358 for (i = 0; i < m; i++) {
1359 f << i;
1360 for (j = 0; j < n; j++) {
1361 f << "," << M[i * n + j];
1362 }
1363 f << endl;
1364 }
1365 f << "END" << endl;
1366 }
1367}
1368
1369void file_io::vector_matrix_write_csv(std::string &fname, std::vector<std::vector<int> > &V)
1370{
1371 int i, j;
1372 int m, n;
1373
1374 m = V.size();
1375 n = V[0].size();
1376 for (i = 0; i < m; i++) {
1377 if (V[i].size() != n) {
1378 cout << "file_io::int_matrix_write_csv the vectors are of differing lengths" << endl;
1379 exit(1);
1380 }
1381 }
1382
1383
1384 {
1385 ofstream f(fname);
1386
1387 f << "Row";
1388 for (j = 0; j < n; j++) {
1389 f << ",C" << j;
1390 }
1391 f << endl;
1392 for (i = 0; i < m; i++) {
1393 f << i;
1394 for (j = 0; j < n; j++) {
1395 f << "," << V[i][j];
1396 }
1397 f << endl;
1398 }
1399 f << "END" << endl;
1400 }
1401}
1402
1403
1404
1406 std::string &fname, double *M, int m, int n)
1407{
1408 int i, j;
1409
1410 {
1411 ofstream f(fname);
1412
1413 f << "Row";
1414 for (j = 0; j < n; j++) {
1415 f << ",C" << j;
1416 }
1417 f << endl;
1418 for (i = 0; i < m; i++) {
1419 f << i;
1420 for (j = 0; j < n; j++) {
1421 f << "," << M[i * n + j];
1422 }
1423 f << endl;
1424 }
1425 f << "END" << endl;
1426 }
1427}
1428
1430 int *M, int m, int n, const char **column_label)
1431{
1432 int i, j;
1433
1434 {
1435 ofstream f(fname);
1436
1437 f << "Row";
1438 for (j = 0; j < n; j++) {
1439 f << "," << column_label[j];
1440 }
1441 f << endl;
1442 for (i = 0; i < m; i++) {
1443 f << i;
1444 for (j = 0; j < n; j++) {
1445 f << "," << M[i * n + j];
1446 }
1447 f << endl;
1448 }
1449 f << "END" << endl;
1450 }
1451}
1452
1454 long int *M, int m, int n, const char **column_label)
1455{
1456 int i, j;
1457
1458 {
1459 ofstream f(fname);
1460
1461 f << "Row";
1462 for (j = 0; j < n; j++) {
1463 f << "," << column_label[j];
1464 }
1465 f << endl;
1466 for (i = 0; i < m; i++) {
1467 f << i;
1468 for (j = 0; j < n; j++) {
1469 f << "," << M[i * n + j];
1470 }
1471 f << endl;
1472 }
1473 f << "END" << endl;
1474 }
1475}
1476
1477void file_io::int_matrix_read_csv(std::string &fname,
1478 int *&M, int &m, int &n, int verbose_level)
1479{
1480 int f_v = (verbose_level >= 1);
1481 int i, j, a;
1482
1483 if (f_v) {
1484 cout << "file_io::int_matrix_read_csv reading file " << fname << endl;
1485 }
1486 if (file_size(fname) <= 0) {
1487 cout << "int_matrix_read_csv file " << fname
1488 << " does not exist or is empty" << endl;
1489 cout << "file_size(fname)=" << file_size(fname) << endl;
1490 exit(1);
1491 }
1492 {
1494
1495 if (f_v) {
1496 cout << "file_io::int_matrix_read_csv before S.read_spreadsheet" << endl;
1497 }
1498 S.read_spreadsheet(fname, verbose_level - 1);
1499 if (f_v) {
1500 cout << "file_io::int_matrix_read_csv after S.read_spreadsheet" << endl;
1501 }
1502
1503 m = S.nb_rows - 1;
1504 n = S.nb_cols - 1;
1505 if (f_v) {
1506 cout << "The spreadsheet has " << S.nb_cols << " columns" << endl;
1507 }
1508 M = NEW_int(m * n);
1509 for (i = 0; i < m; i++) {
1510 for (j = 0; j < n; j++) {
1511
1512 a = S.get_int(i + 1, j + 1);
1513 M[i * n + j] = a;
1514 }
1515 }
1516 }
1517 if (f_v) {
1518 cout << "int_matrix_read_csv done" << endl;
1519 }
1520}
1521
1523 int *&M, int &m, int &n, int verbose_level)
1524{
1525 int f_v = (verbose_level >= 1);
1526 int i, j, a;
1527
1528 if (f_v) {
1529 cout << "file_io::int_matrix_read_csv_no_border reading file " << fname << endl;
1530 }
1531 if (file_size(fname) <= 0) {
1532 cout << "file_io::int_matrix_read_csv_no_border file " << fname
1533 << " does not exist or is empty" << endl;
1534 cout << "file_size(fname)=" << file_size(fname) << endl;
1535 exit(1);
1536 }
1537 {
1539
1540 S.read_spreadsheet(fname, 0/*verbose_level - 1*/);
1541
1542 m = S.nb_rows;
1543 n = S.nb_cols;
1544 cout << "The spreadsheet has " << S.nb_cols << " columns" << endl;
1545 M = NEW_int(m * n);
1546 for (i = 0; i < m; i++) {
1547 for (j = 0; j < n; j++) {
1548 a = S.get_int(i, j);
1549 M[i * n + j] = a;
1550 }
1551 }
1552 }
1553 if (f_v) {
1554 cout << "file_io::int_matrix_read_csv_no_border done" << endl;
1555 }
1556}
1557
1558void file_io::lint_matrix_read_csv(std::string &fname,
1559 long int *&M, int &m, int &n, int verbose_level)
1560{
1561 int f_v = (verbose_level >= 1);
1562 int i, j;
1563 long int a;
1564
1565 if (f_v) {
1566 cout << "lint_matrix_read_csv reading file " << fname << endl;
1567 }
1568 if (file_size(fname) <= 0) {
1569 cout << "int_matrix_read_csv file " << fname
1570 << " does not exist or is empty" << endl;
1571 cout << "file_size(fname)=" << file_size(fname) << endl;
1572 exit(1);
1573 }
1574 {
1576
1577 S.read_spreadsheet(fname, 0/*verbose_level - 1*/);
1578
1579 m = S.nb_rows - 1;
1580 n = S.nb_cols - 1;
1581 M = NEW_lint(m * n);
1582 for (i = 0; i < m; i++) {
1583 for (j = 0; j < n; j++) {
1584 a = S.get_int(i + 1, j + 1);
1585 M[i * n + j] = a;
1586 }
1587 }
1588 }
1589 if (f_v) {
1590 cout << "lint_matrix_read_csv done" << endl;
1591 }
1592
1593}
1594
1595void file_io::double_matrix_read_csv(std::string &fname,
1596 double *&M, int &m, int &n, int verbose_level)
1597{
1598 int f_v = (verbose_level >= 1);
1599 int i, j;
1600
1601 if (f_v) {
1602 cout << "double_matrix_read_csv reading file "
1603 << fname << endl;
1604 }
1605 if (file_size(fname) <= 0) {
1606 cout << "double_matrix_read_csv file " << fname
1607 << " does not exist or is empty" << endl;
1608 cout << "file_size(fname)=" << file_size(fname) << endl;
1609 exit(1);
1610 }
1611 {
1613 double d;
1614
1615 S.read_spreadsheet(fname, 0/*verbose_level - 1*/);
1616
1617 m = S.nb_rows - 1;
1618 n = S.nb_cols - 1;
1619 M = new double [m * n];
1620 for (i = 0; i < m; i++) {
1621 for (j = 0; j < n; j++) {
1622 d = S.get_double(i + 1, j + 1);
1623 M[i * n + j] = d;
1624 }
1625 }
1626 }
1627 if (f_v) {
1628 cout << "double_matrix_read_csv done" << endl;
1629 }
1630}
1631
1632
1633void file_io::read_column_and_parse(std::string &fname, std::string &col_label,
1634 data_structures::set_of_sets *&SoS, int verbose_level)
1635{
1636 int f_v = (verbose_level >= 1);
1637
1638 if (f_v) {
1639 cout << "file_io::read_column_and_parse reading file " << fname << endl;
1640 }
1641 if (file_size(fname) <= 0) {
1642 cout << "file_io::read_column_and_parse file " << fname
1643 << " does not exist or is empty" << endl;
1644 cout << "file_size(fname)=" << file_size(fname) << endl;
1645 exit(1);
1646 }
1647 {
1649 int idx;
1650 int nb_sets;
1651 int i;
1652
1653 S.read_spreadsheet(fname, 0/*verbose_level - 1*/);
1654
1655 idx = S.find_column(col_label);
1656 if (idx == -1) {
1657 cout << "file_io::read_column_and_parse cannot find column " << col_label << endl;
1658 exit(1);
1659 }
1660 nb_sets = S.nb_rows - 1;
1661
1662 int underlying_set_size = INT_MAX;
1663
1665
1666 SoS->init_simple(underlying_set_size,
1667 nb_sets, verbose_level);
1668
1669 for (i = 0; i < nb_sets; i++) {
1670
1671 string str;
1672 long int *set;
1673 int sz;
1674
1675 S.get_string(str, i + 1, idx);
1676
1677 Lint_vec_scan(str, set, sz);
1678
1679 SoS->Sets[i] = set;
1680 SoS->Set_size[i] = sz;
1681
1682 }
1683 }
1684 if (f_v) {
1685 cout << "file_io::read_column_and_parse done" << endl;
1686 }
1687
1688}
1689
1690
1691
1692void file_io::int_matrix_write_cas_friendly(std::string &fname, int *M, int m, int n)
1693{
1694 int i, j;
1695
1696 {
1697 ofstream f(fname);
1698
1699 f << "[";
1700 for (i = 0; i < m; i++) {
1701 f << "[";
1702 for (j = 0; j < n; j++) {
1703 f << M[i * n + j];
1704 if (j < n - 1) {
1705 f << ", ";
1706 }
1707 }
1708 f << "]";
1709 if (i < m - 1) {
1710 f << ", " << endl;
1711 }
1712 }
1713 f << "]" << endl;
1714 }
1715}
1716
1717void file_io::int_matrix_write_text(std::string &fname, int *M, int m, int n)
1718{
1719 int i, j;
1720
1721 {
1722 ofstream f(fname);
1723
1724 f << m << " " << n << endl;
1725 for (i = 0; i < m; i++) {
1726 for (j = 0; j < n; j++) {
1727 f << M[i * n + j] << " ";
1728 }
1729 f << endl;
1730 }
1731 }
1732}
1733
1734void file_io::lint_matrix_write_text(std::string &fname, long int *M, int m, int n)
1735{
1736 int i, j;
1737
1738 {
1739 ofstream f(fname);
1740
1741 f << m << " " << n << endl;
1742 for (i = 0; i < m; i++) {
1743 for (j = 0; j < n; j++) {
1744 f << M[i * n + j] << " ";
1745 }
1746 f << endl;
1747 }
1748 }
1749}
1750
1751void file_io::int_matrix_read_text(std::string &fname, int *&M, int &m, int &n)
1752{
1753 int i, j;
1754
1755 if (file_size(fname) <= 0) {
1756 cout << "int_matrix_read_text The file "
1757 << fname << " does not exist" << endl;
1758 exit(1);
1759 }
1760 {
1761 ifstream f(fname);
1762
1763 f >> m >> n;
1764 M = NEW_int(m * n);
1765 for (i = 0; i < m; i++) {
1766 for (j = 0; j < n; j++) {
1767 f >> M[i * n + j];
1768 }
1769 }
1770 }
1771}
1772
1774 int &nb_V, std::vector<std::vector<int>> &Edges, int verbose_level)
1775{
1776 int f_v = (verbose_level >= 1);
1777 int i, a, b;
1778
1779 if (f_v) {
1780 cout << "file_io::read_dimacs_graph_format fname = " << fname << endl;
1781 }
1782 if (file_size(fname) <= 0) {
1783 cout << "file_io::read_dimacs_graph_format The file "
1784 << fname << " does not exist" << endl;
1785 exit(1);
1786 }
1787
1788 char *buf;
1789 int nb_E;
1790
1791 buf = NEW_char(MY_OWN_BUFSIZE);
1792
1793 {
1794 ifstream f(fname);
1795
1796 f.getline(buf, MY_OWN_BUFSIZE, '\n');
1797 sscanf(buf, "p edge %d %d", &nb_V, &nb_E);
1798 if (f_v) {
1799 cout << "file_io::read_dimacs_graph_format a graph on "
1800 << nb_V << " vertices with " << nb_E << " edges" << endl;
1801 }
1802
1803 for (i = 0; i < nb_E; i++) {
1804
1805 f.getline(buf, MY_OWN_BUFSIZE, '\n');
1806
1807 sscanf(buf, "e %d %d", &a, &b);
1808
1809 vector<int> v;
1810
1811 v.push_back(a - 1);
1812 v.push_back(b - 1);
1813
1814 Edges.push_back(v);
1815 }
1816 }
1817
1818 FREE_char(buf);
1819 if (f_v) {
1820 cout << "file_io::read_dimacs_graph_format done" << endl;
1821 }
1822}
1823
1824
1825void file_io::parse_sets(int nb_cases, char **data, int f_casenumbers,
1826 int *&Set_sizes, long int **&Sets,
1827 char **&Ago_ascii, char **&Aut_ascii,
1828 int *&Casenumbers,
1829 int verbose_level)
1830{
1831 int f_v = (verbose_level >= 1);
1832 int f_vv = (verbose_level >= 2);
1833 int h, casenumber;
1834 char *ago_ascii, *aut_ascii;
1835 char *p_buf;
1837
1838 if (f_v) {
1839 cout << "parse_sets f_casenumbers=" << f_casenumbers
1840 << " nb_cases = " << nb_cases << endl;
1841 }
1842
1843 ago_ascii = NEW_char(MY_OWN_BUFSIZE);
1844 aut_ascii = NEW_char(MY_OWN_BUFSIZE);
1845
1846 Set_sizes = NEW_int(nb_cases);
1847 Sets = NEW_plint(nb_cases);
1848 Ago_ascii = NEW_pchar(nb_cases);
1849 Aut_ascii = NEW_pchar(nb_cases);
1850 Casenumbers = NEW_int(nb_cases);
1851
1852 for (h = 0; h < nb_cases; h++) {
1853
1854 //cout << h << " : ";
1855 //cout << " : " << data[h] << endl;
1856
1857 p_buf = data[h];
1858 if (f_casenumbers) {
1859 ST.s_scan_int(&p_buf, &casenumber);
1860 }
1861 else {
1862 casenumber = h;
1863 }
1864
1865 parse_line(p_buf, Set_sizes[h], Sets[h],
1866 ago_ascii, aut_ascii);
1867
1868 Casenumbers[h] = casenumber;
1869
1870 Ago_ascii[h] = NEW_char(strlen(ago_ascii) + 1);
1871 strcpy(Ago_ascii[h], ago_ascii);
1872
1873 Aut_ascii[h] = NEW_char(strlen(aut_ascii) + 1);
1874 strcpy(Aut_ascii[h], aut_ascii);
1875
1876#if 0
1877 cout << h << " : ";
1878 print_set(cout, len, sets[h]);
1879 cout << " : " << data[h] << endl;
1880#endif
1881
1882 if (f_vv && ((h % 1000000) == 0)) {
1883 cout << h << " : " << Casenumbers[h]
1884 << " : " << data[h] << endl;
1885 }
1886 }
1887
1888
1889 FREE_char(ago_ascii);
1890 FREE_char(aut_ascii);
1891}
1892
1893void file_io::parse_line(char *line, int &len,
1894 long int *&set, char *ago_ascii, char *aut_ascii)
1895{
1896 int i;
1897 char *p_buf;
1899
1900 //cout << "parse_line: " << line << endl;
1901 p_buf = line;
1902 ST.s_scan_int(&p_buf, &len);
1903 //cout << "parsing data of length " << len << endl;
1904 set = NEW_lint(len);
1905 for (i = 0; i < len; i++) {
1906 ST.s_scan_lint(&p_buf, &set[i]);
1907 }
1908 ST.s_scan_token(&p_buf, ago_ascii);
1909 if (strcmp(ago_ascii, "1") == 0) {
1910 aut_ascii[0] = 0;
1911 }
1912 else {
1913 ST.s_scan_token(&p_buf, aut_ascii);
1914 }
1915}
1916
1917
1919 std::string &fname, int verbose_level)
1920{
1921 int f_v = (verbose_level >= 1);
1922 char *buf, *p_buf;
1923 int nb_sol, len;
1924 int ret;
1926
1927 if (f_v) {
1928 cout << "count_number_of_orbits_in_file " << fname << endl;
1929 cout << "count_number_of_orbits_in_file "
1930 "trying to read file "
1931 << fname << " of size " << file_size(fname) << endl;
1932 }
1933
1934 if (file_size(fname) < 0) {
1935 cout << "count_number_of_orbits_in_file "
1936 "file size is -1" << endl;
1937 return -1;
1938 }
1939
1940 buf = NEW_char(MY_OWN_BUFSIZE);
1941
1942
1943
1944 {
1945 ifstream fp(fname);
1946
1947
1948 nb_sol = 0;
1949 while (TRUE) {
1950 if (fp.eof()) {
1951 break;
1952 }
1953
1954 //cout << "count_number_of_orbits_in_file "
1955 //"reading line, nb_sol = " << nb_sol << endl;
1956 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
1957 if (strlen(buf) == 0) {
1958 cout << "count_number_of_orbits_in_file "
1959 "reading an empty line" << endl;
1960 break;
1961 }
1962
1963 // check for comment line:
1964 if (buf[0] == '#') {
1965 continue;
1966 }
1967
1968 p_buf = buf;
1969 ST.s_scan_int(&p_buf, &len);
1970 if (len == -1) {
1971 if (f_v) {
1972 cout << "count_number_of_orbits_in_file "
1973 "found a complete file with " << nb_sol
1974 << " solutions" << endl;
1975 }
1976 break;
1977 }
1978 else {
1979 if (FALSE) {
1980 cout << "count_number_of_orbits_in_file "
1981 "found a set of size " << len << endl;
1982 }
1983 }
1984 nb_sol++;
1985 }
1986 }
1987 ret = nb_sol;
1988//finish:
1989
1990 FREE_char(buf);
1991
1992 return ret;
1993}
1994
1995int file_io::count_number_of_lines_in_file(std::string &fname, int verbose_level)
1996{
1997 int f_v = (verbose_level >= 1);
1998 char *buf;
1999 int nb_lines;
2000
2001 if (f_v) {
2002 cout << "count_number_of_lines_in_file " << fname << endl;
2003 cout << "trying to read file " << fname << " of size "
2004 << file_size(fname) << endl;
2005 }
2006
2007 if (file_size(fname) < 0) {
2008 cout << "count_number_of_lines_in_file file size is -1" << endl;
2009 return 0;
2010 }
2011
2012 buf = NEW_char(MY_OWN_BUFSIZE);
2013
2014
2015
2016 {
2017 ifstream fp(fname);
2018
2019
2020 nb_lines = 0;
2021 while (TRUE) {
2022 if (fp.eof()) {
2023 break;
2024 }
2025
2026 //cout << "count_number_of_lines_in_file "
2027 // "reading line, nb_sol = " << nb_sol << endl;
2028 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
2029 nb_lines++;
2030 }
2031 }
2032 FREE_char(buf);
2033
2034 return nb_lines;
2035}
2036
2037int file_io::try_to_read_file(std::string &fname,
2038 int &nb_cases, char **&data, int verbose_level)
2039{
2040 int f_v = (verbose_level >= 1);
2041 //int n1;
2042 char *buf, *p_buf;
2043 int nb_sol, len, a;
2045
2046 if (f_v) {
2047 cout << "try_to_read_file trying to read file " << fname
2048 << " of size " << file_size(fname) << endl;
2049 }
2050 buf = NEW_char(MY_OWN_BUFSIZE);
2051
2052
2053 if (file_size(fname.c_str()) <= 0) {
2054 goto return_false;
2055 }
2056
2057 {
2058 ifstream fp(fname);
2059
2060#if 0
2061 if (fp.eof()) {
2062 goto return_false;
2063 }
2064 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
2065 if (strlen(buf) == 0) {
2066 goto return_false;
2067 }
2068 sscanf(buf + 1, "%d", &n1);
2069 cout << "n1=" << n1;
2070 if (n1 != n) {
2071 cout << "try_to_read_file() n1 != n" << endl;
2072 exit(1);
2073 }
2074#endif
2075
2076 nb_sol = 0;
2077 while (TRUE) {
2078 if (fp.eof()) {
2079 break;
2080 }
2081 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
2082 if (strlen(buf) == 0) {
2083 goto return_false;
2084 }
2085
2086 // check for comment line:
2087 if (buf[0] == '#') {
2088 continue;
2089 }
2090
2091 p_buf = buf;
2092 ST.s_scan_int(&p_buf, &len);
2093 if (len == -1) {
2094 if (f_v) {
2095 cout << "found a complete file with "
2096 << nb_sol << " solutions" << endl;
2097 }
2098 break;
2099 }
2100 nb_sol++;
2101 }
2102 }
2103 nb_cases = nb_sol;
2104 data = NEW_pchar(nb_cases);
2105 {
2106 ifstream fp(fname);
2107
2108#if 0
2109 if (fp.eof()) {
2110 goto return_false;
2111 }
2112 fp.getline(buf, MY_BUFSIZE, '\n');
2113 if (strlen(buf) == 0) {
2114 goto return_false;
2115 }
2116 sscanf(buf + 1, "%d", &n1);
2117 if (n1 != n) {
2118 cout << "try_to_read_file() n1 != n" << endl;
2119 exit(1);
2120 }
2121#endif
2122
2123 nb_sol = 0;
2124 while (TRUE) {
2125 if (fp.eof()) {
2126 break;
2127 }
2128 fp.getline(buf, MY_OWN_BUFSIZE, '\n');
2129 len = strlen(buf);
2130 if (len == 0) {
2131 goto return_false;
2132 }
2133
2134 // check for comment line:
2135 if (buf[0] == '#') {
2136 continue;
2137 }
2138
2139 p_buf = buf;
2140 ST.s_scan_int(&p_buf, &a);
2141 if (a == -1) {
2142 if (f_v) {
2143 cout << "read " << nb_sol
2144 << " solutions" << endl;
2145 }
2146 break;
2147 }
2148
2149
2150 data[nb_sol] = NEW_char(len + 1);
2151 strcpy(data[nb_sol], buf);
2152
2153 //cout << nb_sol << " : " << data[nb_sol] << endl;
2154
2155 nb_sol++;
2156 }
2157 }
2158
2159 FREE_char(buf);
2160 return TRUE;
2161
2162return_false:
2163 FREE_char(buf);
2164 return FALSE;
2165}
2166
2168 std::string &fname, int &nb_cases,
2169 char **&data, long int **&sets, int *&set_sizes,
2170 int verbose_level)
2171{
2172 int f_v = (verbose_level >= 1);
2173 int f_vv = (verbose_level >= 2);
2174
2175 if (f_v) {
2176 cout << "file_io::read_and_parse_data_file: reading file "
2177 << fname << endl;
2178 }
2179 if (try_to_read_file(fname, nb_cases, data, verbose_level)) {
2180 if (f_vv) {
2181 cout << "file_io::read_and_parse_data_file file read containing " << nb_cases
2182 << " cases" << endl;
2183 }
2184 }
2185 else {
2186 cout << "file_io::read_and_parse_data_file couldn't read file "
2187 << fname << endl;
2188 exit(1);
2189 }
2190
2191#if 0
2192 for (i = 0; i < nb_cases; i++) {
2193 cout << i << " : " << data[i] << endl;
2194 }
2195#endif
2196
2197
2198 if (f_v) {
2199 cout << "file_io::read_and_parse_data_file: parsing sets" << endl;
2200 }
2201 //parse_sets(nb_cases, data, set_sizes, sets);
2202
2203 char **Ago_ascii;
2204 char **Aut_ascii;
2205 int *Casenumbers;
2206 int i;
2207
2208 parse_sets(nb_cases, data, FALSE /*f_casenumbers */,
2209 set_sizes, sets, Ago_ascii, Aut_ascii,
2210 Casenumbers,
2211 0/*verbose_level - 2*/);
2212
2213 FREE_int(Casenumbers);
2214
2215 for (i = 0; i < nb_cases; i++) {
2216 strcpy(data[i], Aut_ascii[i]);
2217 }
2218
2219 for (i = 0; i < nb_cases; i++) {
2220 FREE_char(Ago_ascii[i]);
2221 FREE_char(Aut_ascii[i]);
2222 }
2223 FREE_pchar(Ago_ascii);
2224 FREE_pchar(Aut_ascii);
2225 if (f_v) {
2226 cout << "file_io::read_and_parse_data_file done" << endl;
2227 }
2228}
2229
2231 char **data, long int **&sets)
2232{
2233 char **Ago_ascii;
2234 char **Aut_ascii;
2235 int *Casenumbers;
2236 int *set_sizes;
2237 int i;
2238
2239 parse_sets(nb_cases, data, FALSE /*f_casenumbers */,
2240 set_sizes, sets, Ago_ascii, Aut_ascii,
2241 Casenumbers,
2242 0/*verbose_level - 2*/);
2243 for (i = 0; i < nb_cases; i++) {
2244 if (set_sizes[i] != len) {
2245 cout << "file_io::parse_sets_and_check_sizes_easy "
2246 "set_sizes[i] != len" << endl;
2247 exit(1);
2248 }
2249 }
2250
2251
2252 FREE_int(set_sizes);
2253 FREE_int(Casenumbers);
2254
2255#if 1
2256 for (i = 0; i < nb_cases; i++) {
2257 strcpy(data[i], Aut_ascii[i]);
2258 }
2259#endif
2260
2261 for (i = 0; i < nb_cases; i++) {
2262 FREE_char(Ago_ascii[i]);
2263 FREE_char(Aut_ascii[i]);
2264 }
2265 FREE_pchar(Ago_ascii);
2266 FREE_pchar(Aut_ascii);
2267
2268}
2269
2271 int *Set_sizes, long int **Sets,
2272 char **Ago_ascii, char **Aut_ascii,
2273 int *Casenumbers)
2274// Frees only those pointers that are not NULL
2275{
2276 int i;
2277
2278 if (Ago_ascii) {
2279 for (i = 0; i < nb_cases; i++) {
2280 FREE_char(Ago_ascii[i]);
2281 }
2282 FREE_pchar(Ago_ascii);
2283 }
2284 if (Aut_ascii) {
2285 for (i = 0; i < nb_cases; i++) {
2286 FREE_char(Aut_ascii[i]);
2287 }
2288 FREE_pchar(Aut_ascii);
2289 }
2290 if (Sets) {
2291 for (i = 0; i < nb_cases; i++) {
2292 FREE_lint(Sets[i]);
2293 }
2294 FREE_plint(Sets);
2295 }
2296 if (Set_sizes) {
2297 FREE_int(Set_sizes);
2298 }
2299 if (Casenumbers) {
2300 FREE_int(Casenumbers);
2301 }
2302}
2303
2305 std::string &fname,
2306 int f_casenumbers,
2307 int &nb_cases,
2308 int *&Set_sizes, long int **&Sets,
2309 char **&Ago_ascii,
2310 char **&Aut_ascii,
2311 int *&Casenumbers,
2312 int verbose_level)
2313{
2314 int f_v = (verbose_level >= 1);
2315 int f_vv = (verbose_level >= 2);
2316 char **data;
2317 int i;
2318
2319 if (f_v) {
2320 cout << "file_io::read_and_parse_data_file_fancy "
2321 "reading file "
2322 << fname << endl;
2323 }
2324 if (f_vv) {
2325 cout << "file_io::read_and_parse_data_file_fancy "
2326 "before try_to_read_file" << endl;
2327 }
2328 if (try_to_read_file(fname, nb_cases, data, verbose_level - 1)) {
2329 if (f_vv) {
2330 cout << "file_io::read_and_parse_data_file_fancy "
2331 "file read containing "
2332 << nb_cases << " cases" << endl;
2333 }
2334 }
2335 else {
2336 cout << "file_io::read_and_parse_data_file_fancy "
2337 "couldn't read file fname="
2338 << fname << endl;
2339 exit(1);
2340 }
2341
2342#if 0
2343 if (f_vv) {
2344 cout << "after try_to_read_file" << endl;
2345 for (i = 0; i < nb_cases; i++) {
2346 cout << i << " : " << data[i] << endl;
2347 }
2348 }
2349#endif
2350
2351
2352 if (f_vv) {
2353 cout << "file_io::read_and_parse_data_file_fancy "
2354 "parsing sets" << endl;
2355 }
2356 parse_sets(nb_cases, data, f_casenumbers,
2357 Set_sizes, Sets, Ago_ascii, Aut_ascii,
2358 Casenumbers,
2359 verbose_level - 2);
2360
2361 if (f_vv) {
2362 cout << "file_io::read_and_parse_data_file_fancy "
2363 "freeing temporary data" << endl;
2364 }
2365 for (i = 0; i < nb_cases; i++) {
2366 FREE_char(data[i]);
2367 }
2368 FREE_pchar(data);
2369 if (f_vv) {
2370 cout << "file_io::read_and_parse_data_file_fancy done" << endl;
2371 }
2372}
2373
2374void file_io::read_set_from_file(std::string &fname,
2375 long int *&the_set, int &set_size, int verbose_level)
2376// if the file is empty, set_size cannot be determined and is set to 0
2377{
2378 int f_v = (verbose_level >= 1);
2379 int f_vv = (verbose_level >= 2);
2380 int i, a;
2381
2382 if (f_v) {
2383 cout << "file_io::read_set_from_file opening file " << fname
2384 << " of size " << file_size(fname)
2385 << " for reading" << endl;
2386 }
2387 ifstream f(fname);
2388
2389 f >> set_size;
2390
2391 if (set_size == -1) {
2392 if (f_v) {
2393 cout << "file_io::read_set_from_file the file is empty, "
2394 "set_size cannot be determined" << endl;
2395 }
2396 set_size = 0;
2397 }
2398 else {
2399 if (f_v) {
2400 cout << "file_io::read_set_from_file allocating set of size "
2401 << set_size << endl;
2402 }
2403 the_set = NEW_lint(set_size);
2404
2405 if (f_v) {
2406 cout << "file_io::read_set_from_file reading set of size "
2407 << set_size << endl;
2408 }
2409 for (i = 0; i < set_size; i++) {
2410 f >> a;
2411 //if (f_v) {
2412 //cout << "read_set_from_file: the " << i
2413 //<< "-th number is " << a << endl;
2414 //}
2415 if (a == -1)
2416 break;
2417 the_set[i] = a;
2418 }
2419 if (f_v) {
2420 cout << "file_io::read_set_from_file read a set of size " << set_size
2421 << " from file " << fname << endl;
2422 }
2423 if (f_vv) {
2424 cout << "file_io::read_set_from_file the set is:" << endl;
2425 Lint_vec_print(cout, the_set, set_size);
2426 cout << endl;
2427 }
2428 }
2429 if (f_v) {
2430 cout << "file_io::read_set_from_file done" << endl;
2431 }
2432}
2433
2434void file_io::write_set_to_file(std::string &fname,
2435 long int *the_set, int set_size, int verbose_level)
2436{
2437 int f_v = (verbose_level >= 1);
2438 int i;
2439
2440 if (f_v) {
2441 cout << "write_set_to_file opening file "
2442 << fname << " for writing" << endl;
2443 }
2444 {
2445 ofstream f(fname);
2446
2447 f << set_size << " ";
2448
2449 for (i = 0; i < set_size; i++) {
2450#if 0
2451 if (i && ((i % 10) == 0)) {
2452 f << endl;
2453 }
2454#endif
2455 f << the_set[i] << " ";
2456 }
2457 f << endl << -1 << endl;
2458 }
2459 if (f_v) {
2460 cout << "Written file " << fname << " of size "
2461 << file_size(fname) << endl;
2462 }
2463}
2464
2465void file_io::read_set_from_file_lint(std::string &fname,
2466 long int *&the_set, int &set_size, int verbose_level)
2467{
2468 int f_v = (verbose_level >= 1);
2469 int f_vv = (verbose_level >= 2);
2470 int i;
2471 long int a;
2472
2473 if (f_v) {
2474 cout << "read_set_from_file_lint opening file " << fname
2475 << " of size " << file_size(fname)
2476 << " for reading" << endl;
2477 }
2478 ifstream f(fname);
2479
2480 f >> set_size;
2481 if (f_v) {
2482 cout << "read_set_from_file_lint allocating set of size "
2483 << set_size << endl;
2484 }
2485 the_set = NEW_lint(set_size);
2486
2487 if (f_v) {
2488 cout << "read_set_from_file_lint reading set of size "
2489 << set_size << endl;
2490 }
2491 for (i = 0; i < set_size; i++) {
2492 f >> a;
2493 //if (f_v) {
2494 //cout << "read_set_from_file: the " << i
2495 //<< "-th number is " << a << endl;
2496 //}
2497 if (a == -1) {
2498 break;
2499 }
2500 the_set[i] = a;
2501 }
2502 if (f_v) {
2503 cout << "read a set of size " << set_size
2504 << " from file " << fname << endl;
2505 }
2506 if (f_vv) {
2507 cout << "the set is:" << endl;
2508 Lint_vec_print(cout, the_set, set_size);
2509 cout << endl;
2510 }
2511}
2512
2513void file_io::write_set_to_file_lint(std::string &fname,
2514 long int *the_set, int set_size, int verbose_level)
2515{
2516 int f_v = (verbose_level >= 1);
2517 int i;
2518
2519 if (f_v) {
2520 cout << "write_set_to_file_lint opening file "
2521 << fname << " for writing" << endl;
2522 }
2523 {
2524 ofstream f(fname);
2525
2526 f << set_size << endl;
2527
2528 for (i = 0; i < set_size; i++) {
2529#if 0
2530 if (i && ((i % 10) == 0)) {
2531 f << endl;
2532 }
2533#endif
2534 f << the_set[i] << " ";
2535 }
2536 f << endl << -1 << endl;
2537 }
2538 if (f_v) {
2539 cout << "Written file " << fname << " of size "
2540 << file_size(fname) << endl;
2541 }
2542}
2543
2544void file_io::read_set_from_file_int4(std::string &fname,
2545 long int *&the_set, int &set_size, int verbose_level)
2546{
2547 int f_v = (verbose_level >= 1);
2548 int f_vv = (verbose_level >= 2);
2549 int i, b;
2550 int_4 a;
2551
2552 if (f_v) {
2553 cout << "read_set_from_file_int4 opening file " << fname
2554 << " of size " << file_size(fname)
2555 << " for reading" << endl;
2556 }
2557 ifstream f(fname, ios::binary);
2558
2559 f.read((char *) &a, sizeof(int_4));
2560 set_size = a;
2561 the_set = NEW_lint(set_size);
2562
2563 for (i = 0; i < set_size; i++) {
2564 f.read((char *) &a, sizeof(int_4));
2565 b = a;
2566 //if (f_v) {
2567 //cout << "read_set_from_file: the " << i
2568 //<< "-th number is " << a << endl;
2569 //}
2570 if (b == -1) {
2571 break;
2572 }
2573 the_set[i] = b;
2574 }
2575 if (f_v) {
2576 cout << "read a set of size " << set_size
2577 << " from file " << fname << endl;
2578 }
2579 if (f_vv) {
2580 cout << "the set is:" << endl;
2581 Lint_vec_print(cout, the_set, set_size);
2582 cout << endl;
2583 }
2584}
2585
2586void file_io::read_set_from_file_int8(std::string &fname,
2587 long int *&the_set, int &set_size, int verbose_level)
2588{
2589 int f_v = (verbose_level >= 1);
2590 int f_vv = (verbose_level >= 2);
2591 int i;
2592 long int b;
2593 int_8 a;
2594
2595 if (f_v) {
2596 cout << "read_set_from_file_int8 opening file " << fname
2597 << " of size " << file_size(fname)
2598 << " for reading" << endl;
2599 }
2600 ifstream f(fname, ios::binary);
2601
2602 f.read((char *) &a, sizeof(int_8));
2603 set_size = a;
2604 the_set = NEW_lint(set_size);
2605
2606 for (i = 0; i < set_size; i++) {
2607 f.read((char *) &a, sizeof(int_8));
2608 b = a;
2609 //if (f_v) {
2610 //cout << "read_set_from_file: the " << i
2611 //<< "-th number is " << a << endl;
2612 //}
2613 if (b == -1) {
2614 break;
2615 }
2616 the_set[i] = b;
2617 }
2618 if (f_v) {
2619 cout << "read a set of size " << set_size
2620 << " from file " << fname << endl;
2621 }
2622 if (f_vv) {
2623 cout << "the set is:" << endl;
2624 Lint_vec_print(cout, the_set, set_size);
2625 cout << endl;
2626 }
2627}
2628
2630 long int *the_set, int set_size, int verbose_level)
2631{
2632 int f_v = (verbose_level >= 1);
2633 int i;
2634 int_4 a;
2635 int b;
2636
2637 if (f_v) {
2638 cout << "write_set_to_file_as_int4 opening file "
2639 << fname << " for writing" << endl;
2640 }
2641 {
2642 ofstream f(fname, ios::binary);
2643
2644
2645 a = (int_4) set_size;
2646 f.write((char *) &a, sizeof(int_4));
2647 b = a;
2648 if (b != set_size) {
2649 cout << "write_set_to_file_as_int4 "
2650 "data loss regarding set_size" << endl;
2651 cout << "set_size=" << set_size << endl;
2652 cout << "a=" << a << endl;
2653 cout << "b=" << b << endl;
2654 exit(1);
2655 }
2656 for (i = 0; i < set_size; i++) {
2657 a = (int_4) the_set[i];
2658 f.write((char *) &a, sizeof(int_4));
2659 b = a;
2660 if (b != the_set[i]) {
2661 cout << "write_set_to_file_as_int4 data loss" << endl;
2662 cout << "i=" << i << endl;
2663 cout << "the_set[i]=" << the_set[i] << endl;
2664 cout << "a=" << a << endl;
2665 cout << "b=" << b << endl;
2666 exit(1);
2667 }
2668 }
2669 }
2670 if (f_v) {
2671 cout << "Written file " << fname
2672 << " of size " << file_size(fname) << endl;
2673 }
2674}
2675
2677 long int *the_set, int set_size, int verbose_level)
2678{
2679 int f_v = (verbose_level >= 1);
2680 int i;
2681 int_8 a, b;
2682
2683 if (f_v) {
2684 cout << "write_set_to_file_as_int8 opening file "
2685 << fname << " for writing" << endl;
2686 }
2687 {
2688 ofstream f(fname, ios::binary);
2689
2690
2691 a = (int_8) set_size;
2692 f.write((char *) &a, sizeof(int_8));
2693 b = a;
2694 if (b != set_size) {
2695 cout << "write_set_to_file_as_int8 "
2696 "data loss regarding set_size" << endl;
2697 cout << "set_size=" << set_size << endl;
2698 cout << "a=" << a << endl;
2699 cout << "b=" << b << endl;
2700 exit(1);
2701 }
2702 for (i = 0; i < set_size; i++) {
2703 a = (int_8) the_set[i];
2704 f.write((char *) &a, sizeof(int_8));
2705 b = a;
2706 if (b != the_set[i]) {
2707 cout << "write_set_to_file_as_int8 data loss" << endl;
2708 cout << "i=" << i << endl;
2709 cout << "the_set[i]=" << the_set[i] << endl;
2710 cout << "a=" << a << endl;
2711 cout << "b=" << b << endl;
2712 exit(1);
2713 }
2714 }
2715 }
2716 if (f_v) {
2717 cout << "Written file " << fname
2718 << " of size " << file_size(fname) << endl;
2719 }
2720}
2721
2722void file_io::read_k_th_set_from_file(std::string &fname, int k,
2723 int *&the_set, int &set_size, int verbose_level)
2724{
2725 int f_v = (verbose_level >= 1);
2726 int f_vv = (verbose_level >= 2);
2727 int i, a, h;
2728
2729 if (f_v) {
2730 cout << "read_k_th_set_from_file opening file "
2731 << fname << " of size " << file_size(fname)
2732 << " for reading" << endl;
2733 }
2734 ifstream f(fname);
2735
2736 f >> set_size;
2737 the_set = NEW_int(set_size);
2738
2739 for (h = 0; h <= k; h++) {
2740 for (i = 0; i < set_size; i++) {
2741 f >> a;
2742 if (f_v) {
2743 cout << "read_k_th_set_from_file: h="
2744 << h << " the " << i
2745 << "-th number is " << a << endl;
2746 }
2747 //if (a == -1)
2748 //break;
2749 the_set[i] = a;
2750 }
2751 }
2752 if (f_v) {
2753 cout << "read a set of size " << set_size
2754 << " from file " << fname << endl;
2755 }
2756 if (f_vv) {
2757 cout << "the set is:" << endl;
2758 Int_vec_print(cout, the_set, set_size);
2759 cout << endl;
2760 }
2761}
2762
2763
2765 int *Inc, int m, int n, int verbose_level)
2766{
2767 int f_v = (verbose_level >= 1);
2768 int i, nb_inc;
2769
2770 if (f_v) {
2771 cout << "write_incidence_matrix_to_file opening file "
2772 << fname << " for writing" << endl;
2773 }
2774 {
2775 ofstream f(fname);
2776
2777 nb_inc = 0;
2778 for (i = 0; i < m * n; i++) {
2779 if (Inc[i]) {
2780 nb_inc++;
2781 }
2782 }
2783 f << m << " " << n << " " << nb_inc << endl;
2784
2785 for (i = 0; i < m * n; i++) {
2786 if (Inc[i]) {
2787 f << i << " ";
2788 }
2789 }
2790 f << " 0" << endl; // no group order
2791
2792 f << -1 << endl;
2793 }
2794 if (f_v) {
2795 cout << "Written file " << fname << " of size "
2796 << file_size(fname) << endl;
2797 }
2798}
2799
2800#define READ_INCIDENCE_BUFSIZE 1000000
2801
2803 std::string &inc_file_name, int inc_file_idx, int verbose_level)
2804{
2805 int f_v = (verbose_level >= 1);
2806 int f_vv = (verbose_level >= 2);
2807 int nb_inc;
2808 int a, h, cnt;
2809 char buf[READ_INCIDENCE_BUFSIZE];
2810 char *p_buf;
2811 int *X = NULL;
2813
2814
2815 if (f_v) {
2816 cout << "read_incidence_matrix_from_inc_file "
2817 << inc_file_name << " no " << inc_file_idx << endl;
2818 }
2819 {
2820 ifstream f(inc_file_name);
2821
2822 if (f.eof()) {
2823 exit(1);
2824 }
2825 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
2826 if (strlen(buf) == 0) {
2827 exit(1);
2828 }
2829 sscanf(buf, "%d %d %d", &m, &n, &nb_inc);
2830 if (f_vv) {
2831 cout << "m=" << m;
2832 cout << " n=" << n;
2833 cout << " nb_inc=" << nb_inc << endl;
2834 }
2835 X = NEW_int(nb_inc);
2836 cnt = 0;
2837 while (TRUE) {
2838 if (f.eof()) {
2839 break;
2840 }
2841 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
2842 if (strlen(buf) == 0) {
2843 continue;
2844 }
2845
2846 // check for comment line:
2847 if (buf[0] == '#') {
2848 continue;
2849 }
2850
2851 p_buf = buf;
2852
2853 ST.s_scan_int(&p_buf, &a);
2854 if (f_vv) {
2855 //cout << cnt << " : " << a << " ";
2856 }
2857 if (a == -1) {
2858 cout << "\nread_incidence_matrix_from_inc_file: "
2859 "found a complete file with "
2860 << cnt << " solutions" << endl;
2861 break;
2862 }
2863 X[0] = a;
2864
2865 //cout << "reading " << nb_inc << " incidences" << endl;
2866 for (h = 1; h < nb_inc; h++) {
2867 ST.s_scan_int(&p_buf, &a);
2868 if (a < 0 || a >= m * n) {
2869 cout << "attention, read " << a
2870 << " h=" << h << endl;
2871 exit(1);
2872 }
2873 X[h] = a;
2874 //M[a] = 1;
2875 }
2876 //f >> a; // skip aut group order
2877 if (cnt == inc_file_idx) {
2878 M = NEW_int(m * n);
2879 for (h = 0; h < m * n; h++) {
2880 M[h] = 0;
2881 }
2882 for (h = 0; h < nb_inc; h++) {
2883 M[X[h]] = 1;
2884 }
2885 if (f_vv) {
2886 cout << "read_incidence_matrix_from_inc_file: "
2887 "found the following incidence matrix:" << endl;
2889 M, m, n, n, 1);
2890 }
2891 break;
2892 }
2893 cnt++;
2894 }
2895 }
2896 FREE_int(X);
2897}
2898
2899
2900void file_io::read_incidence_file(std::vector<std::vector<int> > &Geos,
2901 int &m, int &n, int &nb_flags,
2902 std::string &inc_file_name, int verbose_level)
2903{
2904 int f_v = (verbose_level >= 1);
2905 int f_vv = (verbose_level >= 2);
2906 int a, h, cnt;
2907 char buf[READ_INCIDENCE_BUFSIZE];
2908 char *p_buf;
2909 int *X = NULL;
2911
2912
2913 if (f_v) {
2914 cout << "file_io::read_incidence_file " << inc_file_name << endl;
2915 }
2916 {
2917 ifstream f(inc_file_name);
2918
2919 if (f.eof()) {
2920 exit(1);
2921 }
2922 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
2923 if (strlen(buf) == 0) {
2924 exit(1);
2925 }
2926 sscanf(buf, "%d %d %d", &m, &n, &nb_flags);
2927 if (f_vv) {
2928 cout << "m=" << m;
2929 cout << " n=" << n;
2930 cout << " nb_flags=" << nb_flags << endl;
2931 }
2932 X = NEW_int(nb_flags);
2933 cnt = 0;
2934 while (TRUE) {
2935 if (f.eof()) {
2936 break;
2937 }
2938 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
2939 if (strlen(buf) == 0) {
2940 continue;
2941 }
2942
2943 // check for comment line:
2944 if (buf[0] == '#') {
2945 continue;
2946 }
2947
2948 p_buf = buf;
2949
2950 ST.s_scan_int(&p_buf, &a);
2951 if (f_vv) {
2952 //cout << cnt << " : " << a << " ";
2953 }
2954 if (a == -1) {
2955 cout << "file_io::read_incidence_file: "
2956 "found a complete file with "
2957 << cnt << " solutions" << endl;
2958 break;
2959 }
2960 X[0] = a;
2961
2962 //cout << "reading " << nb_inc << " incidences" << endl;
2963 for (h = 1; h < nb_flags; h++) {
2964 ST.s_scan_int(&p_buf, &a);
2965 if (a < 0 || a >= m * n) {
2966 cout << "attention, read " << a
2967 << " h=" << h << endl;
2968 exit(1);
2969 }
2970 X[h] = a;
2971 //M[a] = 1;
2972 }
2973 //f >> a; // skip aut group order
2974
2975 vector<int> v;
2976
2977 for (h = 0; h < nb_flags; h++) {
2978 v.push_back(X[h]);
2979 }
2980 Geos.push_back(v);
2981 cnt++;
2982 }
2983 }
2984 FREE_int(X);
2985}
2986
2987
2988void file_io::read_incidence_by_row_ranks_file(std::vector<std::vector<int> > &Geos,
2989 int &m, int &n, int &r,
2990 std::string &inc_file_name, int verbose_level)
2991{
2992 int f_v = (verbose_level >= 1);
2993 int f_vv = (verbose_level >= 2);
2994 int a, h, cnt;
2995 char buf[READ_INCIDENCE_BUFSIZE];
2996 char *p_buf;
2997 int *X = NULL;
2999
3000
3001 if (f_v) {
3002 cout << "file_io::read_incidence_by_row_ranks_file " << inc_file_name << endl;
3003 }
3004 {
3005 ifstream f(inc_file_name);
3006
3007 if (f.eof()) {
3008 exit(1);
3009 }
3010 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
3011 if (strlen(buf) == 0) {
3012 exit(1);
3013 }
3014 sscanf(buf, "%d %d %d", &m, &n, &r);
3015 if (f_vv) {
3016 cout << "m=" << m;
3017 cout << " n=" << n;
3018 cout << " r=" << r << endl;
3019 }
3020 X = NEW_int(m);
3021 int *Row;
3023 int sz;
3024
3025 Row = NEW_int(m);
3026 cnt = 0;
3027 while (TRUE) {
3028 if (f.eof()) {
3029 break;
3030 }
3031 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
3032 if (strlen(buf) == 0) {
3033 continue;
3034 }
3035
3036 // check for comment line:
3037 if (buf[0] == '#') {
3038 continue;
3039 }
3040
3041 p_buf = buf;
3042
3043 ST.s_scan_int(&p_buf, &a);
3044 if (f_vv) {
3045 //cout << cnt << " : " << a << " ";
3046 }
3047 if (a == -1) {
3048 cout << "file_io::read_incidence_file: "
3049 "found a complete file with "
3050 << cnt << " solutions" << endl;
3051 break;
3052 }
3053 sz = a;
3054
3055 //cout << "reading " << nb_inc << " incidences" << endl;
3056 for (h = 0; h < sz; h++) {
3057 ST.s_scan_int(&p_buf, &a);
3058 X[h] = a;
3059 //M[a] = 1;
3060 }
3061 //f >> a; // skip aut group order
3062
3063 vector<int> v;
3064 int u;
3065
3066 for (h = 0; h < sz; h++) {
3067 Combi.unrank_k_subset(X[h], Row, n, r);
3068 for (u = 0; u < r; u++) {
3069 v.push_back(h * n + Row[u]);
3070 }
3071 }
3072 Geos.push_back(v);
3073 cnt++;
3074 }
3075 FREE_int(Row);
3076 FREE_int(X);
3077 }
3078}
3079
3080
3081
3083 char *inc_file_name, int verbose_level)
3084{
3085 int f_v = (verbose_level >= 1);
3086 int f_vv = (verbose_level >= 2);
3087 int nb_inc;
3088 int a, h, cnt;
3089 char buf[READ_INCIDENCE_BUFSIZE];
3090 char *p_buf;
3091 int *X = NULL;
3092 int m, n;
3094
3095
3096 if (f_v) {
3097 cout << "inc_file_get_number_of_geometries "
3098 << inc_file_name << endl;
3099 }
3100 {
3101 ifstream f(inc_file_name);
3102
3103 if (f.eof()) {
3104 exit(1);
3105 }
3106 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
3107 if (strlen(buf) == 0) {
3108 exit(1);
3109 }
3110 sscanf(buf, "%d %d %d", &m, &n, &nb_inc);
3111 if (f_vv) {
3112 cout << "m=" << m;
3113 cout << " n=" << n;
3114 cout << " nb_inc=" << nb_inc << endl;
3115 }
3116 X = NEW_int(nb_inc);
3117 cnt = 0;
3118 while (TRUE) {
3119 if (f.eof()) {
3120 break;
3121 }
3122 f.getline(buf, READ_INCIDENCE_BUFSIZE, '\n');
3123 if (strlen(buf) == 0) {
3124 continue;
3125 }
3126
3127 // check for comment line:
3128 if (buf[0] == '#') {
3129 continue;
3130 }
3131
3132 p_buf = buf;
3133
3134 ST.s_scan_int(&p_buf, &a);
3135 if (f_vv) {
3136 //cout << cnt << " : " << a << " ";
3137 }
3138 if (a == -1) {
3139 cout << "\nread_incidence_matrix_from_inc_file: "
3140 "found a complete file with " << cnt
3141 << " solutions" << endl;
3142 break;
3143 }
3144 X[0] = a;
3145
3146 //cout << "reading " << nb_inc << " incidences" << endl;
3147 for (h = 1; h < nb_inc; h++) {
3148 ST.s_scan_int(&p_buf, &a);
3149 if (a < 0 || a >= m * n) {
3150 cout << "attention, read " << a
3151 << " h=" << h << endl;
3152 exit(1);
3153 }
3154 X[h] = a;
3155 //M[a] = 1;
3156 }
3157 //f >> a; // skip aut group order
3158 cnt++;
3159 }
3160 }
3161 FREE_int(X);
3162 return cnt;
3163}
3164
3165long int file_io::file_size(std::string &fname)
3166{
3167 return file_size(fname.c_str());
3168}
3169
3170long int file_io::file_size(const char *name)
3171{
3172 //cout << "file_size fname=" << name << endl;
3173#ifdef SYSTEMUNIX
3174 int handle;
3175 long int size;
3176
3177 //cout << "Unix mode" << endl;
3178 handle = open(name, O_RDWR/*mode*/);
3179 size = lseek(handle, 0L, SEEK_END);
3180 close(handle);
3181 return size;
3182#endif
3183#ifdef SYSTEMMAC
3184 int handle;
3185 long int size;
3186
3187 //cout << "Macintosh mode" << endl;
3188 handle = open(name, O_RDONLY);
3189 /* THINK C Unix Lib */
3190 size = lseek(handle, 0L, SEEK_END);
3191 /* THINK C Unix Lib */
3192 close(handle);
3193 return size;
3194#endif
3195#ifdef SYSTEMWINDOWS
3196
3197 cout << "file_io::file_size SYSTEMWINDOWS but not SYSTEMUNIX" << endl;
3198 exit(1);
3199
3200 //int handle = _open(name, _O_RDONLY);
3201 //int size = _lseek(handle, 0, SEEK_END);
3202 //close (handle);
3203 //return size;
3204#endif
3205}
3206
3207void file_io::delete_file(const char *fname)
3208{
3209 char str[1000];
3210
3211 sprintf(str, "rm %s", fname);
3212 system(str);
3213}
3214
3215void file_io::fwrite_int4(FILE *fp, int a)
3216{
3217 int_4 I;
3218
3219 I = (int_4) a;
3220 fwrite(&I, 1 /* size */, 4 /* items */, fp);
3221}
3222
3224{
3225 int_4 I;
3226
3227 fread(&I, 1 /* size */, 4 /* items */, fp);
3228 return I;
3229}
3230
3231void file_io::fwrite_uchars(FILE *fp, uchar *p, int len)
3232{
3233 fwrite(p, 1 /* size */, len /* items */, fp);
3234}
3235
3236void file_io::fread_uchars(FILE *fp, uchar *p, int len)
3237{
3238 fread(p, 1 /* size */, len /* items */, fp);
3239}
3240
3241void file_io::read_numbers_from_file(std::string &fname,
3242 int *&the_set, int &set_size, int verbose_level)
3243{
3244 int f_v = (verbose_level >= 1);
3245 int f_vv = (verbose_level >= 2);
3246 int i, a;
3247 double d;
3248
3249 if (f_v) {
3250 cout << "read_numbers_from_file opening file " << fname
3251 << " of size " << file_size(fname) << " for reading" << endl;
3252 }
3253 ifstream f(fname);
3254
3255 set_size = 1000;
3256 the_set = NEW_int(set_size);
3257
3258 for (i = 0; TRUE; i++) {
3259 if (f.eof()) {
3260 break;
3261 }
3262 f >> d;
3263 a = (int) d;
3264 if (f_vv) {
3265 cout << "read_set_from_file: the " << i
3266 << "-th number is " << d << " which becomes "
3267 << a << endl;
3268 }
3269 if (a == -1) {
3270 break;
3271 }
3272 the_set[i] = a;
3273 if (i >= set_size) {
3274 cout << "i >= set_size" << endl;
3275 exit(1);
3276 }
3277 }
3278 set_size = i;
3279 if (f_v) {
3280 cout << "read a set of size " << set_size
3281 << " from file " << fname << endl;
3282 }
3283 if (f_vv) {
3284 cout << "the set is:" << endl;
3285 Int_vec_print(cout, the_set, set_size);
3286 cout << endl;
3287 }
3288}
3289
3291 std::string &fname_ascii,
3292 int *&Sets, int &nb_sets, int &set_size, int verbose_level)
3293{
3294 int f_v = (verbose_level >= 1);
3295 if (f_v) {
3296 cout << "file_io::read_ascii_set_of_sets_constant_size "
3297 "reading ascii file " << fname_ascii << endl;
3298 }
3300 int N;
3301 int i;
3302
3303 N = count_number_of_lines_in_file(fname_ascii,
3304 0 /* verbose_level */);
3305
3306
3307 {
3308 if (f_v) {
3309 cout << "file_io::read_ascii_set_of_sets_constant_size "
3310 "Reading file " << fname_ascii << " of size "
3311 << file_size(fname_ascii) << ":" << endl;
3312 }
3313 ifstream fp(fname_ascii);
3314
3315 int nb;
3316
3317
3318
3319
3320 nb_sets = 0;
3321 while (TRUE) {
3322 fp >> nb;
3323 if (nb == -1) {
3324 break;
3325 }
3326
3327 if (f_v) {
3328 cout << "file_io::read_ascii_set_of_sets_constant_size "
3329 "set " << nb_sets << ":";
3330 }
3331
3332 if (nb_sets == 0) {
3333 set_size = nb;
3334 Sets = NEW_int(N * set_size);
3335 }
3336 else {
3337 if (nb != set_size) {
3338 cout << "file_io::read_ascii_set_of_sets_constant_size "
3339 "nb != set_size" << endl;
3340 exit(1);
3341 }
3342 }
3343 for (i = 0; i < set_size; i++) {
3344 fp >> Sets[nb_sets * set_size + i];
3345 }
3346
3347 Sorting.int_vec_heapsort(Sets + nb_sets * set_size, set_size);
3348
3349 if (f_v) {
3350 cout << "file_io::read_ascii_set_of_sets_constant_size "
3351 "set " << nb_sets << " / " << N << " is ";
3352 Int_vec_print(cout, Sets + nb_sets * set_size, set_size);
3353 cout << endl;
3354 }
3355 nb_sets++;
3356 }
3357 }
3358 if (f_v) {
3359 cout << "file_io::read_ascii_set_of_sets_constant_size "
3360 "We found " << nb_sets << " sets" << endl;
3361 }
3362
3363#if 0
3364 cout << "writing spreads to file " << fname_spreads << endl;
3365 Fio.int_matrix_write_csv(fname_spreads, Spreads, nb_spreads,
3366 P->spread_size);
3367
3368 cout << "Written file " << fname_spreads << " of size "
3369 << Fio.file_size(fname_spreads) << endl;
3370 FREE_int(Spreads);
3371#endif
3372 if (f_v) {
3373 cout << "file_io::read_ascii_set_of_sets_constant_size "
3374 "reading ascii file " << fname_ascii << " done" << endl;
3375 }
3376}
3377
3378void file_io::write_decomposition_stack(char *fname, int m, int n, int *v, int *b, int *aij, int verbose_level)
3379{
3380 int f_v = (verbose_level >= 1);
3381
3382 if (f_v) {
3383 cout << "file_io::write_widor" << endl;
3384 }
3385 {
3386 ofstream f(fname);
3387 int i, j;
3388
3389
3390 f << "<HTDO type=pt ptanz=" << m << " btanz=" << n << " fuse=simple>" << endl;
3391 f << " ";
3392 for (j = 0; j < n; j++) {
3393 f << setw(8) << b[j] << " ";
3394 }
3395 f << endl;
3396 for (i = 0; i < m; i++) {
3397 f << setw(8) << v[i];
3398 for (j = 0; j < n; j++) {
3399 f << setw(8) << aij[i * n + j] << " ";
3400 }
3401 f << endl;
3402 }
3403 f << endl;
3404 for (i = 0; i < m; i++) {
3405 f << setw(3) << 1;
3406 }
3407 f << endl;
3408 f << "</HTDO>" << endl;
3409 }
3410
3411 if (f_v) {
3412 cout << "file_io::write_decomposition_stack done" << endl;
3413 cout << "written file " << fname << " of size " << file_size(fname) << endl;
3414 }
3415}
3416
3417void file_io::create_file(create_file_description *Descr, int verbose_level)
3418{
3419 file_io Fio;
3420 int j;
3421
3422 if (Descr->f_read_cases) {
3423
3424 cout << "Descr->f_read_cases" << endl;
3425 string fname;
3426 char str[1000];
3427 //int *Cases;
3428 int nb_cases;
3429 int n, c;
3430
3431 cout << "reading file " << Descr->read_cases_fname << endl;
3432
3433
3435
3436 S.read_spreadsheet(Descr->read_cases_fname, 0/*verbose_level - 1*/);
3437
3438 nb_cases = S.nb_rows;
3439 n = S.nb_cols;
3440
3441#if 0
3443 Cases, nb_cases, n, 0 /* verbose_level */);
3444#endif
3445
3446 cout << "nb_cases = " << nb_cases << endl;
3447 cout << "n = " << n << endl;
3448 if (n != 1) {
3449 cout << "read cases, n != 1" << endl;
3450 exit(1);
3451 }
3452#if 0
3453 cout << "We found " << nb_cases << " cases to do:" << endl;
3454 int_vec_print(cout, Cases, nb_cases);
3455 cout << endl;
3456#endif
3457
3458 const char *log_fname = "log_file.txt";
3459 const char *log_mask = "\tsbatch job%03d";
3460 {
3461 ofstream fp_log(log_fname);
3462
3463 for (c = 0; c < nb_cases; c++) {
3464
3465 //i = Cases[c];
3466 sprintf(str, Descr->file_mask.c_str(), c);
3467 fname.assign(str);
3468
3469
3470 {
3471 ofstream fp(fname);
3472
3473 for (j = 0; j < Descr->nb_lines; j++) {
3474 if (Descr->f_line_numeric[j]) {
3475 sprintf(str, Descr->lines[j].c_str(), c);
3476 }
3477 else {
3478 string s;
3479
3480 S.get_string(s, c, 0);
3481
3482 sprintf(str, Descr->lines[j].c_str(), s.c_str());
3483 }
3485 fp << str << endl;
3486 }
3487 }
3488 cout << "Written file " << fname << " of size "
3489 << Fio.file_size(fname) << endl;
3490
3491 char log_entry[1000];
3492
3493 sprintf(log_entry, log_mask, c);
3494 fp_log << log_entry << endl;
3495 }
3496 }
3497 cout << "Written file " << log_fname << " of size "
3498 << Fio.file_size(log_fname) << endl;
3499 }
3500 else if (Descr->f_read_cases_text) {
3501 cout << "read_cases_text" << endl;
3502
3503 if (!Descr->f_N) {
3504 cout << "please use option -N <N>" << endl;
3505 exit(1);
3506 }
3507 if (!Descr->f_command) {
3508 cout << "please use option -command <command>" << endl;
3509 exit(1);
3510 }
3511
3512 cout << "Reading file " << Descr->read_cases_fname << endl;
3513
3515 int row;
3516
3518 S->read_spreadsheet(Descr->read_cases_fname, 0 /*verbose_level*/);
3519
3520 cout << "Read spreadsheet with " << S->nb_rows << " rows" << endl;
3521
3522 //S->print_table(cout, FALSE /* f_enclose_in_parentheses */);
3523 for (row = 0; row < MINIMUM(10, S->nb_rows); row++) {
3524 cout << "row " << row << " : ";
3525 S->print_table_row(row,
3526 FALSE /* f_enclose_in_parentheses */, cout);
3527 }
3528 cout << "..." << endl;
3529 for (row = MAXIMUM(S->nb_rows - 10, 0); row < S->nb_rows; row++) {
3530 cout << "row " << row << " : ";
3531 S->print_table_row(row,
3532 FALSE /* f_enclose_in_parentheses */, cout);
3533 }
3534
3535
3536
3537 create_files_list_of_cases(S, Descr, verbose_level);
3538
3539 }
3540 else if (Descr->f_N) {
3541 create_files(Descr, verbose_level);
3542 }
3543
3544}
3545
3547{
3548 int i, j, l;
3549
3550 l = strlen(str);
3551 for (i = 0, j = 0; i < l; i++, j++) {
3552 if (str[i] == '\\' && i < l - 1 && str[i + 1] == 't') {
3553 str[j] = '\t';
3554 i++;
3555 }
3556 else if (str[i] == '\\' && i < l - 1 && str[i + 1] == 'D') {
3557 str[j] = '$';
3558 i++;
3559 }
3560 else if (str[i] == '\\' && i < l - 1 && str[i + 1] == 'B') {
3561 str[j] = '\\';
3562 i++;
3563 }
3564 else if (str[i] == '\\' && i < l - 1 && str[i + 1] == 'n') {
3565 str[j] = '\n';
3566 i++;
3567 }
3568 else {
3569 str[j] = str[i];
3570 }
3571 }
3572 str[j] = 0;
3573}
3574
3576 int verbose_level)
3577{
3578 int f_v = (verbose_level >= 1);
3579 int i, j;
3580 file_io Fio;
3581
3582 string fname;
3583 char str[1000];
3584 int r;
3585
3586 if (f_v) {
3587 cout << "file_io::create_files" << endl;
3588 }
3589
3590 const char *makefile_fname = "makefile_submit";
3591 {
3592 ofstream fp_makefile(makefile_fname);
3593
3594 for (i = 0; i < Descr->N; i++) {
3595
3596 sprintf(str, Descr->file_mask.c_str(), i);
3597 fname.assign(str);
3598
3599 fp_makefile << "\tsbatch " << fname << endl;
3600 {
3601 ofstream fp(fname);
3602
3603 for (j = 0; j < Descr->nb_lines; j++) {
3604
3605
3606 cout << "mask='" << Descr->lines[j].c_str() << "'" << endl;
3607 sprintf(str, Descr->lines[j].c_str(), i, i, i, i, i, i, i, i);
3608
3609
3611 cout << "str='" << str << "'" << endl;
3612 fp << str << endl;
3613 }
3614 if (Descr->f_repeat) {
3615 if (Descr->f_split) {
3616 for (r = 0; r < Descr->split_m; r++) {
3617 for (j = 0; j < Descr->repeat_N; j++) {
3618 if ((j % Descr->split_m) == r) {
3619 sprintf(str, Descr->repeat_mask.c_str(), j);
3621 fp << str << endl;
3622 }
3623 }
3624 fp << endl;
3625 }
3626 }
3627 else {
3628 int c;
3629
3630 sprintf(str, Descr->repeat_mask.c_str(), Descr->repeat_N);
3632 fp << str << endl;
3633 if (!Descr->f_command) {
3634 cout << "please use option -command when using -repeat" << endl;
3635 exit(1);
3636 }
3637 for (j = 0; j < Descr->repeat_N; j++) {
3638 c = Descr->repeat_start + j * Descr->repeat_increment;
3639 sprintf(str, Descr->command.c_str(), c, c, c, c);
3641 fp << str << endl;
3642 }
3643 }
3644 for (j = 0; j < Descr->nb_final_lines; j++) {
3645 fp << Descr->final_lines[j] << endl;
3646 }
3647 }
3648 }
3649 cout << "Written file " << fname << " of size "
3650 << Fio.file_size(fname) << endl;
3651
3652 }
3653
3654 }
3655 cout << "Written file " << makefile_fname << " of size "
3656 << Fio.file_size(makefile_fname) << endl;
3657
3658
3659 if (f_v) {
3660 cout << "file_io::create_files done" << endl;
3661 }
3662}
3663
3665 create_file_description *Descr, int verbose_level)
3666{
3667 int f_v = (verbose_level >= 1);
3668 int i, j;
3669
3670 string fname;
3671 char str[1000];
3672 file_io Fio;
3673
3674 if (f_v) {
3675 cout << "file_io::create_files_list_of_cases" << endl;
3676 }
3677
3678 int nb_cases = S->nb_rows - 1;
3679 cout << "nb_cases=" << nb_cases << endl;
3680
3681
3682 const char *makefile_fname = "makefile_submit";
3683 const char *fname_submit_script = "submit_jobs.sh";
3684 {
3685 ofstream fp_makefile(makefile_fname);
3686 ofstream fp_submit_script(fname_submit_script);
3687
3688 fp_submit_script << "#!/bin/bash" << endl;
3689 for (i = 0; i < Descr->N; i++) {
3690
3691 sprintf(str, Descr->file_mask.c_str(), i);
3692 fname.assign(str);
3693
3694 fp_makefile << "\tsbatch " << fname << endl;
3695 fp_submit_script << "sbatch " << fname << endl;
3696 {
3697 ofstream fp(fname);
3698
3699 for (j = 0; j < Descr->nb_lines; j++) {
3700 sprintf(str, Descr->lines[j].c_str(), i, i, i, i, i, i, i, i);
3702 fp << str << endl;
3703 }
3704
3705 if (Descr->f_tasks) {
3706 char str[1000];
3707 int t;
3708 //int NT;
3709
3710 sprintf(str, Descr->tasks_line.c_str(), Descr->nb_tasks);
3711 fp << str << endl;
3712 //NT = Descr->N * Descr->nb_tasks;
3713 for (t = 0; t < Descr->nb_tasks; t++) {
3714 sprintf(str, Descr->command.c_str(), i, t, i, t);
3716 fp << str; // << " \\" << endl;
3717 for (j = 0; j < nb_cases; j++) {
3718 if ((j % Descr->N) != i) {
3719 continue;
3720 }
3721 if (((j - i) / Descr->N) % Descr->nb_tasks != t) {
3722 continue;
3723 }
3724 string entry;
3725 //int case_number;
3726
3727 //case_number = S->get_int(j + 1, Descr->read_cases_column_of_case);
3728 S->get_string(entry, j + 1, Descr->read_cases_column_of_fname);
3729 fp << /* case_number << " " <<*/ entry;
3730
3731 if (j < nb_cases - Descr->N) {
3732 fp << ", "; // << endl;
3733 }
3734 else {
3735 fp << ")\"\\" << endl;
3736 }
3737 }
3738 fp << " & " << endl;
3739 //fp << "\t\t" << -1 << " &" << endl;
3740 }
3741 } // if
3742 else {
3743 sprintf(str, Descr->command.c_str(), i);
3745 fp << str << " \\" << endl;
3746 //fp << command << " \\" << endl;
3747 for (j = 0; j < nb_cases; j++) {
3748 if ((j % Descr->N) != i) {
3749 continue;
3750 }
3751 string entry;
3752 //int case_number;
3753
3754 //case_number = S->get_int(j + 1, Descr->read_cases_column_of_case);
3755 S->get_string(entry, j + 1, Descr->read_cases_column_of_fname);
3756 fp << "\t\t" /*<< case_number << " "*/ << entry << " \\" << endl;
3757#if 0
3758 if (j < nb_cases - N) {
3759 fp << ", "; // << endl;
3760 }
3761 else {
3762 fp << ")\"\\" << endl;
3763 }
3764#endif
3765 }
3766 fp << " & " << endl;
3767 //fp << "\t\t" << -1 << " &" << endl;
3768 } // else
3769
3770 for (j = 0; j < Descr->nb_final_lines; j++) {
3771 sprintf(str, Descr->final_lines[j].c_str(), i, i, i, i, i, i, i, i);
3773 fp << str << endl;
3774 } // next j
3775
3776 } // close fp(fname)
3777
3778 cout << "Written file " << fname << " of size "
3779 << Fio.file_size(fname) << endl;
3780
3781 } // next i
3782
3783 }
3784 cout << "Written file " << makefile_fname << " of size "
3785 << Fio.file_size(makefile_fname) << endl;
3786
3787 const char *mask_submit_script_piecewise = "submit_jobs_%d.sh";
3788 char fname_submit_piecewise[1000];
3789 char cmd[2000];
3790 int h;
3791 int N1 = 128;
3792
3793 for (h = 0; h < Descr->N / N1; h++) {
3794 sprintf(fname_submit_piecewise, mask_submit_script_piecewise, h * N1);
3795 {
3796 ofstream fp_submit_script(fname_submit_piecewise);
3797
3798 fp_submit_script << "#!/bin/bash" << endl;
3799 for (i = 0; i < N1; i++) {
3800
3801 sprintf(str, Descr->file_mask.c_str(), h * N1 + i);
3802 fname.assign(str);
3803
3804 fp_submit_script << "sbatch " << fname;
3805 if (i < N1 - 1) {
3806 fp_submit_script << "; ";
3807 }
3808 else {
3809 fp_submit_script << endl;
3810 }
3811 }
3812 }
3813 cout << "Written file " << fname_submit_piecewise << " of size "
3814 << Fio.file_size(fname_submit_piecewise) << endl;
3815 sprintf(cmd, "chmod +x %s", fname_submit_piecewise);
3816 system(cmd);
3817 }
3818 if (f_v) {
3819 cout << "file_io::create_files_list_of_cases done" << endl;
3820 }
3821}
3822
3823int file_io::number_of_vertices_in_colored_graph(std::string &fname, int verbose_level)
3824{
3826
3827 CG.load(fname, verbose_level);
3828
3829 return CG.nb_points;
3830}
3831
3832void file_io::do_csv_file_select_rows(std::string &fname,
3833 std::string &rows_text,
3834 int verbose_level)
3835{
3836 int f_v = (verbose_level >= 1);
3837
3838 if (f_v) {
3839 cout << "file_io::do_csv_file_select_rows" << endl;
3840 }
3841 int *Rows;
3842 int nb_rows;
3844
3845 Int_vec_scan(rows_text, Rows, nb_rows);
3846
3848
3849 S.read_spreadsheet(fname, verbose_level);
3850
3851
3852 int i;
3853
3854
3855
3856 string fname_out;
3857
3858 fname_out.assign(fname);
3859 ST.chop_off_extension(fname_out);
3860 fname_out.append("_select.csv");
3861
3862 {
3863 ofstream ost(fname_out);
3864 ost << "Row,";
3865 S.print_table_row(0, FALSE, ost);
3866 for (i = 0; i < nb_rows; i++) {
3867 ost << i << ",";
3868 S.print_table_row(Rows[i] + 1, FALSE, ost);
3869 }
3870 ost << "END" << endl;
3871 }
3872 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
3873
3874 FREE_int(Rows);
3875
3876 if (f_v) {
3877 cout << "file_io::do_csv_file_select_rows done" << endl;
3878 }
3879}
3880
3882 int split_modulo,
3883 int verbose_level)
3884{
3885 int f_v = (verbose_level >= 1);
3886
3887 if (f_v) {
3888 cout << "file_io::do_csv_file_split_rows_modulo" << endl;
3889 }
3892
3893 S.read_spreadsheet(fname, verbose_level);
3894
3895
3896 int i, I;
3897
3898
3899
3900
3901
3902 for (I = 0; I < split_modulo; I++) {
3903
3904 string fname_out;
3905 char str[1000];
3906
3907 fname_out.assign(fname);
3908 ST.chop_off_extension(fname_out);
3909 sprintf(str, "_split_%d_mod_%d.csv", I, split_modulo);
3910 fname_out.append(str);
3911
3912 {
3913 ofstream ost(fname_out);
3914 S.print_table_row(0, FALSE, ost);
3915 for (i = 0; i < S.nb_rows - 1; i++) {
3916 if ((i % split_modulo) != I) {
3917 continue;
3918 }
3919 //ost << i << ",";
3920 S.print_table_row(i + 1, FALSE, ost);
3921 }
3922 ost << "END" << endl;
3923 }
3924 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
3925 }
3926
3927 if (f_v) {
3928 cout << "file_io::do_csv_file_split_rows_modulo done" << endl;
3929 }
3930}
3931
3932void file_io::do_csv_file_select_cols(std::string &fname,
3933 std::string &cols_text,
3934 int verbose_level)
3935{
3936 int f_v = (verbose_level >= 1);
3937
3938 if (f_v) {
3939 cout << "file_io::do_csv_file_select_cols" << endl;
3940 }
3941 int *Cols;
3942 int nb_cols;
3944
3945 Int_vec_scan(cols_text, Cols, nb_cols);
3946
3948
3949 S.read_spreadsheet(fname, verbose_level);
3950
3951
3952 int i;
3953 int nb_rows;
3954
3955 nb_rows = S.nb_rows;
3956 if (f_v) {
3957 cout << "file_io::do_csv_file_select_cols nb_rows=" << nb_rows << endl;
3958 }
3959
3960
3961 string fname_out;
3962
3963 fname_out.assign(fname);
3964 ST.chop_off_extension(fname_out);
3965 fname_out.append("_select.csv");
3966
3967 {
3968 ofstream ost(fname_out);
3969 ost << "Row,";
3970 S.print_table_row_with_column_selection(0, FALSE, Cols, nb_cols, ost);
3971 for (i = 0; i < nb_rows - 1; i++) {
3972 ost << i << ",";
3974 Cols, nb_cols, ost);
3975 }
3976 ost << "END" << endl;
3977 }
3978 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
3979
3980 fname_out.assign(fname);
3981 ST.chop_off_extension(fname_out);
3982 fname_out.append("_special.csv");
3983
3984 {
3985 ofstream ost(fname_out);
3986 //ost << "Row,";
3987 //S.print_table_row_with_column_selection(0, FALSE, Cols, nb_cols, ost);
3988 for (i = 0; i < nb_rows - 1; i++) {
3989 ost << "Orb" << i << "=";
3991 Cols, nb_cols, ost);
3992 }
3993 ost << "END" << endl;
3994 }
3995 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
3996
3997 FREE_int(Cols);
3998 if (f_v) {
3999 cout << "file_io::do_csv_file_select_cols done" << endl;
4000 }
4001}
4002
4003
4004
4006 std::string &rows_text, std::string &cols_text,
4007 int verbose_level)
4008{
4009 int f_v = (verbose_level >= 1);
4010
4011 if (f_v) {
4012 cout << "file_io::do_csv_file_select_rows_and_cols" << endl;
4013 }
4014 int *Rows;
4015 int nb_rows;
4016 int *Cols;
4017 int nb_cols;
4019
4020 Int_vec_scan(rows_text, Rows, nb_rows);
4021 cout << "Rows: ";
4022 Int_vec_print(cout, Rows, nb_rows);
4023 cout << endl;
4024
4025 Int_vec_scan(cols_text, Cols, nb_cols);
4026 cout << "Cols: ";
4027 Int_vec_print(cout, Cols, nb_cols);
4028 cout << endl;
4029
4031
4032 S.read_spreadsheet(fname, verbose_level);
4033
4034
4035 int i;
4036
4037
4038
4039 string fname_out;
4040
4041 fname_out.assign(fname);
4042 ST.chop_off_extension(fname_out);
4043 fname_out.append("_select.csv");
4044
4045 {
4046 ofstream ost(fname_out);
4047 ost << "Row,";
4048 S.print_table_row_with_column_selection(0, FALSE, Cols, nb_cols, ost);
4049 for (i = 0; i < nb_rows; i++) {
4050 ost << i << ",";
4052 Cols, nb_cols, ost);
4053 }
4054 ost << "END" << endl;
4055 }
4056 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
4057
4058
4059 FREE_int(Rows);
4060 FREE_int(Cols);
4061 if (f_v) {
4062 cout << "file_io::do_csv_file_select_rows done" << endl;
4063 }
4064}
4065
4067 std::string &csv_fname, std::string &col_label, int verbose_level)
4068{
4069 int f_v = (verbose_level >= 1);
4070
4071 if (f_v) {
4072 cout << "file_io::do_csv_file_extract_column_to_txt" << endl;
4073 }
4074 string fname;
4076
4078 int identifier_column;
4079
4081
4082 S->read_spreadsheet(csv_fname, 0 /*verbose_level*/);
4083 cout << "Table " << csv_fname << " has been read" << endl;
4084
4085
4086 identifier_column = S->find_column(col_label);
4087
4088
4089 fname.assign(csv_fname);
4090 ST.replace_extension_with(fname, "_");
4091 fname.append(col_label);
4092 fname.append(".txt");
4093
4094
4095
4096
4097 {
4098 ofstream ost(fname);
4099
4100 int i, j;
4101
4102 for (i = 1; i < S->nb_rows; i++) {
4103 string entry;
4104 long int *v;
4105 int sz;
4106
4107 S->get_string(entry, i, identifier_column);
4108 Lint_vec_scan(entry, v, sz);
4109 ost << sz;
4110 for (j = 0; j < sz; j++) {
4111 ost << " " << v[j];
4112 }
4113 ost << endl;
4114 FREE_lint(v);
4115 }
4116 ost << -1 << endl;
4117 }
4118 if (f_v) {
4119 cout << "Written file " << fname << " of size " << file_size(fname) << endl;
4120 }
4121
4122 if (f_v) {
4123 cout << "file_io::do_csv_file_extract_column_to_txt done" << endl;
4124 }
4125}
4126
4127
4128
4130 std::string &csv_fname, int verbose_level)
4131{
4132 int f_v = (verbose_level >= 1);
4133
4134 if (f_v) {
4135 cout << "file_io::do_csv_file_sort_each_row" << endl;
4136 }
4137 int *M;
4138 int m, n;
4140 int i;
4141 string fname;
4143
4144 int_matrix_read_csv(csv_fname, M, m, n, verbose_level);
4145 for (i = 0; i < m; i++) {
4146 Sorting.int_vec_heapsort(M + i * n, n);
4147 }
4148 fname.assign(csv_fname);
4149 ST.replace_extension_with(fname, "_sorted.csv");
4150
4151 int_matrix_write_csv(fname, M, m, n);
4152
4153 if (f_v) {
4154 cout << "Written file " << fname << " of size " << file_size(fname) << endl;
4155 }
4156
4157 if (f_v) {
4158 cout << "file_io::do_csv_file_sort_each_row done" << endl;
4159 }
4160}
4161
4163 std::vector<std::string> &csv_file_join_fname,
4164 std::vector<std::string> &csv_file_join_identifier, int verbose_level)
4165{
4166 int f_v = (verbose_level >= 1);
4167
4168 if (f_v) {
4169 cout << "file_io::do_csv_file_join" << endl;
4170 }
4171
4172 int nb_files;
4173 int i;
4174
4175 nb_files = csv_file_join_fname.size();
4176
4178 int *identifier_column;
4179
4180 S = new data_structures::spreadsheet[nb_files];
4181 identifier_column = NEW_int(nb_files);
4182
4183 for (i = 0; i < nb_files; i++) {
4184 cout << "Reading table " << csv_file_join_fname[i] << endl;
4185 S[i].read_spreadsheet(csv_file_join_fname[i], 0 /*verbose_level*/);
4186 cout << "Table " << csv_file_join_fname[i] << " has been read" << endl;
4187#if 0
4188 if (i == 0) {
4189 cout << "The first table is:" << endl;
4190 S[0].print_table(cout, FALSE);
4191 }
4192#endif
4193 if (FALSE) {
4194 cout << "The " << i << "th table is:" << endl;
4195 S[i].print_table(cout, FALSE);
4196 }
4197
4198
4199 }
4200
4201#if 0
4202 cout << "adding " << nb_with << " -with entries" << endl;
4203 for (i = 0; i < nb_with; i++) {
4204 S[with_table[i]].add_column_with_constant_value(with_label[i], with_value[i]);
4205 }
4206#endif
4207
4208 for (i = 0; i < nb_files; i++) {
4209 identifier_column[i] = S[i].find_by_column(csv_file_join_identifier[i].c_str());
4210 cout << "Table " << csv_file_join_fname[i] << ", identifier " << identifier_column[i] << endl;
4211 }
4212
4213#if 0
4214 for (i = 0; i < nb_files; i++) {
4215 by_column[i] = S[i].find_by_column(join_by);
4216 cout << "File " << fname[i] << " by_column[" << i << "]=" << by_column[i] << endl;
4217 }
4218#endif
4219
4220 cout << "joining " << nb_files << " files" << endl;
4221 for (i = 1; i < nb_files; i++) {
4222 cout << "Joining table " << 0 << " = " << csv_file_join_fname[0] << " with table " << i << " = " << csv_file_join_fname[i] << endl;
4223 S[0].join_with(S + i, identifier_column[0], identifier_column[i], verbose_level - 2);
4224 cout << "joining " << csv_file_join_fname[0] << " with table " << csv_file_join_fname[i] << " done" << endl;
4225#if 0
4226 cout << "After join, the table is:" << endl;
4227 S[0].print_table(cout, FALSE);
4228#endif
4229 }
4230
4231
4232
4233
4234
4235
4236#if 0
4237 if (f_drop) {
4238 S[0].remove_rows(drop_column, drop_label, verbose_level);
4239 }
4240#endif
4241
4242
4243 string save_fname;
4245
4246 save_fname.assign(csv_file_join_fname[0]);
4247 ST.chop_off_extension(save_fname);
4248 save_fname.append("_joined.csv");
4249
4250 {
4251 ofstream f(save_fname);
4252 S[0].print_table(f, FALSE);
4253 f << "END" << endl;
4254 }
4255 cout << "Written file " << save_fname << " of size " << file_size(save_fname) << endl;
4256
4257
4258 if (f_v) {
4259 cout << "file_io::do_csv_file_join done" << endl;
4260 }
4261}
4262
4264 std::vector<std::string> &fname_in, std::string &fname_out, int verbose_level)
4265{
4266 int f_v = (verbose_level >= 1);
4267
4268 if (f_v) {
4269 cout << "file_io::do_csv_file_concatenate" << endl;
4270 }
4271
4272 int nb_files;
4273 int i;
4274
4275 nb_files = fname_in.size();
4276
4278 int *identifier_column;
4279
4280 S = new data_structures::spreadsheet[nb_files];
4281 identifier_column = NEW_int(nb_files);
4282
4283 for (i = 0; i < nb_files; i++) {
4284 cout << "Reading table " << fname_in[i] << endl;
4285 S[i].read_spreadsheet(fname_in[i], 0 /*verbose_level*/);
4286 cout << "Table " << fname_in[i] << " has been read" << endl;
4287
4288 if (FALSE) {
4289 cout << "The " << i << "-th table is:" << endl;
4290 S[i].print_table(cout, FALSE);
4291 }
4292
4293
4294 }
4295
4296 {
4297 ofstream ost(fname_out);
4298 int j;
4299 int f_enclose_in_parentheses = FALSE;
4300
4301 S[0].print_table_row(0, f_enclose_in_parentheses, ost);
4302 for (i = 0; i < nb_files; i++) {
4303 //S[i].print_table(ost, FALSE);
4304 for (j = 1; j < S[i].nb_rows; j++) {
4305 S[i].print_table_row(j, f_enclose_in_parentheses, ost);
4306 }
4307 }
4308 ost << "END" << endl;
4309 }
4310 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
4311
4312
4313 if (f_v) {
4314 cout << "file_io::do_csv_file_concatenate done" << endl;
4315 }
4316}
4317
4318void file_io::do_csv_file_latex(std::string &fname,
4319 int f_produce_latex_header,
4320 int nb_lines_per_table,
4321 int verbose_level)
4322{
4323 int f_v = (verbose_level >= 1);
4324
4325 if (f_v) {
4326 cout << "file_io::do_csv_file_latex" << endl;
4327 }
4328
4330
4331 S.read_spreadsheet(fname, verbose_level);
4332
4333
4334 if (f_v) {
4335 cout << "file_io::do_csv_file_latex S.nb_rows = " << S.nb_rows << endl;
4336 cout << "file_io::do_csv_file_latex S.nb_cols = " << S.nb_cols << endl;
4337 }
4338
4339
4340 string fname_out;
4342
4343 fname_out.assign(fname);
4344 ST.chop_off_extension(fname_out);
4345 fname_out.append(".tex");
4346
4347 {
4348 ofstream ost(fname_out);
4350
4351 //S.print_table_latex_all_columns(ost, FALSE /* f_enclose_in_parentheses */);
4352
4353 int *f_column_select;
4354 int j;
4355
4356 f_column_select = NEW_int(S.nb_cols);
4357 for (j = 0; j < S.nb_cols; j++) {
4358 f_column_select[j] = TRUE;
4359 }
4360 f_column_select[0] = FALSE;
4361
4362
4363 if (f_produce_latex_header) {
4364 //L.head_easy(ost);
4365 L.head(ost,
4366 FALSE /* f_book */,
4367 TRUE /* f_title */,
4368 "File", "Orbiter",
4369 FALSE /*f_toc */,
4370 FALSE /* f_landscape */,
4371 FALSE /* f_12pt */,
4372 FALSE /* f_enlarged_page */,
4373 TRUE /* f_pagenumbers */,
4374 NULL /* extras_for_preamble */);
4375 }
4376
4377 S.print_table_latex(ost,
4378 f_column_select,
4379 FALSE /* f_enclose_in_parentheses */,
4380 nb_lines_per_table);
4381
4382 FREE_int(f_column_select);
4383
4384 if (f_produce_latex_header) {
4385 L.foot(ost);
4386 }
4387
4388 }
4389 cout << "Written file " << fname_out << " of size " << file_size(fname_out) << endl;
4390
4391
4392 if (f_v) {
4393 cout << "file_io::do_csv_file_select_rows done" << endl;
4394 }
4395}
4396
4397void file_io::read_solutions_and_tally(std::string &fname, int sz, int verbose_level)
4398{
4399 int nb_solutions;
4400 int solution_size = sz;
4401 int *Sol;
4402 int i, j;
4403
4404 std::vector<std::vector<int> > Solutions;
4405
4406
4408 Solutions, solution_size,
4409 verbose_level);
4410
4411 nb_solutions = Solutions.size();
4412
4413 Sol = NEW_int(nb_solutions * solution_size);
4414 for (i = 0; i < nb_solutions; i++) {
4415 for (j = 0; j < solution_size; j++) {
4416 Sol[i * solution_size + j] = Solutions[i][j];
4417 }
4418 }
4419
4420
4421 cout << "nb_solutions = " << nb_solutions << endl;
4422
4424
4425 T.init(Sol, nb_solutions * solution_size, TRUE, 0);
4426 cout << "tally:" << endl;
4427 T.print(TRUE);
4428 cout << endl;
4429
4430
4431 int *Pts;
4432 int nb_pts;
4433 int multiplicity = 4;
4434
4436 Pts, nb_pts, multiplicity, verbose_level);
4437
4438 cout << "multiplicity " << multiplicity << " number of pts = " << nb_pts << endl;
4439 Int_vec_print(cout, Pts, nb_pts);
4440 cout << endl;
4441
4442
4443 FREE_int(Sol);
4444
4445}
4446
4447void file_io::save_fibration(std::vector<std::vector<std::pair<int, int> > > &Fibration, std::string &fname, int verbose_level)
4448{
4449 int f_v = (verbose_level >= 1);
4450
4451 if (f_v) {
4452 cout << "file_io::save_fibration" << endl;
4453 }
4455 string data_fname1;
4456 string data_fname2;
4459 int nb_sets;
4460 int *Sz;
4461 int i, j, l, a, b;
4462
4463 nb_sets = Fibration.size();
4464 Sz = NEW_int(nb_sets);
4465 for (i = 0; i < nb_sets; i++) {
4466 Sz[i] = Fibration[i].size();
4467 }
4468
4471
4472 File_idx->init_basic_with_Sz_in_int(INT_MAX /* underlying_set_size */,
4473 nb_sets, Sz, verbose_level);
4474 Obj_idx->init_basic_with_Sz_in_int(INT_MAX /* underlying_set_size */,
4475 nb_sets, Sz, verbose_level);
4476 for (i = 0; i < nb_sets; i++) {
4477 l = Fibration[i].size();
4478 for (j = 0; j < l; j++) {
4479 a = Fibration[i][j].first;
4480 b = Fibration[i][j].second;
4481 File_idx->Sets[i][j] = a;
4482 Obj_idx->Sets[i][j] = b;
4483 }
4484 }
4485
4486
4487 data_fname1.assign(fname);
4488 ST.replace_extension_with(data_fname1, "1.csv");
4489 data_fname2.assign(fname);
4490 ST.replace_extension_with(data_fname2, "2.csv");
4491
4492 if (f_v) {
4493 cout << "file_io::save_fibration before File_idx->save_csv" << endl;
4494 }
4495 File_idx->save_csv(data_fname1, TRUE, verbose_level);
4496 if (f_v) {
4497 cout << "file_io::save_fibration before Obj_idx->save_csv" << endl;
4498 }
4499 Obj_idx->save_csv(data_fname2, TRUE, verbose_level);
4500 if (f_v) {
4501 cout << "file_io::save_fibration after Obj_idx->save_csv" << endl;
4502 }
4503
4504
4505 if (f_v) {
4506 cout << "Written file " << data_fname1 << " of size " << file_size(data_fname1) << endl;
4507 cout << "Written file " << data_fname2 << " of size " << file_size(data_fname2) << endl;
4508 }
4509
4510 FREE_int(Sz);
4511 FREE_OBJECT(File_idx);
4512 FREE_OBJECT(Obj_idx);
4513
4514 if (f_v) {
4515 cout << "file_io::save_fibration done" << endl;
4516 }
4517}
4518
4519
4520void file_io::save_cumulative_canonical_labeling(std::vector<std::vector<int> > &Cumulative_canonical_labeling,
4521 std::string &fname, int verbose_level)
4522{
4523 int f_v = (verbose_level >= 1);
4524
4525 if (f_v) {
4526 cout << "file_io::save_cumulative_canonical_labeling" << endl;
4527 }
4528 //string_tools ST;
4529 string canonical_labeling_fname;
4530 int canonical_labeling_len;
4531 int u, v;
4532 long int *M;
4533
4534 if (Cumulative_canonical_labeling.size()) {
4535 canonical_labeling_len = Cumulative_canonical_labeling[0].size();
4536 }
4537 else {
4538 canonical_labeling_len = 0;
4539 }
4540
4541 canonical_labeling_fname.assign(fname);
4542 //ST.replace_extension_with(canonical_labeling_fname, "_can_lab.csv");
4543
4544
4545 M = NEW_lint(Cumulative_canonical_labeling.size() * canonical_labeling_len);
4546 for (u = 0; u < Cumulative_canonical_labeling.size(); u++) {
4547 for (v = 0; v < canonical_labeling_len; v++) {
4548 M[u * canonical_labeling_len + v] = Cumulative_canonical_labeling[u][v];
4549 }
4550 }
4551 lint_matrix_write_csv(canonical_labeling_fname,
4552 M, Cumulative_canonical_labeling.size(), canonical_labeling_len);
4553
4554 if (f_v) {
4555 cout << "Written file " << canonical_labeling_fname << " of size " << file_size(canonical_labeling_fname) << endl;
4556 }
4557 FREE_lint(M);
4558
4559}
4560
4561void file_io::save_cumulative_ago(std::vector<long int> &Cumulative_Ago,
4562 std::string &fname, int verbose_level)
4563{
4564 int f_v = (verbose_level >= 1);
4565
4566 if (f_v) {
4567 cout << "file_io::save_cumulative_ago" << endl;
4568 }
4569 string ago_fname;
4570 int u;
4571 long int *M;
4573
4574 ago_fname.assign(fname);
4575
4576 M = NEW_lint(Cumulative_Ago.size());
4577 for (u = 0; u < Cumulative_Ago.size(); u++) {
4578 M[u] = Cumulative_Ago[u];
4579 }
4580 lint_vec_write_csv(M, Cumulative_Ago.size(), ago_fname, "Ago");
4581
4583
4584 T.init_lint(M, Cumulative_Ago.size(), FALSE, 0);
4585 if (f_v) {
4586 cout << "Written file " << ago_fname << " of size " << file_size(ago_fname) << endl;
4587 }
4588
4589 if (f_v) {
4590 cout << "Ago distribution: ";
4591 T.print(TRUE);
4592 cout << endl;
4593 }
4594
4595 string ago_fname1;
4596
4597 ago_fname1.assign(ago_fname);
4598 ST.replace_extension_with(ago_fname1, "_ago_class_");
4599 T.save_classes_individually(ago_fname1);
4600
4601 FREE_lint(M);
4602
4603}
4604
4605void file_io::save_cumulative_data(std::vector<std::vector<int> > &Cumulative_data,
4606 std::string &fname, int verbose_level)
4607{
4608 int f_v = (verbose_level >= 1);
4609
4610 if (f_v) {
4611 cout << "file_io::save_cumulative_data" << endl;
4612 }
4613
4614 string data_fname;
4615 int data_len;
4616 int u, v;
4617 long int *M;
4618
4619 if (Cumulative_data.size()) {
4620 data_len = Cumulative_data[0].size();
4621 }
4622 else {
4623 data_len = 0;
4624 }
4625
4626 data_fname.assign(fname);
4627
4628 M = NEW_lint(Cumulative_data.size() * data_len);
4629 for (u = 0; u < Cumulative_data.size(); u++) {
4630 for (v = 0; v < data_len; v++) {
4631 M[u * data_len + v] = Cumulative_data[u][v];
4632 }
4633 }
4634 lint_matrix_write_csv(data_fname,
4635 M, Cumulative_data.size(), data_len);
4636
4637 if (f_v) {
4638 cout << "Written file " << data_fname << " of size " << file_size(data_fname) << endl;
4639 }
4640 FREE_lint(M);
4641
4642}
4643
4645 long int *data, int nb_rows, int data_sz, int nb_cols, int verbose_level)
4646{
4647 int f_v = (verbose_level >= 1);
4648 int *T;
4649 int i, j, h;
4650
4651 T = NEW_int(nb_rows * nb_cols);
4652
4653 Int_vec_zero(T, nb_rows * nb_cols);
4654 for (i = 0; i < nb_rows; i++) {
4655 for (h = 0; h < data_sz; h++) {
4656 j = data[i * data_sz + h];
4657 T[i * nb_cols + j] = 1;
4658 }
4659
4660 }
4661 int_matrix_write_csv(fname, T,
4662 nb_rows,
4663 nb_cols);
4664
4665 if (f_v) {
4666 cout << "file_io::write_characteristic_matrix Written file " << fname << " of size " << file_size(fname) << endl;
4667 }
4668 FREE_int(T);
4669
4670
4671}
4672
4673
4674}}}
4675
4676
4677
void init_basic_with_Sz_in_int(int underlying_set_size, int nb_sets, int *Sz, int verbose_level)
void save_csv(std::string &fname, int f_make_heading, int verbose_level)
void init_simple(int underlying_set_size, int nb_sets, int verbose_level)
Definition: set_of_sets.cpp:67
a collection of functions related to sorted vectors
void read_spreadsheet(std::string &fname, int verbose_level)
void join_with(spreadsheet *S2, int by1, int by2, int verbose_level)
void remove_rows(const char *drop_column, const char *drop_label, int verbose_level)
void print_table_row(int row, int f_enclose_in_parentheses, std::ostream &ost)
void print_table_latex(std::ostream &ost, int *f_column_select, int f_enclose_in_parentheses, int nb_lines_per_table)
void print_table_row_with_column_selection(int row, int f_enclose_in_parentheses, int *Col_selection, int nb_cols_selected, std::ostream &ost)
void add_column_with_constant_value(const char *label, char *value)
void print_table(std::ostream &ost, int f_enclose_in_parentheses)
functions related to strings and character arrays
void replace_extension_with(char *p, const char *new_ext)
a statistical analysis of data consisting of single integers
void init(int *data, int data_length, int f_second, int verbose_level)
Definition: tally.cpp:72
void save_classes_individually(std::string &fname)
Definition: tally.cpp:733
void init_lint(long int *data, int data_length, int f_second, int verbose_level)
Definition: tally.cpp:123
void get_data_by_multiplicity(int *&Pts, int &nb_pts, int multiplicity, int verbose_level)
Definition: tally.cpp:557
void load(std::string &fname, int verbose_level)
int count_number_of_lines_in_file(std::string &fname, int verbose_level)
Definition: file_io.cpp:1995
void int_vec_array_write_csv(int nb_vecs, int **Vec, int len, std::string &fname, const char **column_label)
Definition: file_io.cpp:1240
void parse_sets_and_check_sizes_easy(int len, int nb_cases, char **data, long int **&sets)
Definition: file_io.cpp:2230
void read_set_from_file_int4(std::string &fname, long int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2544
void read_k_th_set_from_file(std::string &fname, int k, int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2722
void read_solutions_from_file_and_get_solution_size(std::string &fname, int &nb_solutions, int *&Solutions, int &solution_size, int verbose_level)
Definition: file_io.cpp:831
void count_number_of_solutions_in_file_and_get_solution_size(std::string &fname, int &nb_solutions, int &solution_size, int verbose_level)
Definition: file_io.cpp:586
void int_matrix_write_csv(std::string &fname, int *M, int m, int n)
Definition: file_io.cpp:1300
int count_number_of_orbits_in_file(std::string &fname, int verbose_level)
Definition: file_io.cpp:1918
void create_files_list_of_cases(data_structures::spreadsheet *S, create_file_description *Descr, int verbose_level)
Definition: file_io.cpp:3664
void save_fibration(std::vector< std::vector< std::pair< int, int > > > &Fibration, std::string &fname, int verbose_level)
Definition: file_io.cpp:4447
void int_vecs3_write_csv(int *v1, int *v2, int *v3, int len, std::string &fname, const char *label1, const char *label2, const char *label3)
Definition: file_io.cpp:1223
void do_csv_file_select_rows(std::string &fname, std::string &rows_text, int verbose_level)
Definition: file_io.cpp:3832
void do_csv_file_sort_each_row(std::string &csv_fname, int verbose_level)
Definition: file_io.cpp:4129
void write_set_to_file_lint(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2513
void int_matrix_read_csv_no_border(std::string &fname, int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1522
void save_cumulative_canonical_labeling(std::vector< std::vector< int > > &Cumulative_canonical_labeling, std::string &fname, int verbose_level)
Definition: file_io.cpp:4520
void int_vec_write_csv(int *v, int len, std::string &fname, const char *label)
Definition: file_io.cpp:1175
void lint_matrix_write_csv(std::string &fname, long int *M, int m, int n)
Definition: file_io.cpp:1323
void int_matrix_write_text(std::string &fname, int *M, int m, int n)
Definition: file_io.cpp:1717
void int_vecs_write_csv(int *v1, int *v2, int len, std::string &fname, const char *label1, const char *label2)
Definition: file_io.cpp:1207
void do_csv_file_select_cols(std::string &fname, std::string &cols_text, int verbose_level)
Definition: file_io.cpp:3932
void read_and_parse_data_file_fancy(std::string &fname, int f_casenumbers, int &nb_cases, int *&Set_sizes, long int **&Sets, char **&Ago_ascii, char **&Aut_ascii, int *&Casenumbers, int verbose_level)
Definition: file_io.cpp:2304
void int_matrix_read_csv(std::string &fname, int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1477
void read_incidence_by_row_ranks_file(std::vector< std::vector< int > > &Geos, int &m, int &n, int &r, std::string &inc_file_name, int verbose_level)
Definition: file_io.cpp:2988
void concatenate_files_into(const char *fname_in_mask, int N, std::ofstream &fp_out, const char *EOF_marker, int f_title_line, int &cnt_total, std::vector< int > &missing_idx, int verbose_level)
Definition: file_io.cpp:113
int inc_file_get_number_of_geometries(char *inc_file_name, int verbose_level)
Definition: file_io.cpp:3082
void count_number_of_solutions_in_file_by_case(std::string &fname, int *&nb_solutions, int *&case_nb, int &nb_cases, int verbose_level)
Definition: file_io.cpp:731
void copy_file_to_ostream(std::ostream &ost, const char *fname)
Definition: file_io.cpp:1140
void vector_matrix_write_csv(std::string &fname, std::vector< std::vector< int > > &V)
Definition: file_io.cpp:1369
void lint_matrix_write_csv_override_headers(std::string &fname, std::string *headers, long int *M, int m, int n)
Definition: file_io.cpp:1346
void poset_classification_read_candidates_of_orbit(std::string &fname, int orbit_at_level, long int *&candidates, int &nb_candidates, int verbose_level)
Definition: file_io.cpp:191
void write_set_to_file_as_int8(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2676
void read_column_and_parse(std::string &fname, std::string &col_label, data_structures::set_of_sets *&SoS, int verbose_level)
Definition: file_io.cpp:1633
void double_matrix_write_csv(std::string &fname, double *M, int m, int n)
Definition: file_io.cpp:1405
void do_csv_file_split_rows_modulo(std::string &fname, int split_modulo, int verbose_level)
Definition: file_io.cpp:3881
void parse_sets(int nb_cases, char **data, int f_casenumbers, int *&Set_sizes, long int **&Sets, char **&Ago_ascii, char **&Aut_ascii, int *&Casenumbers, int verbose_level)
Definition: file_io.cpp:1825
void read_set_from_file_lint(std::string &fname, long int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2465
void free_data_fancy(int nb_cases, int *Set_sizes, long int **Sets, char **Ago_ascii, char **Aut_ascii, int *Casenumbers)
Definition: file_io.cpp:2270
void read_dimacs_graph_format(std::string &fname, int &nb_V, std::vector< std::vector< int > > &Edges, int verbose_level)
Definition: file_io.cpp:1773
void int_matrix_write_csv_with_labels(std::string &fname, int *M, int m, int n, const char **column_label)
Definition: file_io.cpp:1429
void int_matrix_write_cas_friendly(std::string &fname, int *M, int m, int n)
Definition: file_io.cpp:1692
void do_csv_file_latex(std::string &fname, int f_produce_latex_header, int nb_lines_per_table, int verbose_level)
Definition: file_io.cpp:4318
void lint_matrix_read_csv(std::string &fname, long int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1558
void write_exact_cover_problem_to_file(int *Inc, int nb_rows, int nb_cols, std::string &fname)
Definition: file_io.cpp:437
void do_csv_file_concatenate(std::vector< std::string > &fname, std::string &fname_out, int verbose_level)
Definition: file_io.cpp:4263
void concatenate_files(const char *fname_in_mask, int N, const char *fname_out, const char *EOF_marker, int f_title_line, int &cnt_total, std::vector< int > missing_idx, int verbose_level)
Definition: file_io.cpp:38
void read_solution_file(std::string &fname, int *Inc, int nb_rows, int nb_cols, int *&Solutions, int &sol_length, int &nb_sol, int verbose_level)
Definition: file_io.cpp:467
void read_incidence_file(std::vector< std::vector< int > > &Geos, int &m, int &n, int &nb_flags, std::string &inc_file_name, int verbose_level)
Definition: file_io.cpp:2900
void lint_matrix_write_text(std::string &fname, long int *M, int m, int n)
Definition: file_io.cpp:1734
void write_decomposition_stack(char *fname, int m, int n, int *v, int *b, int *aij, int verbose_level)
Definition: file_io.cpp:3378
void do_csv_file_join(std::vector< std::string > &csv_file_join_fname, std::vector< std::string > &csv_file_join_identifier, int verbose_level)
Definition: file_io.cpp:4162
void write_incidence_matrix_to_file(std::string &fname, int *Inc, int m, int n, int verbose_level)
Definition: file_io.cpp:2764
void parse_line(char *line, int &len, long int *&set, char *ago_ascii, char *aut_ascii)
Definition: file_io.cpp:1893
int try_to_read_file(std::string &fname, int &nb_cases, char **&data, int verbose_level)
Definition: file_io.cpp:2037
void read_ascii_set_of_sets_constant_size(std::string &fname_ascii, int *&Sets, int &nb_sets, int &set_size, int verbose_level)
Definition: file_io.cpp:3290
void read_solutions_from_file(std::string &fname, int &nb_solutions, int *&Solutions, int solution_size, int verbose_level)
Definition: file_io.cpp:907
void do_csv_file_select_rows_and_cols(std::string &fname, std::string &rows_text, std::string &cols_text, int verbose_level)
Definition: file_io.cpp:4005
void lint_vec_write_csv(long int *v, int len, std::string &fname, const char *label)
Definition: file_io.cpp:1191
void int_matrix_read_text(std::string &fname, int *&M, int &m, int &n)
Definition: file_io.cpp:1751
void read_and_parse_data_file(std::string &fname, int &nb_cases, char **&data, long int **&sets, int *&set_sizes, int verbose_level)
Definition: file_io.cpp:2167
void read_candidates_for_one_orbit_from_file(std::string &prefix, int level, int orbit_at_level, int level_of_candidates_file, long int *S, void(*early_test_func_callback)(long int *S, int len, long int *candidates, int nb_candidates, long int *good_candidates, int &nb_good_candidates, void *data, int verbose_level), void *early_test_func_callback_data, long int *&candidates, int &nb_candidates, int verbose_level)
Definition: file_io.cpp:254
void lint_matrix_write_csv_with_labels(std::string &fname, long int *M, int m, int n, const char **column_label)
Definition: file_io.cpp:1453
void lint_vec_array_write_csv(int nb_vecs, long int **Vec, int len, std::string &fname, const char **column_label)
Definition: file_io.cpp:1270
void save_cumulative_data(std::vector< std::vector< int > > &Cumulative_data, std::string &fname, int verbose_level)
Definition: file_io.cpp:4605
void read_solutions_and_tally(std::string &fname, int sz, int verbose_level)
Definition: file_io.cpp:4397
int number_of_vertices_in_colored_graph(std::string &fname, int verbose_level)
Definition: file_io.cpp:3823
void save_cumulative_ago(std::vector< long int > &Cumulative_Ago, std::string &fname, int verbose_level)
Definition: file_io.cpp:4561
void count_number_of_solutions_in_file(std::string &fname, int &nb_solutions, int verbose_level)
Definition: file_io.cpp:671
void write_set_to_file_as_int4(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2629
void double_matrix_read_csv(std::string &fname, double *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1595
void read_numbers_from_file(std::string &fname, int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:3241
void create_file(create_file_description *Descr, int verbose_level)
Definition: file_io.cpp:3417
void write_characteristic_matrix(std::string &fname, long int *data, int nb_rows, int data_sz, int nb_cols, int verbose_level)
Definition: file_io.cpp:4644
void do_csv_file_extract_column_to_txt(std::string &csv_fname, std::string &col_label, int verbose_level)
Definition: file_io.cpp:4066
void create_files(create_file_description *Descr, int verbose_level)
Definition: file_io.cpp:3575
void read_incidence_matrix_from_inc_file(int *&M, int &m, int &n, std::string &inc_file_name, int inc_file_idx, int verbose_level)
Definition: file_io.cpp:2802
void read_solutions_from_file_size_is_known(std::string &fname, std::vector< std::vector< int > > &Solutions, int solution_size, int verbose_level)
Definition: file_io.cpp:981
void read_set_from_file(std::string &fname, long int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2374
void write_set_to_file(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2434
int find_orbit_index_in_data_file(std::string &prefix, int level_of_candidates_file, long int *starter, int verbose_level)
Definition: file_io.cpp:345
void read_solutions_from_file_by_case(std::string &fname, int *nb_solutions, int *case_nb, int nb_cases, int **&Solutions, int solution_size, int verbose_level)
Definition: file_io.cpp:1037
void read_set_from_file_int8(std::string &fname, long int *&the_set, int &set_size, int verbose_level)
Definition: file_io.cpp:2586
void head(std::ostream &ost, int f_book, int f_title, const char *title, const char *author, int f_toc, int f_landscape, int f_12pt, int f_enlarged_page, int f_pagenumbers, const char *extras_for_preamble)
#define MY_OWN_BUFSIZE
Definition: file_io.cpp:26
#define BUFSIZE_READ_SOLUTION_FILE
Definition: file_io.cpp:465
#define READ_INCIDENCE_BUFSIZE
Definition: file_io.cpp:2800
#define Lint_vec_copy(A, B, C)
Definition: foundations.h:694
#define Int_vec_scan(A, B, C)
Definition: foundations.h:716
#define NEW_pchar(n)
Definition: foundations.h:635
#define FREE_pchar(p)
Definition: foundations.h:648
#define NEW_plint(n)
Definition: foundations.h:629
#define MINIMUM(x, y)
Definition: foundations.h:216
#define FREE_int(p)
Definition: foundations.h:640
#define Int_vec_zero(A, B)
Definition: foundations.h:713
#define Int_vec_print_fully(A, B, C)
Definition: foundations.h:687
unsigned char uchar
Definition: foundations.h:204
#define Lint_vec_scan(A, B, C)
Definition: foundations.h:717
#define NEW_pint(n)
Definition: foundations.h:627
#define FREE_plint(p)
Definition: foundations.h:643
#define NEW_char(n)
Definition: foundations.h:632
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define NEW_int(n)
Definition: foundations.h:625
#define Int_vec_print_integer_matrix_width(A, B, C, D, E, F)
Definition: foundations.h:691
int int_4
Definition: foundations.h:181
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define FREE_char(p)
Definition: foundations.h:646
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
#define MAXIMUM(x, y)
Definition: foundations.h:217
long int_8
Definition: foundations.h:182
#define MY_BUFSIZE
the orbiter library for the classification of combinatorial objects