1 | #include "base/bdmbase.h" |
---|
2 | #include "base/user_info.h" |
---|
3 | #include "generator.h" |
---|
4 | #include "additive_generator.h" |
---|
5 | #include "size_generator.h" |
---|
6 | #include "square_mat_point.h" |
---|
7 | #include <iostream> |
---|
8 | #include <iomanip> |
---|
9 | #include <memory> |
---|
10 | #include <stdlib.h> |
---|
11 | |
---|
12 | using namespace std; |
---|
13 | using namespace bdm; |
---|
14 | using namespace itpp; |
---|
15 | |
---|
16 | UIREGISTER ( size_generator ); |
---|
17 | UIREGISTER ( additive_generator ); |
---|
18 | UIREGISTER ( square_mat_point ); |
---|
19 | |
---|
20 | const char *generator_file_name = "generator.cfg"; |
---|
21 | const char *agenda_file_name = "agenda.cfg"; |
---|
22 | int agenda_length = 10; |
---|
23 | |
---|
24 | int main ( int argc, char const *argv[] ) { |
---|
25 | RNG_randomize(); |
---|
26 | |
---|
27 | bool unknown = false; |
---|
28 | int update_next = 0; // 1 generator file, 2 agenda file, 3 agenda length |
---|
29 | const char **param = argv + 1; |
---|
30 | while ( *param && !unknown ) { |
---|
31 | if ( update_next ) { |
---|
32 | if ( update_next == 1 ) { |
---|
33 | generator_file_name = *param; |
---|
34 | } else if ( update_next == 2 ) { |
---|
35 | agenda_file_name = *param; |
---|
36 | } else { |
---|
37 | int length = atoi ( *param ); |
---|
38 | if ( length > 0 ) { |
---|
39 | agenda_length = length; |
---|
40 | } else { |
---|
41 | cerr << "invalid agenda length value ignored" << endl; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | update_next = 0; |
---|
46 | } else { |
---|
47 | if ( !strcmp ( *param, "-a" ) ) { |
---|
48 | update_next = 2; |
---|
49 | } else if ( !strcmp ( *param, "-g" ) ) { |
---|
50 | update_next = 1; |
---|
51 | } else if ( !strcmp ( *param, "-l" ) ) { |
---|
52 | update_next = 3; |
---|
53 | } else { |
---|
54 | unknown = true; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | ++param; |
---|
59 | } |
---|
60 | |
---|
61 | if ( unknown || update_next ) { |
---|
62 | cerr << "usage: " << argv[0] << " [ -g generator.cfg ] [ -a agenda_output.cfg ] [ -l agenda_length ]" << endl; |
---|
63 | } else { |
---|
64 | Array<square_mat_point *> mag ( agenda_length ); |
---|
65 | |
---|
66 | UIFile gspec ( generator_file_name ); |
---|
67 | auto_ptr<generator> gen ( UI::build<generator> ( gspec, "generator", UI::compulsory ) ); |
---|
68 | for ( int i = 0; i < agenda_length; ++i ) { |
---|
69 | mat m = gen->next(); |
---|
70 | square_mat_point *p = new square_mat_point(); |
---|
71 | p->set_parameters ( m, randu ( m.rows() ), randu() ); |
---|
72 | mag ( i ) = p; |
---|
73 | } |
---|
74 | |
---|
75 | UIFile fag; |
---|
76 | UI::save ( mag, fag, "agenda" ); |
---|
77 | fag.save ( agenda_file_name ); |
---|
78 | |
---|
79 | for ( int i = 0; i < agenda_length; ++i ) { |
---|
80 | square_mat_point *p = mag ( i ); |
---|
81 | mag ( i ) = 0; |
---|
82 | delete p; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|