argparse is sorta broken lol

dev
Brett 2025-05-31 21:39:00 -04:00
parent b733f1509c
commit 584a8ac47e
6 changed files with 30 additions and 54 deletions

View File

@ -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)

View File

@ -28,31 +28,30 @@
#include <filesystem>
#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<std::string>("file");
// auto rice_file_path = args.get<std::string>("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;
}

View File

@ -19,10 +19,9 @@
#ifndef BLT_GP_CONFIG_H
#define BLT_GP_CONFIG_H
#include <utility>
#include <thread>
#include <blt/gp/fwdecl.h>
#include <blt/std/types.h>
#include <blt/meta/config_generator.h>
#include <blt/gp/generators.h>
#include <blt/gp/transformers.h>
@ -160,6 +159,11 @@ namespace blt::gp
return *this;
}
};
std::tuple<prog_config_t, selection_t*> 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

View File

@ -69,6 +69,8 @@ namespace blt::gp
class stack_allocator;
class selection_t;
template<typename T>
class tracked_allocator_t;

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef CONFIG_FROM_ARGS_H
#define CONFIG_FROM_ARGS_H
#include <blt/gp/program.h>
namespace blt::gp
{
std::tuple<prog_config_t, selection_t*> make_config(int argc, const char** argv);
}
#endif //CONFIG_FROM_ARGS_H

View File

@ -15,11 +15,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../../include/blt/gp/util/config_from_args.h"
#include <blt/gp/config.h>
#include <blt/parse/argparse_v2.h>
#include "blt/std/string.h"
#include <blt/gp/selection.h>
namespace blt::gp
{
@ -51,7 +50,7 @@ namespace blt::gp
return config;
}
std::tuple<prog_config_t, selection_t*> make_config(int argc, const char** argv)
std::tuple<prog_config_t, selection_t*> 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<i32>().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<i32>().set_help("The maximum number of nodes in the initial trees");
parser.add_flag("--elites").set_dest("elites").set_default(2).as_type<i32>().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")
{