diff --git a/CMakeLists.txt b/CMakeLists.txt index cc4711e..96fbe3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ macro(compile_options target_name) sanitizers(${target_name}) endmacro() -project(blt-gp VERSION 0.5.38) +project(blt-gp VERSION 0.5.39) include(CTest) diff --git a/examples/src/rice_classification.cpp b/examples/src/rice_classification.cpp index 3473d7b..359e3d1 100644 --- a/examples/src/rice_classification.cpp +++ b/examples/src/rice_classification.cpp @@ -28,31 +28,30 @@ #include #include "../rice_classification.h" #include "blt/fs/loader.h" -#include "../../include/blt/gp/util/config_from_args.h" static const auto SEED_FUNC = [] { return std::random_device()(); }; -int main(int argc, const char** argv) +int main(const int argc, const char** argv) { - auto [config, selection] = blt::gp::make_config(argc, argv); - blt::arg_parse parser; - parser.addArgument(blt::arg_builder{"file"} - .setHelp("File for rice data. Should be in .arff format.").setDefault("../datasets/Rice_Cammeo_Osmancik.arff").build()); + auto [config, selection] = blt::gp::create_config_from_args(argc, argv); + // blt::arg_parse parser; + // parser.addArgument(blt::arg_builder{"file"} + // .setHelp("File for rice data. Should be in .arff format.").setDefault("../datasets/Rice_Cammeo_Osmancik.arff").build()); - auto args = parser.parse_args(argc, argv); + // auto args = parser.parse_args(argc, argv); - if (!args.contains("file")) - { - BLT_WARN("Please provide path to file with -f or --file"); - return 1; - } + // if (!args.contains("file")) + // { + // BLT_WARN("Please provide path to file with -f or --file"); + // return 1; + // } - auto rice_file_path = args.get("file"); + // auto rice_file_path = args.get("file"); blt::gp::example::rice_classification_t rice_classification{SEED_FUNC, config}; rice_classification.set_all_selections(*selection); - rice_classification.execute(rice_file_path); + rice_classification.execute("../datasets/Rice_Cammeo_Osmancik.arff"); return 0; } diff --git a/include/blt/gp/config.h b/include/blt/gp/config.h index 53eed10..011f362 100644 --- a/include/blt/gp/config.h +++ b/include/blt/gp/config.h @@ -19,10 +19,9 @@ #ifndef BLT_GP_CONFIG_H #define BLT_GP_CONFIG_H -#include #include +#include #include -#include #include #include @@ -160,6 +159,11 @@ namespace blt::gp return *this; } }; + + std::tuple create_config_from_args(int argc, const char** argv); + + // need to make parser for config file, update arg parser, make default config file. + // maybe make a system with basic tree but changes behaviour based on if there is a drop type, using weird type stuff? (we already return an object to modify) } #endif //BLT_GP_CONFIG_H diff --git a/include/blt/gp/fwdecl.h b/include/blt/gp/fwdecl.h index fddc4f2..652aab5 100644 --- a/include/blt/gp/fwdecl.h +++ b/include/blt/gp/fwdecl.h @@ -68,6 +68,8 @@ namespace blt::gp class full_generator_t; class stack_allocator; + + class selection_t; template class tracked_allocator_t; diff --git a/include/blt/gp/util/config_from_args.h b/include/blt/gp/util/config_from_args.h deleted file mode 100644 index 966f384..0000000 --- a/include/blt/gp/util/config_from_args.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -/* - * Copyright (C) 2024 Brett Terpstra - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef CONFIG_FROM_ARGS_H -#define CONFIG_FROM_ARGS_H - -#include - -namespace blt::gp -{ - std::tuple make_config(int argc, const char** argv); -} - -#endif //CONFIG_FROM_ARGS_H diff --git a/src/util/config_from_args.cpp b/src/config.cpp similarity index 97% rename from src/util/config_from_args.cpp rename to src/config.cpp index a0592a4..063ea05 100644 --- a/src/util/config_from_args.cpp +++ b/src/config.cpp @@ -15,11 +15,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "../../include/blt/gp/util/config_from_args.h" - +#include #include - #include "blt/std/string.h" +#include namespace blt::gp { @@ -51,7 +50,7 @@ namespace blt::gp return config; } - std::tuple make_config(int argc, const char** argv) + std::tuple create_config_from_args(int argc, const char** argv) { if (argc == 1) { @@ -60,6 +59,7 @@ namespace blt::gp argc = arr.size(); } argparse::argument_parser_t parser; + parser.with_help(); parser.add_flag("--initial_tree_min").set_dest("initial_tree_min").set_default(2).as_type().set_help("The minimum number of nodes in the initial trees"); parser.add_flag("--initial_tree_max").set_dest("initial_tree_max").set_default(6).as_type().set_help("The maximum number of nodes in the initial trees"); parser.add_flag("--elites").set_dest("elites").set_default(2).as_type().set_help("Number of best fitness individuals to keep each generation"); @@ -151,9 +151,9 @@ namespace blt::gp return {config, &s_tournament_selection}; if (args.get("mode") == "manual") { - selection_t* selection_op = nullptr; - crossover_t* crossover_op = nullptr; - mutation_t* mutation_op = nullptr; + selection_t* selection_op = &s_tournament_selection; + crossover_t* crossover_op = &s_subtree_crossover; + mutation_t* mutation_op = &s_single_point_mutation; const auto selection_arg = string::toLowerCase(args.get("selection_type")); if (selection_arg == "tournament") { @@ -222,4 +222,4 @@ namespace blt::gp } BLT_ABORT("Broken arguments!"); } -} +} \ No newline at end of file