add eoEvalCmd, an eval that call a system command

This commit is contained in:
Johann Dreo 2020-02-08 16:34:34 +01:00
commit ccb4b3787b
4 changed files with 173 additions and 0 deletions

View file

@ -70,6 +70,7 @@ set (TEST_LIST
#t-eoDualFitness
t-eoParser
t-eoPartiallyMappedXover
t-eoEvalCmd
)

29
eo/test/t-eoEvalCmd.cpp Normal file
View file

@ -0,0 +1,29 @@
#include <iostream>
#include <eo>
#include <es.h>
using namespace std;
int main(int /*argc*/, char* /*argv[]*/)
{
typedef eoReal<eoMinimizingFitness> EOT;
// Build something like: ">&1 echo 1.2; # INVALID 2 1 2"
eoEvalCmd<EOT> eval("echo 1.2", ">&1", "; #");
EOT sol = {1,2};
std::clog << sol << std::endl;
try {
eval(sol);
} catch(eoSystemError& e) {
std::cerr << e.what() << std::endl;
exit(1);
}
std::clog << eval.last_call() << std::endl;
EOT::Fitness f = sol.fitness();
std::clog << "fitness: " << f << std::endl;
assert(f = 1.2);
}