From f68d3c1396fdd004a991d0613593a7c0f02dadde Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 16 Mar 2020 18:30:48 +0100 Subject: [PATCH] add an interface toward IOHexperimenter Handle IOH mono-objective function and CSV logger. --- problems/eval/eoEvalIOH.h | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 problems/eval/eoEvalIOH.h diff --git a/problems/eval/eoEvalIOH.h b/problems/eval/eoEvalIOH.h new file mode 100644 index 000000000..7bbc3d449 --- /dev/null +++ b/problems/eval/eoEvalIOH.h @@ -0,0 +1,61 @@ + +#ifndef _eoEvalIOH_h +#define _eoEvalIOH_h + +#include +#include + +/** Wrap an IOHexperimenter's problem class within an eoEvalFunc. + * + * See https://github.com/IOHprofiler/IOHexperimenter + * + * Handle only fitnesses that inherits from eoScalarFitness. + * + * @note: You're responsible of matching the fitness' scalar type (IOH handle double and int, as of 2020-03-09). + * + * You will need to pass the IOH include directory to your compiler (e.g. IOHexperimenter/build/Cpp/src/). + */ +template +class eoEvalIOH : public eoEvalFunc +{ + public: + using Fitness = typename EOT::Fitness; + using ScalarType = typename Fitness::ScalarType; + + eoEvalIOH( IOHprofiler_problem & pb) : + _ioh_pb(pb), + _has_log(false) + { } + + eoEvalIOH( IOHprofiler_problem & pb, IOHprofiler_csv_logger & log ) : + _ioh_pb(pb), + _has_log(true), + _ioh_log(log) + { } + + virtual void operator()(EOT& sol) + { + if(not sol.invalid()) { + return; + } + + sol.fitness( call( sol ) ); + } + + protected: + IOHprofiler_problem & _ioh_pb; + bool _has_log; + IOHprofiler_csv_logger & _ioh_log; + + virtual Fitness call(EOT& sol) + { + Fitness f = _ioh_pb.evaluate(sol); + if(_has_log) { + _ioh_log.write_line(_ioh_pb.loggerInfo()); + } + return f; + } + +}; + +#endif // _eoEvalIOH_h