Line data Source code
1 : /*******************************************************************************
2 : * *
3 : * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles *
4 : * (S)tochastiques *
5 : * *
6 : * Copyright (C) 2009-2012 LSV & LACL *
7 : * Authors: Paolo Ballarini BenoƮt Barbot & Hilal Djafri *
8 : * Website: http://www.lsv.ens-cachan.fr/Software/cosmos *
9 : * *
10 : * This program is free software; you can redistribute it and/or modify *
11 : * it under the terms of the GNU General Public License as published by *
12 : * the Free Software Foundation; either version 3 of the License, or *
13 : * (at your option) any later version. *
14 : * *
15 : * This program is distributed in the hope that it will be useful, *
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 : * GNU General Public License for more details. *
19 : * *
20 : * You should have received a copy of the GNU General Public License along *
21 : * with this program; if not, write to the Free Software Foundation, Inc., *
22 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
23 : * file result.cpp created by Benoit Barbot on 22/05/12. *
24 : *******************************************************************************
25 : */
26 :
27 : #include <sys/stat.h>
28 : #include <math.h>
29 :
30 : #include <sstream>
31 : #include <iostream>
32 : #include <cstdlib>
33 : #include <iomanip>
34 : #include <tuple>
35 : #include <list>
36 : #include <ctime>
37 : #include <ratio>
38 : #include <chrono>
39 :
40 : #include "result.hpp"
41 : #include "HaslFormula.hpp"
42 : #include "server.hpp"
43 :
44 : using namespace std;
45 :
46 31 : result::result() : MeanM2(P.nbAlgebraic,P.nbQualitatif),HaslResult(P.HaslFormulasname.size()) {
47 :
48 31 : if(P.chernoff){ //Compute Chernoff-Hoeffding bounds
49 0 : HaslFormulasTop::computeChernoff();
50 : }
51 : //Set the confidence level to all Hasl formula
52 31 : for (auto &it : P.HaslFormulas)it->setLevel(P.Level);
53 :
54 31 : gnuplotstream = NULL;
55 31 : lastprint = chrono::system_clock::now();
56 31 : lastdraw = chrono::system_clock::now();
57 :
58 :
59 31 : Progress = 0;
60 31 : ProgressArray = vector<double>(P.HaslFormulasname.size()); //relative error
61 :
62 31 : endline = 0;
63 :
64 31 : if (P.dataoutput.compare("")) {
65 1 : if (P.verbose > 0)cout << "Output Data to: " << P.dataoutput << endl;
66 1 : outdatastream.open(P.dataoutput.c_str(), fstream::out);
67 1 : outdatastream.precision(15);
68 1 : outdatastream << "\"Number of trajectory\" \"Number of successfull trajectory\"";
69 3 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
70 4 : string iname = P.HaslFormulasname[i];
71 2 : if (!iname.compare("")) {
72 1 : outdatastream << " \"Mean[" << i << "]\" \"Confidence interval Width[" << i << "]\" \"Confidence interval lower bound [" << i << "]\" \"Confidence interval upper bound [" << i << "]\"";
73 : } else {
74 1 : outdatastream << " \"Mean[" << iname << "]\" \"Confidence interval Width[" << iname << "]\" \"Confidence interval lower bound [" << iname << "]\" \"Confidence interval upper bound [" << iname << "]\"";
75 : }
76 : }
77 1 : outdatastream << endl;
78 : }
79 31 : if (!P.gnuplotDriver.empty()) {
80 0 : if (system("which gnuplot > /dev/null") != 0) {
81 0 : cerr << "gnuplot not found" << endl;
82 0 : P.gnuplotDriver = "";
83 : } else {
84 0 : string gnuplotcmd = "(tee " + P.tmpPath + "/gnuplotscript.gp) | gnuplot";
85 0 : gnuplotstream = popen(gnuplotcmd.c_str(), "w");
86 0 : if (P.verbose > 2)cout << "Gnuplot opened" << endl;
87 0 : if (gnuplotstream == NULL) {
88 0 : perror("Fail to lauch gnuplot");
89 0 : exit(EXIT_FAILURE);
90 : }
91 0 : if (P.alligatorMode) {
92 0 : P.gnuplotDriver="png font 'arial,12' size 1000, 400";
93 : }
94 0 : gnuplotextenstion = P.gnuplotDriver.substr(0,P.gnuplotDriver.find(' '));
95 0 : string str = "set terminal "+P.gnuplotDriver +"\n";
96 0 : fputs(str.c_str(), gnuplotstream);
97 0 : fputs("set grid lt 4 lc rgb '#909090'\n", gnuplotstream);
98 0 : fputs("set style fill solid 0.2 noborder\n", gnuplotstream);
99 0 : flushgnuplot();
100 : }
101 : }
102 :
103 31 : maxformulaname = 11;
104 245 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++)
105 214 : maxformulaname = max(maxformulaname, P.HaslFormulasname[i].size());
106 :
107 31 : start = chrono::system_clock::now();
108 31 : lastprint = chrono::system_clock::now();
109 31 : }
110 :
111 31 : void result::close_gnuplot() {
112 31 : if (gnuplotstream != NULL) {
113 0 : fputs("exit\n", gnuplotstream);
114 0 : flushgnuplot();
115 0 : pclose(gnuplotstream);
116 : }
117 31 : }
118 :
119 233 : void result::addBatch(BatchR &batchResult) {
120 233 : MeanM2.unionR(batchResult);
121 233 : Progress = 1.0;
122 2212 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
123 1979 : HaslResult[i] = P.HaslFormulas[i]->eval(MeanM2);
124 1979 : if (P.BoundedContinuous) {
125 2 : HaslResult[i].low *= (1 - P.epsilon);
126 : }
127 :
128 1979 : double rewidth = 0.0;
129 1979 : if (P.HaslFormulas[i]->TypeOp != HYPOTHESIS) {
130 1979 : if (P.relative) {
131 18 : if (HaslResult[i].mean == 0) { rewidth=P.Width; } // This is a kludge (a choice should be made for relative width if the mean is zero. Maybe as an argument ?
132 18 : else { rewidth = fabs((HaslResult[i].width() / HaslResult[i].mean)); }
133 1961 : } else rewidth = HaslResult[i].width();
134 1979 : ProgressArray[i] = pow(rewidth / P.Width, -2.0); //make it linear
135 : } else {
136 0 : ProgressArray[i] = (log(HaslResult[i].conf / (1 - HaslResult[i].conf))) / (log(P.Level / (1 - P.Level))); //make it linear
137 : }
138 :
139 1979 : Progress = min(Progress, ProgressArray[i]);
140 : }
141 : //Progress = min(Progress,(double)MeanM2->I / (double)P.MaxRuns);
142 233 : if (outdatastream.is_open())outputData();
143 233 : }
144 :
145 267 : bool result::continueSim() {
146 267 : if (MeanM2.I >= P.MaxRuns)return false;
147 244 : if (!P.sequential)return true;
148 244 : if (P.Width == 0)return true;
149 :
150 244 : return (Progress < 1.0);
151 : //for(auto &it : ProgressArray)if(it < 1.0)return true;
152 :
153 : return false;
154 : }
155 :
156 224 : void result::printPercent(double i, double j) {
157 224 : const double t = P.terminalWidth - (maxformulaname+2) - 6;
158 : double u;
159 224 : if (j != 0) {
160 224 : u = fmax(0.0, fmin(t, (t * i) / j));
161 0 : } else u = 0;
162 224 : cout << "[";
163 11632 : for (int k = 1; k < t; k++) {
164 11408 : if (k < u) {
165 3745 : cout << "|";
166 7663 : } else cout << " ";
167 : };
168 224 : cout << "] " << (int) (100 * (u / t)) << "%\t" << endl;
169 224 : }
170 :
171 143 : void result::printCompactResult(){
172 143 : int precision = (P.terminalWidth - maxformulaname -40)/7;
173 143 : if (precision>10)precision=10;
174 143 : if (precision<1)precision=1;
175 1861 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++)
176 1718 : if (P.HaslFormulasname[i].find("$GRAPH$") == string::npos) {
177 1718 : cout << setw(maxformulaname + 1) << left << (P.HaslFormulasname[i] + ":") << " |< ";
178 1718 : cout.precision(precision-2);
179 1718 : cout << setw(precision) << HaslResult[i].min << " -[ ";
180 1718 : cout << setw(precision) << HaslResult[i].low << " < ";
181 1718 : cout << setw(precision) << HaslResult[i].mean << " > ";
182 1718 : cout << setw(precision) << HaslResult[i].up << " ]- ";
183 1718 : cout << setw(precision) << HaslResult[i].max << " >| width=";
184 1718 : cout << fixed << setw(precision) << HaslResult[i].width() /*<< defaultfloat*/ <<" level=";
185 1718 : cout << setw(8) << HaslResult[i].conf << endl;
186 1718 : cout.precision(12);
187 1718 : endline++;
188 1718 : if (!P.RareEvent && ProgressArray[i] != 0 && P.verbose > 2 && P.sequential) {
189 0 : cout << setw(maxformulaname + 2) << left << "% of width:";
190 0 : printPercent(ProgressArray[i], 1.0);
191 0 : endline++;
192 : }
193 : }
194 143 : }
195 :
196 232 : void result::printProgress() {
197 232 : auto current = chrono::system_clock::now();
198 232 : if (chrono::duration_cast<chrono::milliseconds>(current - lastprint) < P.updatetime)
199 240 : return;
200 112 : lastprint = current;
201 112 : if (P.alligatorMode) {
202 0 : printAlligator();
203 0 : return;
204 : }
205 3272 : while (endline >= 0) {
206 1580 : endline--;
207 1580 : if(P.isTTY)cout << "\033[A\033[2K";
208 : }
209 112 : cout << "Total paths: ";
210 112 : cout << setw(10) << MeanM2.I << " Accepted paths: ";
211 112 : cout << setw(10) << MeanM2.Isucc << " Wall-clock time: ";
212 :
213 112 : double p2 = Progress;
214 112 : if(!P.sequential || P.Width == 0)p2=0;
215 112 : double ProgressTot = max(p2, (double) MeanM2.I / (double) P.MaxRuns);
216 112 : auto wallclock = chrono::duration_cast<chrono::milliseconds>(current - start);
217 :
218 112 : auto estimated = wallclock * (1.0 / ProgressTot - 1.0);
219 112 : cout << chrono::duration_cast<chrono::seconds>(wallclock).count() << "s Remaining(approximative): ";
220 112 : cout << chrono::duration_cast<chrono::seconds>(estimated).count() << "s Trajectories per second: ";
221 112 : cout.precision(2);
222 112 : cout << (1000.0 * (double) MeanM2.I) / chrono::duration_cast<chrono::milliseconds>(wallclock).count() << endl;
223 112 : cout.precision(7);
224 :
225 112 : endline++;
226 :
227 112 : if (P.verbose > 1) {
228 112 : if(P.isTTY)cout << "\033[1m\033[33m";
229 112 : printCompactResult();
230 112 : if(P.isTTY)cout <<"\033[0m";
231 : }
232 112 : if(P.isTTY)cout << "\033[1m\033[3m";
233 112 : if (P.sequential) {
234 112 : cout << setw(maxformulaname+2 ) << left << "% of Err: ";
235 112 : printPercent(Progress, 1.0);
236 112 : endline++;
237 : }
238 112 : cout << setw(maxformulaname + 2) << left << "% of run: ";
239 112 : printPercent(MeanM2.I, P.MaxRuns);
240 112 : cout.precision(12);
241 112 : if(P.isTTY)cout <<"\033[0m";
242 112 : endline++;
243 : }
244 :
245 31 : void result::stopclock() {
246 31 : end = chrono::system_clock::now();
247 31 : cpu_time_used = chrono::duration_cast<chrono::duration<double> >(end - start).count();
248 31 : if(P.verbose>0 && P.isTTY){while (endline >= 0) {
249 0 : endline--;
250 0 : cout << "\033[A\033[2K";
251 : }
252 0 : cout << endl;
253 : }
254 31 : }
255 :
256 93 : void result::print(ostream &s) {
257 93 : s.precision(15);
258 186 : const string guiprefix = "#{GUI}#";
259 93 : if(P.guiGreatSpnMode){
260 0 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
261 0 : let fn=P.HaslFormulasname[i];
262 0 : if( fn.substr(0,11) == "Throughput_"){
263 0 : cout << guiprefix << " RESULT ALL THROUGHPUT ";
264 0 : cout << fn.substr(11,fn.length()-11) << " = ";
265 0 : cout << HaslResult[i].mean << endl;
266 : }
267 0 : if( fn.substr(0,10) == "MeanToken_"){
268 0 : cout << guiprefix << " RESULT ALL MEAN ";
269 0 : cout << fn.substr(10,fn.length()-10) << " = ";
270 0 : cout << HaslResult[i].mean << endl;
271 : }
272 : }
273 :
274 : }
275 :
276 : //if(!P.computeStateSpace)
277 : {
278 93 : s << "Command line:\t" << P.commandLine << endl;
279 93 : s << "Model path:\t" << P.PathGspn << endl;
280 93 : if (P.loopLHA > 0.0) {
281 30 : s << "LHA loop:\t" << P.loopLHA << " transient:\t" << P.loopTransientLHA << endl;
282 63 : } else if (!P.CSLformula.empty()) {
283 9 : s << "Formula:\t" << P.CSLformula << endl;
284 54 : } else s << "LHA path:\t" << P.PathLha << endl;
285 93 : s << "Seed:\t" << P.seed<<endl;
286 :
287 735 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
288 642 : if (!P.alligatorMode || (P.HaslFormulas[i]->TypeOp != PDF_PART && P.HaslFormulas[i]->TypeOp != CDF_PART)) {
289 : /*if (MeanM2->IsBernoulli[i]) {
290 : low[i] = (0 > low[i]) ? 0.0 : low[i];
291 : up[i] = (1 < up[i]) ? 1.0 : up[i];
292 : width[i] = up[i] - low[i];
293 : }*/
294 :
295 642 : s << P.HaslFormulasname[i] << ":" << endl;
296 :
297 642 : s << "Estimated value:\t" << HaslResult[i].mean << endl;
298 642 : if (P.sequential) {
299 642 : if (P.computeStateSpace > 0) {
300 9 : s << "Confidence interval:\t[" << HaslResult[i].mean * 0.999 << " , " << HaslResult[i].mean * 1.0001 << "]" << endl;
301 : } else {
302 633 : s << "Confidence interval:\t[" << HaslResult[i].low << " , " << HaslResult[i].up << "]" << endl;
303 : }
304 642 : s << "Minimal and maximal value:\t[" << HaslResult[i].min << " , " << HaslResult[i].max << "]" << endl;
305 642 : s << "Width:\t" << HaslResult[i].width() << endl;
306 642 : s << "Level:\t" << HaslResult[i].conf << endl;
307 : } else {
308 0 : s << "Confidence interval:\t[" << HaslResult[i].low << " , " << HaslResult[i].up << "]" << endl;
309 0 : s << "Minimal and maximal value:\t[" << HaslResult[i].min << " , " << HaslResult[i].max << "]" << endl;
310 0 : s << "Width:\t" << P.Width << endl;
311 : }
312 : }
313 : }
314 93 : s << "Method:\t";
315 93 : if (P.computeStateSpace > 0) {
316 9 : s << "Result computed numerically" << endl;
317 84 : } else if (!P.sequential) {
318 0 : s << "Confidence interval computed using Chernoff-Hoeffding bound." << endl;
319 84 : } else if (P.MaxRuns > MeanM2.I) {
320 15 : s << "Confidence interval computed sequentially using Chows-Robbin algorithm or SPRT." << endl;
321 : } else
322 69 : s << "Confidence interval computed using approximation to normal low." << endl;
323 :
324 93 : s << "Confidence level:\t" << P.Level << endl;
325 : //s << "Relative error:\t" << RelErr << endl;
326 93 : s << "Total paths:\t" << MeanM2.I << endl;
327 93 : s << "Accepted paths:\t" << MeanM2.Isucc << endl;
328 93 : s << "Batch size:\t" << P.Batch << endl;
329 93 : s << "Time for simulation:\t" << cpu_time_used << "s" << endl;
330 : rusage cpu_child;
331 93 : getrusage(RUSAGE_CHILDREN, &cpu_child);
332 93 : double child_time = cpu_child.ru_utime.tv_sec + cpu_child.ru_utime.tv_usec / 1000000.0;
333 93 : child_time += cpu_child.ru_stime.tv_sec + cpu_child.ru_stime.tv_usec / 1000000.0;
334 93 : double child_memory = cpu_child.ru_maxrss;
335 93 : getrusage(RUSAGE_SELF, &cpu_child);
336 93 : child_time += cpu_child.ru_utime.tv_sec + cpu_child.ru_utime.tv_usec / 1000000.0;
337 93 : child_time += cpu_child.ru_stime.tv_sec + cpu_child.ru_stime.tv_usec / 1000000.0;
338 93 : child_memory += cpu_child.ru_maxrss;
339 93 : s << "Total CPU time:\t" << child_time << endl;
340 93 : child_memory /= 1024;
341 : #ifdef __APPLE__
342 : //getrusage return the memory used in byte on darwin whereas it
343 : //is return in kbyte on linux.
344 : child_memory /= 1024;
345 : #endif
346 93 : s << "Total Memory used:\t" << setprecision(4) << child_memory << " MB" << endl;
347 93 : s << "Number of jobs:\t" << P.Njob << endl;
348 :
349 :
350 93 : if(P.guiGreatSpnMode){
351 0 : cout << guiprefix << " RESULT STAT simulation_time " << cpu_time_used << endl;;
352 0 : cout << guiprefix << " RESULT STAT total_time " << child_time << endl;;
353 0 : cout << guiprefix << " RESULT STAT memory " << child_memory << "MB"<< endl;;
354 : }
355 :
356 : }
357 93 : }
358 :
359 0 : tuple<string, double> result::split_name(string s) {
360 0 : size_t colon = s.find(":");
361 0 : size_t fb = s.find("[");
362 0 : size_t comma = s.find(",", fb);
363 0 : if (comma != string::npos) {
364 0 : return make_tuple(s.substr(0, min(colon,fb)),
365 0 : stod(s.substr(comma + 2, s.length() - comma - 3)));
366 : } else {
367 0 : size_t fb = s.find("$GRAPH$");
368 0 : size_t comma = s.find("$", fb + 7);
369 0 : size_t enddol = s.find("$", comma + 1);
370 0 : if (enddol != string::npos) {
371 0 : return make_tuple(s.substr(0, fb), (
372 0 : stod(s.substr(fb + 7, comma - 1)) +
373 0 : stod(s.substr(comma + 1, enddol - comma - 1))) / 2.0);
374 0 : } else return make_tuple("EMPTY", 0.0);
375 : }
376 : }
377 :
378 0 : void result::outputCDFPDF(string f) {
379 0 : ofstream outFile(f.c_str(), ios::out | ios::trunc);
380 0 : map<string, int> namelist;
381 0 : list<string> namelist2;
382 0 : map<double, int> valuelist;
383 0 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
384 0 : auto nv = split_name(P.HaslFormulasname[i]);
385 0 : if (get<0>(nv) != "EMPTY") {
386 0 : if (namelist.find(get<0>(nv)) == namelist.end()) {
387 0 : namelist.insert(make_pair(get<0>(nv), namelist.size()));
388 0 : namelist2.push_back(get<0>(nv));
389 : }
390 0 : if (valuelist.find(get<1>(nv)) == valuelist.end())
391 0 : valuelist.insert(make_pair(get<1>(nv), valuelist.size()));
392 : }
393 : }
394 :
395 0 : outFile << "abscissa" << " ";
396 0 : for (auto &itname : namelist2) {
397 0 : outFile << "\"" << itname << "-low\" ";
398 0 : outFile << "\"" << itname << "\" ";
399 0 : outFile << "\"" << itname << "-up\" ";
400 : }
401 0 : nbColumnGraph = namelist.size();
402 0 : outFile << endl;
403 :
404 0 : for (auto itval : valuelist) {
405 0 : outFile << itval.first;
406 0 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
407 0 : auto nv = split_name(P.HaslFormulasname[i]);
408 0 : if (itval.first == get<1>(nv)) {
409 0 : if (P.HaslFormulas[i]->TypeOp == CDF_PART
410 0 : || P.HaslFormulas[i]->TypeOp == PDF_PART
411 0 : || P.HaslFormulasname[i].find("$GRAPH$") != string::npos) {
412 0 : outFile << " " << HaslResult[i].low;
413 0 : outFile << " " << HaslResult[i].mean;
414 0 : outFile << " " << HaslResult[i].up;
415 : }
416 : }
417 : }
418 0 : outFile << endl;
419 : }
420 0 : outFile.close();
421 0 : }
422 :
423 31 : void result::printGnuplot() {
424 31 : if (gnuplotstream == NULL)return;
425 :
426 0 : if (P.dataPDFCDF.compare("") != 0) {
427 : struct stat filestatus;
428 0 : stat(P.dataPDFCDF.c_str(), &filestatus);
429 0 : if (filestatus.st_size > 0) {
430 0 : if (P.verbose > 2)cout << "invoke gnuplot for graph" << endl;
431 0 : stringstream ss;
432 0 : ss << "set output '" << P.dataPDFCDF << "." << gnuplotextenstion << "'\n";
433 0 : ss << "plot for [i=1:" << nbColumnGraph << "] '" << P.dataPDFCDF;
434 0 : ss << "' using 1:3*i-1:3*i+1 w filledcu ls 1 lc i notitle, ";
435 0 : ss << "for [i=1:" << nbColumnGraph ;
436 0 : ss << "] '' using 1:3*i title columnheader with lines lc i lw 1\n";
437 0 : ss << "set output\n";
438 0 : fputs(ss.str().c_str(),gnuplotstream);
439 0 : flushgnuplot();
440 : }
441 : }
442 :
443 0 : if (P.dataoutput.compare("") != 0) {
444 0 : if (P.verbose > 2)cout << "invoke gnuplot for data" << endl;
445 0 : stringstream ss;
446 0 : ss << "set output '" << P.dataoutput << "." << gnuplotextenstion << "'\n";
447 0 : ss << "plot '" << P.dataoutput << "' using 1:5:6 w filledcu ls 1 title columnheader(4),";
448 0 : ss << "'' using 1:5 notitle with lines lw 1 lc rgb 'black',";
449 0 : ss << "'' using 1:6 notitle with lines lw 1 lc rgb 'black',";
450 0 : ss << "'' using 1:3 title columnheader(3) w lines ls 2 lw 2\n";
451 0 : ss << "set output\n";
452 0 : fputs(ss.str().c_str(),gnuplotstream);
453 0 : flushgnuplot();
454 : }
455 :
456 0 : if (P.datatrace.compare("") != 0) {
457 0 : if (P.verbose > 2)cout << "invoke gnuplot for trace" << endl;
458 0 : string combicmd;
459 : //combicmd = "cp " + P.datatrace + " " + P.tmpPath + "/tmpdatafilecombcp.dat";
460 : //if(P.verbose>2)cout << combicmd << endl;
461 : //system(combicmd.c_str());
462 :
463 0 : combicmd = P.Path + "linecombinator " + P.datatrace + " " + P.tmpPath + "/tmpdatafilecomb.dat " + to_string(P.MaxRuns);
464 0 : if (P.verbose > 2)cout << combicmd << endl;
465 0 : if(system(combicmd.c_str()) !=0){
466 0 : cerr << "Fail to clean data trace" << endl;
467 0 : exit(EXIT_FAILURE);
468 : }
469 0 : cout << "system returned" << endl;
470 0 : stringstream ss;
471 0 : ss << "set output '" << P.datatrace << "." << gnuplotextenstion << "'\n";
472 0 : ss << "plot for [i=2:" << (P.nbPlace + 1) << "] '";
473 0 : ss << P.tmpPath << "/tmpdatafilecomb.dat";
474 0 : ss << "' using 1:i title columnheader(i) with lines\n";
475 0 : ss << "set output\n";
476 0 : fputs(ss.str().c_str(),gnuplotstream);
477 0 : flushgnuplot();
478 : }
479 : }
480 :
481 0 : void result::flushgnuplot() {
482 0 : fflush(gnuplotstream);
483 0 : }
484 :
485 : /* if(0!=ferror(gnuplotstream)){
486 : int statgnu = fflush(gnuplotstream);
487 : return;
488 : }
489 : cerr << "Gnuplot crashes " << endl;
490 : gnuplotstream = NULL;
491 : }*/
492 :
493 5 : void result::outputData() {
494 5 : outdatastream << MeanM2.I << " " << MeanM2.Isucc;
495 15 : for (size_t i = 0; i < P.HaslFormulasname.size(); i++) {
496 10 : outdatastream << " " << HaslResult[i].mean
497 20 : << " " << HaslResult[i].width()
498 20 : << " " << HaslResult[i].low << " " << HaslResult[i].up;
499 : }
500 5 : outdatastream << endl;
501 5 : outdatastream.flush();
502 : /*if(P.gnuplotDriver && MeanM2->I > P.Batch){
503 : auto current = chrono::system_clock::now();
504 :
505 : if( chrono::duration_cast<chrono::duration<double>>(current-lastdraw) < P.updatetime)
506 : return;
507 : lastdraw = current;
508 : printGnuplot();
509 : }*/
510 5 : }
511 :
512 62 : void result::printResultFile(string f) {
513 124 : ofstream ResultsFile(f.c_str(), ios::out | ios::trunc);
514 :
515 62 : if (!ResultsFile) cout << "File '" << f << "' not Created" << endl;
516 : else {
517 62 : print(ResultsFile);
518 62 : if (P.verbose > 0)cout << "Results are saved in '" << f << "'" << endl;
519 62 : ResultsFile.close();
520 : }
521 :
522 62 : }
523 :
524 0 : void result::printAlligator() {
525 0 : print(cout);
526 105 : }
|