2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
4 #include "bbstdFindOptimalParam.h"
5 #include "bbstdPackage.h"
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,FindOptimalParam)
10 BBTK_BLACK_BOX_IMPLEMENTATION(FindOptimalParam,bbtk::AtomicBlackBox);
13 std::string FindOptimalParam::Replace(std::string strCommand, double value)
15 std::string toReplace = std::to_string( value );
16 int pos = strCommand.find("XXvalueXX");
19 strCommand.replace(pos,9,toReplace);
24 int FindOptimalParam::Evaluate( double value )
27 std::string strCommand = Replace( bbGetInputString(), value );
28 strCommand=strCommand+" NameFileTransfer="+bbGetInputTransferFile();
29 printf("EED FindOptimalParam::Evaluate command=%s\n", strCommand.c_str());
30 system( strCommand.c_str() );
31 FILE *ff = fopen( bbGetInputTransferFile().c_str() , "r");
34 fscanf(ff,"%d",&result);
36 printf("EED Warnning!! FindOptimalParam::Evaluate TransferFile not set.\n");
44 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
46 void FindOptimalParam::Process()
49 // THE MAIN PROCESSING METHOD BODY
50 // Here we simply set the input 'In' value to the output 'Out'
51 // And print out the output value
52 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
53 // void bbSet{Input|Output}NAME(const TYPE&)
54 // const TYPE& bbGet{Input|Output}NAME() const
56 // * NAME is the name of the input/output
57 // (the one provided in the attribute 'name' of the tag 'input')
58 // * TYPE is the C++ type of the input/output
59 // (the one provided in the attribute 'type' of the tag 'input')
60 // bbSetOutputOut( bbGetInputIn() );
61 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
63 double start = bbGetInputInitStart();
64 double end = bbGetInputInitEnd();
73 actual = (start+end)/2;
74 evalActual = Evaluate(actual);
78 } else if (evalActual==0) {
80 } else if (evalActual==-9999) {
81 printf("EED Warnning! FindOptimalParam::Process Transfer file Evaluation not coherent ..... \n");
84 printf("EED Warnning! FindOptimalParam::Process Evaluation not coherent ..... \n");
89 printf("EED Warnning! FindOptimalParam::Process Out limit iteration ..... \n");
92 printf("EED FindOptimalParam::Process %f \n",actual);
93 } while ( bbGetInputMinDifference() < (end-start) );
94 bbSetOutputResult(start);
97 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
99 void FindOptimalParam::bbUserSetDefaultValues()
102 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
103 // Here we initialize the input 'In' to 0
104 bbSetInputInitStart(0);
105 bbSetInputInitEnd(100);
106 bbSetInputString("");
107 bbSetInputMinDifference(1);
111 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
113 void FindOptimalParam::bbUserInitializeProcessing()
116 // THE INITIALIZATION METHOD BODY :
118 // but this is where you should allocate the internal/output pointers
124 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
126 void FindOptimalParam::bbUserFinalizeProcessing()
129 // THE FINALIZATION METHOD BODY :
131 // but this is where you should desallocate the internal/output pointers
136 // EO namespace bbstd