File Coverage

blib/lib/Sim/OPT/Sim.pm
Criterion Covered Total %
statement 69 223 30.9
branch 0 24 0.0
condition n/a
subroutine 23 24 95.8
pod 0 1 0.0
total 92 272 33.8


line stmt bran cond sub pod time code
1             package Sim::OPT::Sim;
2             # Copyright (C) 2008-2014 by Gian Luca Brunetti and Politecnico di Milano.
3             # This is the module Sim::OPT::Sim of Sim::OPT, a program for detailed metadesign managing parametric explorations through the ESP-r building performance simulation platform and performing optimization by block coordinate descent.
4             # This is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
5              
6 1     1   9 use v5.14;
  1         3  
  1         52  
7             # use v5.20;
8 1     1   7 use Exporter;
  1         2  
  1         81  
9 1     1   5 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
  1         1  
  1         76  
10 1     1   3 use Math::Trig;
  1         1  
  1         144  
11 1     1   4 use Math::Round;
  1         1  
  1         39  
12 1     1   3 use List::Util qw[ min max reduce shuffle];
  1         2  
  1         62  
13 1     1   6 use List::MoreUtils qw(uniq);
  1         1  
  1         8  
14 1     1   354 use List::AllUtils qw(sum);
  1         2  
  1         45  
15 1     1   4 use Statistics::Basic qw(:all);
  1         1  
  1         6  
16 1     1   534 use Set::Intersection;
  1         3  
  1         64  
17 1     1   6 use List::Compare;
  1         2  
  1         26  
18 1     1   5 use IO::Tee;
  1         2  
  1         48  
19 1     1   6 use Data::Dumper;
  1         2  
  1         61  
20             #$Data::Dumper::Indent = 0;
21             #$Data::Dumper::Useqq = 1;
22             #$Data::Dumper::Terse = 1;
23 1     1   4 use Data::Dump qw(dump);
  1         1  
  1         44  
24 1     1   4 use feature 'say';
  1         2  
  1         92  
25             #use feature qw(postderef);
26             #no warnings qw(experimental::postderef);
27             #use Sub::Signatures;
28             #no warnings qw(Sub::Signatures);
29             #no strict 'refs';
30 1     1   4 use Sim::OPT;
  1         1  
  1         25  
31 1     1   4 use Sim::OPT::Morph;
  1         1  
  1         23  
32 1     1   470 use Sim::OPT::Retrieve;
  1         3  
  1         69  
33 1     1   6 use Sim::OPT::Report;
  1         2  
  1         36  
34 1     1   4 use Sim::OPT::Descend;
  1         1  
  1         35  
35 1     1   6 use Sim::OPT::Takechance;
  1         1  
  1         57  
36 1     1   7 no strict;
  1         2  
  1         41  
37 1     1   5 no warnings;
  1         1  
  1         1585  
