c++ - Where should the user-defined parameters of a framework be ? -
i kind of newbie , creating framework evolve objects in c++ evolutionary algorithm. evolutionary algorithm evolves objects , tests them best solution (for example, evolve weights neural network , test on sample data, in end network has accuracy, without having trained it).
my problem there lots of parameters algorithm (type of selection/crossover/mutation, probabilities each of them...) , since framework, user should able access , modify them.
current solution
for now, created header file parameters.h of form:
// don't change these parameters //mutation type #define flip 1 #define add_connection 2 #define rm_connection 3 // user defined static const int type_of_mutation = flip;
the user modifies static variables type_of_mutation , mutation function tests value of type_of_mutation , calls right mutation function.
this works well, has few drawbacks:
- when change parameter in header , call "make", no change taken account, have call "make clean" "make". saw, not problem in makefile how building works. if did re-build when change parameter, mean re-compile whole project these parameters used everywhere; not efficient.
- if want run genetic algorithm several times different parameters, have run first time save results, change parameters run second time etc.
other possibilities
i thought taking these parameters arguments of top-level function. problem function take 20 arguments or so, doesn't seem readable...
what mean top-level function now, evolutionary algorithm run doing this:
populationmanager mypop; mypop.evolveit();
if defined parameters arguments, have like:
populationmanager mypop; mypop.evolveit(20,10,5,flip,9,8,2,3,tournament,0,23,4);
you can see how hellish may define parameters in right order !
conclusion
the frameworks know make build algorithm pre-defined functions, user shouldn't have go through code change parameters 1 one.
it may useful indicate framework used internally, definite set of projects.
any input best way define these parameters welcome !
if options not change use struct this:
enum class mutationtype { flip, addconnection, removeconnection }; struct options { // documentation mutation_type. mutationtype mutation_type = mutationtype::flip; // documentation integer option. int integer_option = 10; };
and provide constructor takes these options.
options options; options.mutation_type = mutationtype::addconnection; populationmanager population(options);
c++11 makes easy, because allows specifying defaults options, user needs set options need different default.
also note used enum options, ensures user can use correct values.
Comments
Post a Comment