1 # {{{ include statements
3 start include statements
4 use model
::problem
::record
::init_option
;
7 # }}} include statements
13 if ( defined $self -> options
) {
14 foreach my $option ( @
{$self -> options
} ){
15 $option -> restore_init
;
23 # {{{ set_random_inits
24 start set_random_inits
26 if ( defined $self -> options
and not $self -> {'same'} and
27 not $self -> {'fix'} ) {
28 foreach my $option ( @
{$self -> options
} ){
29 $option -> set_random_init
( degree
=> $degree );
34 # }}} set_random_inits
39 if ( defined $self -> options
) {
40 foreach my $option ( @
{$self -> options
} ){
41 if( $option -> can
( 'store_init' ) ){
42 $option -> store_init
;
55 model
::problem
::record
::init_option
->
56 new
( option_string
=> $option_string,
57 on_diagonal
=> $on_diagonal,
61 push( @
{$self -> {'options'}}, $opt_obj ) if( $opt_obj );
71 my @class_names = split('::',ref($self));
72 my $fname = uc(pop(@class_names));
73 $formatted[0] = "\$".$fname." ";
76 my $otype = $self -> {'type'};
77 my $same = $self -> {'same'};
78 my $fix = $self -> {'fix'};
79 my $size = $self -> {'size'};
81 if ( defined $otype ) {
82 $formatted[0] = $formatted[0]." $otype";
83 if ( defined $size ) {
84 $formatted[0] = $formatted[0]."($size)";
86 if ( $self -> sd
() ) {
87 $formatted[0] = $formatted[0]." SD";
89 if ( $self -> corr
() ) {
90 $formatted[0] = $formatted[0]." CORRELATION";
93 $formatted[0] = $formatted[0]." FIX";
96 $formatted[0] = $formatted[0]." SAME\n";
100 $len = length $formatted[0];
101 if ( defined $self -> {'options'} ) {
102 foreach my $option ( @
{$self -> {'options'}} ) {
104 $formatted[0] = $formatted[0].' '.
105 $option -> _format_option
( len
=> $len)."\n";
108 $formatted[0] = $formatted[0]."\n";
111 if ( defined $self -> {'comment'} ) {
112 push( @formatted, @
{$self -> {'comment'}} );
113 $formatted[$#formatted] = $formatted[$#formatted];
130 my ( $any_fixed, $any_sd, $any_corr, $block_sd, $block_corr, $block_fixed ) = ( 0, 0, 0, 0, 0, 0 );
131 if ( defined $self -> {'record_arr'} ) {
132 my ( $digit, $comment, $fixed, $sd, $corr ) = ( undef, undef, 0, 0, 0 );
133 for ( @
{$self -> {'record_arr'}} ) {
138 next unless( length($_) > 0 );
140 # This is a comment row
141 push( @
{$self -> {'comment'}}, $_ . "\n" );
143 # Make sure that the labels and units are in one string
145 # Get rid of unwanted spaces
150 my ( $line, $line_comment ) = split( ";", $_, 2 );
152 $any_fixed++ if /FIX/;
154 $any_sd++ if /STANDARD/;
155 $any_corr++ if /CORRELATION/;
156 $self -> {'type'} = 'DIAGONAL' if /DIAG\w*/;
157 $self -> {'type'} = 'BLOCK' if /BLOCK/;
158 $self -> {'size'} = $2
159 if s/^\s*(BLOCK|DIAG\w*)\s*\((\d+)\)\s*//;
161 # If we have a "BLOCK SAME" the regexp above wont remove
162 # 'BLOCK' and we do it here:
165 $self -> {'same'} = 1 if s/SAME//;
167 while( s/\(([\w ]*)\)// ) {
168 # We should (if the file is correctly formatted) only
169 # find parentheses if the record is NOT of a BLOCK()
170 # type. In this code we find all records code like
171 # (init options) or (options init)
172 my @opt = split( " ",$1 );
173 my ( $digit, $fixed, $sd, $corr ) = ( undef, 0, 0, 0 );
174 for ( my $i = 0; $i <= $#opt; $i++ ) {
175 if ( $opt[$i] =~ /\d+/ ) {
177 } elsif ( $opt[$i] =~ /FIX/ ) {
179 } elsif ( $opt[$i] =~ /SD/ or $opt[$i] =~ /STANDARD/ ) {
181 } elsif ( $opt[$i] =~ /CORRELATION/ ) {
184 'debug' -> die( message
=> "init_record_subs -> _read_options: Unknown option $_" );
187 if ( defined $digit ) {
188 $self -> _add_option
( option_string
=> $digit,
195 @row = split( " ", $_ );
196 for ( my $i = 0; $i <= $#row; $i++ ) {
197 # In this code we find all records coded like: init options init options ...
200 if ( defined $digit ) {
201 push( @digits, $digit );
202 push( @fix , $fixed );
204 push( @corrs , $corr );
205 push( @comments, $comment );
207 ( $fixed, $sd, $corr ) = ( 0, 0, 0 );
209 } elsif ( /FIX/ and not $fixed ) {
211 } elsif ( /SD/ or /STANDARD/ ) {
213 } elsif ( /CORRELATION/ ) {
216 'debug' -> die( message
=> "init_record_subs -> _read_options: Unknown option $_" );
218 $comment = $i == $#row ?
$line_comment : undef;
222 if ( defined $digit ) {
223 push( @digits, $digit );
224 push( @fix , $fixed );
226 push( @corrs , $corr );
227 push( @comments, $comment );
231 if( $self -> {'type'} eq 'BLOCK' ) {
232 $self -> fix
(1) if ($any_fixed);
233 $self -> sd
(1) if ($any_sd);
234 $self -> corr
(1) if ($any_corr);
238 for ( my $i = 0; $i <= $#digits; $i++ ) {
239 my $com_str = defined $comments[$i] ?
';'.$comments[$i] : '';
240 if ( $self -> {'type'} eq 'BLOCK' ) {
241 if ( $i+1 == $row*($row+1)/2 ) {
243 $self -> _add_option
( option_string
=> $digits[$i].$com_str,
246 $self -> _add_option
( option_string
=> $digits[$i].$com_str,
250 $self -> _add_option
( option_string
=> $digits[$i].$com_str,
258 # if ( defined $self -> {'record_arr'} ) {
259 # for ( @{$self -> {'record_arr'}} ) {
261 # next unless( length($_) > 0 );
262 # # Split inits and labels/units
263 # my ( $line, $comment ) = split( ";", $_, 2 );
264 # # Split the init string to see if we have more than one init.
265 # @row = split( " ",$line );
267 # # If we only have one init, send the whole row to option
268 # $self -> _add_option( option_string => $_ );
269 # print "LINE: $_\n";
270 # print "adding one init\n";
271 # # if ( $self -> {'debug'} );
273 # # If we have more than one init, send one init at a time to option
274 # print "LINE: $_\n";
275 # print "adding ",$#row+1," inits\n";
276 # # if ( $self -> {'debug'} );
278 # $self -> _add_option( option_string => $_ );