38              
39             @ISA = qw(Exporter); # our @adamkISA = qw(Exporter);
40             #%EXPORT_TAGS = ( DEFAULT => [qw( &opt &prepare )]); # our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
41             #@EXPORT_OK = qw(); # our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
42              
43             @EXPORT = qw( sim ); # our @EXPORT = qw( );
44              
45             $VERSION = '0.40.0'; # our $VERSION = '';
46              
47              
48             #########################################################################################
49             # HERE FOLLOWS THE CONTENT OF "Sim.pm", Sim::OPT::Sim
50             ##############################################################################
51              
52             # HERE FOLLOWS THE "sim" FUNCTION, CALLED FROM THE MAIN PROGRAM FILE.
53             # IT LAUCHES SIMULATIONS AND ALSO RETRIEVES RESULTS.
54             # THE TWO OPERATIONS ARE CONTROLLED SEPARATELY
55             # FROM THE OPT CONFIGURATION FILE.
56              
57             #____________________________________________________________________________
58             # Activate or deactivate the following function calls depending from your needs
59              
60             sub sim # This function launch the simulations in ESP-r
61             {
62 0     0 0   my $swap = shift; #say $tee "swapINSIM: " . dump($swap);
63 0           my %dat = %$swap;
64 0           my @instances = @{ $dat{instances} }; #say "scalar(\@instances): " . scalar(@instances);
  0            
65 0           my $countcase = $dat{countcase}; #say "dump(\$countcase): " . dump($countcase); # IT WILL BE SHADOWED. CUT ZZZ
66 0           my $countblock = $dat{countblock}; #say "dump(\$countblock): " . dump($countblock); # IT WILL BE SHADOWED. CUT ZZZ
67 0           my %dirfiles = %{ $dat{dirfiles} }; #say "dump(\%dirfiles): " . dump(%dirfiles);
  0            
68            
69 0           $configfile = $main::configfile; #say "dump(\$configfile): " . dump($configfile);
70 0           @sweeps = @main::sweeps; #say "dump(\@sweeps): " . dump(@sweeps);
71 0           @varinumbers = @main::varinumbers; #say "dump(\@varinumbers): " . dump(@varinumbers);
72 0           @mediumiters = @main::mediumiters;
73 0           @rootnames = @main::rootnames; #say "dump(\@rootnames): " . dump(@rootnames);
74 0           %vals = %main::vals; #say "dump(\%vals): " . dump(%vals);
75            
76 0           $mypath = $main::mypath; #say $tee "dumpINSIM(\$mypath): " . dump($mypath);
77 0           $exeonfiles = $main::exeonfiles; #say $tee "dumpINSIM(\$exeonfiles): " . dump($exeonfiles);
78 0           $generatechance = $main::generatechance;
79 0           $file = $main::file;
80 0           $preventsim = $main::preventsim;
81 0           $fileconfig = $main::fileconfig; #say $tee "dumpINSIM(\$fileconfig): " . dump($fileconfig); # NOW GLOBAL. TO MAKE IT PRIVATE, FIX PASSING OF PARAMETERS IN CONTRAINTS PROPAGATION SECONDARY SUBROUTINES
82 0           $outfile = $main::outfile;
83 0           $toshell = $main::toshell;
84 0           $report = $main::report;
85 0           $simnetwork = $main::simnetwork;
86            
87 0           $tee = new IO::Tee(\*STDOUT, ">>$toshell"); # GLOBAL ZZZ
88            
89 0 0         open ( OUTFILE, ">>$outfile" ) or die "Can't open $outfile: $!";
90 0 0         open ( TOSHELL, ">>$toshell" ) or die "Can't open $toshell: $!";
91 0           say "\nNow in Sim::OPT::Sim.\n";
92 0           say TOSHELL "\n#Now in Sim::OPT::Sim.\n";
93            
94 0           %dowhat = %main::dowhat;
95              
96 0           @themereports = @main::themereports; #say "dumpINSIM(\@themereports): " . dump(@themereports);
97 0           @simtitles = @main::simtitles; #say "dumpINSIM(\@simtitles): " . dump(@simtitles);
98 0           @reporttitles = @main::reporttitles;
99 0           @simdata = @main::simdata;
100 0           @retrievedata = @main::retrievedata;
101 0           @keepcolumns = @main::keepcolumns;
102 0           @weights = @main::weights;
103 0           @weightsaim = @main::weightsaim;
104 0           @varthemes_report = @main::varthemes_report;
105 0           @varthemes_variations = @vmain::arthemes_variations;
106 0           @varthemes_steps = @main::varthemes_steps;
107 0           @rankdata = @main::rankdata; # CUT ZZZ
108 0           @rankcolumn = @main::rankcolumn;
109 0           @reporttempsdata = @main::reporttempsdata;
110 0           @reportcomfortdata = @main::reportcomfortdata;
111 0           @reportradiationenteringdata = @main::reportradiationenteringdata;
112 0           @report_loadsortemps = @main::report_loadsortemps;
113 0           @files_to_filter = @main::files_to_filter;
114 0           @filter_reports = @main::filter_reports;
115 0           @base_columns = @main::base_columns;
116 0           @maketabledata = @main::maketabledata;
117 0           @filter_columns = @main::filter_columns;
118            
119 0           my @simcases = @{ $dirfiles{simcases} }; #say "dump(\@simcases): " . dump(@simcases);
  0            
120 0           my @simstruct = @{ $dirfiles{simstruct} }; #say "dump(\@simstruct): " . dump(@simstruct);
  0            
121 0           my @morphcases = @{ $dirfiles{morphcases} };
  0            
122 0           my @morphstruct = @{ $dirfiles{morphstruct} };
  0            
123 0           my @retcases = @{ $dirfiles{retcases} };
  0            
124 0           my @retstruct = @{ $dirfiles{retstruct} };
  0            
125 0           my @repcases = @{ $dirfiles{repcases} };
  0            
126 0           my @repstruct = @{ $dirfiles{repstruct} };
  0            
127 0           my @mergecases = @{ $dirfiles{mergecases} };
  0            
128 0           my @mergestruct = @{ $dirfiles{mergestruct} };
  0            
129 0           my @descendcases = @{ $dirfiles{descendcases} };
  0            
130 0           my @descendstruct = @{ $dirfiles{descendstruct} };
  0            
131            
132 0           my $morphlist = $dirfiles{morphlist}; #say "dump(\$dat{morphlist}): " . dump($dat{morphlist});
133 0           my $morphblock = $dirfiles{morphblock};
134 0           my $simlist = $dirfiles{simlist}; #say "dump(\$simlist): " . dump($simlist);
135 0           my $simblock = $dirfiles{simblock};
136 0           my $retlist = $dirfiles{retlist};
137 0           my $retblock = $dirfiles{retblock};
138 0           my $replist = $dirfiles{replist};
139 0           my $repblock = $dirfiles{repblock};
140 0           my $descendlist = $dirfiles{descendlist};
141 0           my $descendblock = $dirfiles{descendblock};
142            
143             #my $getpars = shift;
144             #eval( $getpars );
145              
146             #if ( fileno (MORPHLIST)
147              
148 0           my @container;
149              
150 0           foreach my $instance (@instances)
151             {
152 0           my %d = %{$instance};
  0            
153 0           my $countcase = $d{countcase}; #say TOSHELL "dump(\$countcase): " . dump($countcase);
154 0           my $countblock = $d{countblock}; #say TOSHELL "dump(\$countblock): " . dump($countblock);
155 0           my @miditers = @{ $d{miditers} }; #say TOSHELL "dump(\@miditers): " . dump(@miditers);
  0            
156 0           my @winneritems = @{ $d{winneritems} }; #say TOSHELL "dumpIN( \@winneritems) " . dump(@winneritems);
  0            
157 0           my $countvar = $d{countvar}; #say TOSHELL "dump(\$countvar): " . dump($countvar);
158 0           my $countstep = $d{countstep}; #say TOSHELL "dump(\$countstep): " . dump($countstep);
159 0           my $to = $d{to}; #say TOSHELL "dump(\$to): " . dump($to);
160 0           my $origin = $d{origin}; #say TOSHELL "dump(\$origin): " . dump($origin);
161 0           my @uplift = @{ $d{uplift} }; #say TOSHELL "dump(\@uplift): " . dump(@uplift);
  0            
162             #eval($getparshere);
163            
164 0           my $rootname = Sim::OPT::getrootname(\@rootnames, $countcase); #say TOSHELL "dump(\$rootname): " . dump($rootname);
165 0           my @blockelts = Sim::OPT::getblockelts(\@sweeps, $countcase, $countblock); #say TOSHELL "dumpIN( \@blockelts) " . dump(@blockelts);
166 0           my @blocks = Sim::OPT::getblocks(\@sweeps, $countcase); #say TOSHELL "dumpIN( \@blocks) " . dump(@blocks);
167 0           my $toitem = Sim::OPT::getitem(\@winneritems, $countcase, $countblock); #say TOSHELL "dump(\$toitem): " . dump($toitem);
168 0           my $from = Sim::OPT::getline($toitem); #say TOSHELL "dumpIN(\$from): " . dump($from);
169 0           my %varnums = Sim::OPT::getcase(\@varinumbers, $countcase); #say TOSHELL "dumpIN---(\%varnums): " . dump(%varnums);
170 0           my %mids = Sim::OPT::getcase(\@miditers, $countcase); #say TOSHELL "dumpIN---(\%mids): " . dump(%mids);
171             #eval($getfly);
172            
173 0           my $stepsvar = Sim::OPT::getstepsvar($countvar, $countcase, \@varinumbers); #say TOSHELL "dump(\$stepsvar): " . dump($stepsvar);
174 0           my $varnumber = $countvar; #say TOSHELL "dump---(\$varnumber): " . dump($varnumber) . "\n\n"; # LEGACY VARIABLE
175            
176 0           my @ress;
177             my @flfs;
178 0           my $countdir = 0;
179            
180             #my $prov = $to;
181             #my $prov =~ s/$mypath\/$file//;
182             #my $prov =~ s/_$//;
183             #my $prov =~ s/_-*$//;
184             #if ( not ( $to ~~ @{ $simcases[$countcase] } ) )
185             #{
186             # push ( @simcases, $to ); say TOSHELL "simcases: " . dump(@simcases);
187             # print SIMLIST "$to\n";
188             #}
189              
190 0           my $simelt = $to;
191 0           my $countsim = 0;
192 0           foreach my $date_to_sim (@simtitles)
193             {
194 0           my $simdataref = $simdata[$countsim];
195 0           my @simdata = @{$simdataref};
  0            
196 0           my $resfile = "$simelt-$date_to_sim.res";
197 0           my $flfile = "$simelt-$date_to_sim.fl";
198 0           push (@ress, $resfile); # ERASE
199 0           push (@flfs, $flfile); # ERASE
200            
201             #if ( fileno (SIMLIST) )
202             #if (not (-e $simlist ) )
203             #{
204             # if ( $countblock == 0 )
205             # {
206 0 0         open ( SIMLIST, ">>$simlist") or die;
207             # }
208             # else
209             # {
210             # open ( SIMLIST, ">>$simlist") or die;
211             # }
212             #}
213            
214             #if ( fileno (SIMBLOCK) )
215 0 0         if (not (-e $simblock ) )
216             {
217 0 0         if ( $countblock == 0 )
218             {
219 0           open ( SIMBLOCK, ">>$simblock"); # or die;
220             }
221             else
222             {
223 0           open ( SIMBLOCK, ">>$simblock"); # or die;
224             }
225             }
226            
227             #say "INSIM1\$countcase : " . dump($countcase);
228             #say "INSIM1\@rootnames : " . dump(@rootnames);
229             #say "INSIM1\$countblock : " . dump($countblock);
230             #say "INSIM1\@sweeps : " . dump(@sweeps);
231             #say "INSIM1\@varinumbers : " . dump(@varinumbers);
232             #say "INSIM1\@miditers : " . dump(@miditers);
233             #say "INSIM1\@winneritems : " . dump(@winneritems);
234             #say "INSIM1\@morphcases : " . dump(@morphcases);
235             #say "INSIM1\@morphstruct : " . dump(@morphstruct);
236            
237 0           push ( @{ $simstruct[$countcase][$countblock] }, $resfile );
  0            
238 0           print SIMBLOCK "$resfile\n";
239            
240 0 0         if ( not ( $resfile ~~ @simcases ) )
241             {
242 0           push ( @simcases, $resfile );
243 0           print SIMLIST "$resfile\n";
244            
245 0 0         unless ( $preventsim eq "y" )
246             {
247 0 0         if ( not ( -e $resfile ) )
248             {
249 0 0         if ( $simnetwork eq "n" )
250             {
251 0           my $printthis =
252             "bps -file $simelt/cfg/$fileconfig -mode script<
253              
254             c
255             $resfile
256             $simdata[0 + (4*$countsim)]
257             $simdata[1 + (4*$countsim)]
258             $simdata[2 + (4*$countsim)]
259             $simdata[3 + (4*$countsim)]
260             s
261             $simnetwork
262             Results for $simelt-$date_to_sim
263             y
264             y
265             -
266             -
267             -
268             -
269             -
270             -
271             -
272             XXX
273             ";
274 0 0         if ($exeonfiles eq "y")
275             {
276 0           print `$printthis`;
277             }
278 0           print TOSHELL "
279             #Simulating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
280             $printthis
281             ";
282             }
283            
284 0 0         if ( $simnetwork eq "y" )
285             {
286 0           my $printthis =
287             "bps -file $simelt/cfg/$fileconfig -mode script<
288              
289             c
290             $resfile
291             $flfile
292             $simdata[0 + (4*$countsim)]
293             $simdata[1 + (4*$countsim)]
294             $simdata[2 + (4*$countsim)]
295             $simdata[3 + (4*$countsim)]
296             s
297             $simnetwork
298             Results for $simelt-$dates_to_sim
299             y
300             y
301             -
302             -
303             -
304             -
305             -
306             -
307             -
308             XXX
309             ";
310 0 0         if ($exeonfiles eq "y")
311             {
312 0           print `$printthis`;
313             }
314 0           print TOSHELL "
315             #Simulating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.\
316             $printthis
317             \n";
318 0           print OUTFILE "TWO, $resfile\n";
319             }
320             }
321             }
322             }
323 0           $countsim++;
324             }
325 0           $countdir++;
326             }
327 0           close SIMLIST;
328 0           close SIMBLOCK;
329 0           return ( \@simcases, \@simstruct );
330 0           close TOSHELL;
331 0           close OUTFILE;
332             } # END SUB sim;
333              
334             # END OF THE CONTENT OF Sim::OPT::Sim
335             ##############################################################################
336             ##############################################################################
337            
338             1;
339