diff --git a/include/cli_options.h b/include/cli_options.h index 9f491c12..b49c9524 100644 --- a/include/cli_options.h +++ b/include/cli_options.h @@ -112,14 +112,13 @@ const std::string ASSIGN_ALGO_DESC = " Select the assignment algorithm. Valid options are `dfs' and `bfs'. Default is `dfs'.\n"; constexpr int ASSIGN_ALGO_VAL = 3001; -// TODO : swap this around, instead of pruning N most unpromising branches, make it try top N promising branches -const std::string PRUNE_BRANCHES = "prune-branches"; -const std::string PRUNE_BRANCHES_DESC = -" -" + PRUNE_BRANCHES + "=\n" -" Prune the N least promising branches at each node in the assignment tree search.\n" -" Specify `smart' instead of an integer to use a computed `smart' pruning at each node\n" -" instead of just a constant integer pruning.\n"; -constexpr int PRUNE_BRANCHES_VAL = 3002; +const std::string BEST_BRANCHES = "best-branches"; +const std::string BEST_BRANCHES_DESC = +" -" + BEST_BRANCHES + "=\n" +" Use only the N most promising branches at each node in the assignment tree search.\n" +" Specify `smart' instead of an integer to use a computed `smart' cutoff at each node\n" +" instead of just a constant integer cutoff.\n"; +constexpr int BEST_BRANCHES_VAL = 3002; // Fieldmap override options diff --git a/include/types.h b/include/types.h index 85038556..ee68faad 100644 --- a/include/types.h +++ b/include/types.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -806,12 +807,13 @@ struct CompilerConfig { // Palette assignment algorithm configuration AssignAlgorithm assignAlgorithm; std::size_t exploredNodeCutoff; - std::size_t pruneCount; + std::size_t bestBranches; bool smartPrune; CompilerConfig() : mode{}, transparencyColor{RGBA_MAGENTA}, tripleLayer{true}, defaultBehavior{"MB_NORMAL"}, - assignAlgorithm{AssignAlgorithm::DEPTH_FIRST}, exploredNodeCutoff{2'000'000}, pruneCount{0}, smartPrune{false} + assignAlgorithm{AssignAlgorithm::DEPTH_FIRST}, exploredNodeCutoff{2'000'000}, bestBranches{SIZE_MAX}, + smartPrune{false} { } }; diff --git a/src/cli_parser.cpp b/src/cli_parser.cpp index dd24d3ee..136039ef 100644 --- a/src/cli_parser.cpp +++ b/src/cli_parser.cpp @@ -345,7 +345,7 @@ DEFAULT_BEHAVIOR_DESC + "\n" + " Color Assignment Config Options\n" + ASSIGN_EXPLORE_CUTOFF_DESC + "\n" + ASSIGN_ALGO_DESC + "\n" + -PRUNE_BRANCHES_DESC + "\n" + +BEST_BRANCHES_DESC + "\n" + " Fieldmap Override Options\n" + TILES_PRIMARY_OVERRIDE_DESC + "\n" + TILES_TOTAL_OVERRIDE_DESC + "\n" + @@ -389,7 +389,7 @@ static void parseSubcommandOptions(PtContext &ctx, int argc, char *const *argv) // Color assignment config options {ASSIGN_EXPLORE_CUTOFF.c_str(), required_argument, nullptr, ASSIGN_EXPLORE_CUTOFF_VAL}, {ASSIGN_ALGO.c_str(), required_argument, nullptr, ASSIGN_ALGO_VAL}, - {PRUNE_BRANCHES.c_str(), required_argument, nullptr, PRUNE_BRANCHES_VAL}, + {BEST_BRANCHES.c_str(), required_argument, nullptr, BEST_BRANCHES_VAL}, // Fieldmap override options {TILES_PRIMARY_OVERRIDE.c_str(), required_argument, nullptr, TILES_PRIMARY_OVERRIDE_VAL}, @@ -517,12 +517,16 @@ static void parseSubcommandOptions(PtContext &ctx, int argc, char *const *argv) case ASSIGN_ALGO_VAL: ctx.compilerConfig.assignAlgorithm = parseAssignAlgorithm(ctx.err, ASSIGN_ALGO, optarg); break; - case PRUNE_BRANCHES_VAL: + case BEST_BRANCHES_VAL: if (std::string{optarg} == "smart") { ctx.compilerConfig.smartPrune = true; } else { - ctx.compilerConfig.pruneCount = parseIntegralOption(ctx.err, PRUNE_BRANCHES, optarg); + ctx.compilerConfig.bestBranches = parseIntegralOption(ctx.err, BEST_BRANCHES, optarg); + if (ctx.compilerConfig.bestBranches == 0) { + fatalerror(ctx.err, + fmt::format("option '{}' argument cannot be 0", fmt::styled(BEST_BRANCHES, fmt::emphasis::bold))); + } } break; @@ -880,8 +884,8 @@ static void parseSubcommandOptions(PtContext &ctx, int argc, char *const *argv) ctx.err.setAllWarnings(WarningMode::OFF); } - if (ctx.compilerConfig.smartPrune && ctx.compilerConfig.pruneCount > 0) { - fatalerror(ctx.err, fmt::format("found two conflicting configs for `{}' option", PRUNE_BRANCHES)); + if (ctx.compilerConfig.smartPrune && ctx.compilerConfig.bestBranches > 0) { + fatalerror(ctx.err, fmt::format("found two conflicting configs for `{}' option", BEST_BRANCHES)); } /* diff --git a/src/palette_assignment.cpp b/src/palette_assignment.cpp index 038a7a2d..c55a701d 100644 --- a/src/palette_assignment.cpp +++ b/src/palette_assignment.cpp @@ -1,5 +1,6 @@ #include "palette_assignment.h" +#include #include #include #include @@ -91,18 +92,10 @@ AssignResult assignDepthFirst(PtContext &ctx, AssignState &state, std::vector pal2IntersectSize; }); - std::size_t stopLimit = state.hardwarePalettes.size(); + std::size_t stopLimit = std::min(state.hardwarePalettes.size(), ctx.compilerConfig.bestBranches); if (ctx.compilerConfig.smartPrune) { throw std::runtime_error{"TODO : impl smart prune"}; } - else if (ctx.compilerConfig.pruneCount > 0) { - if (ctx.compilerConfig.pruneCount >= stopLimit) { - fatalerror(ctx.err, ctx.compilerSrcPaths, ctx.compilerConfig.mode, - fmt::format("'prune-branches' parameter '{}' pruned every branch", - fmt::styled(ctx.compilerConfig.pruneCount, fmt::emphasis::bold))); - } - stopLimit -= ctx.compilerConfig.pruneCount; - } for (size_t i = 0; i < stopLimit; i++) { const ColorSet &palette = state.hardwarePalettes.at(i); @@ -215,19 +208,11 @@ AssignResult assignBreadthFirst(PtContext &ctx, AssignState &initialState, std:: }); bool sawAssignmentWithIntersection = false; - std::size_t stopLimit = currentState.hardwarePalettes.size(); + std::size_t stopLimit = std::min(currentState.hardwarePalettes.size(), ctx.compilerConfig.bestBranches); if (ctx.compilerConfig.smartPrune) { // TODO : impl smart prune feature throw std::runtime_error{"TODO : impl smart prune"}; } - else if (ctx.compilerConfig.pruneCount > 0) { - if (ctx.compilerConfig.pruneCount >= stopLimit) { - fatalerror(ctx.err, ctx.compilerSrcPaths, ctx.compilerConfig.mode, - fmt::format("'prune-branches' parameter '{}' pruned every branch", - fmt::styled(ctx.compilerConfig.pruneCount, fmt::emphasis::bold))); - } - stopLimit -= ctx.compilerConfig.pruneCount; - } for (size_t i = 0; i < stopLimit; i++) { const ColorSet &palette = currentState.hardwarePalettes.at(i);