Skip to content

Commit

Permalink
BFS can now compile secondary sets
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Sep 23, 2023
1 parent 687d256 commit 1fe1316
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/cli_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ 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>\n"
Expand Down
25 changes: 22 additions & 3 deletions src/palette_assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AssignResult assignDepthFirst(PtContext &ctx, AssignState &state, std::vector<Co
* secondary tiles to freely use.
*/
if (!primaryPalettes.empty()) {
for (size_t i = 0; i < primaryPalettes.size(); i++) {
for (std::size_t i = 0; i < primaryPalettes.size(); i++) {
const ColorSet &palette = primaryPalettes.at(i);
if ((palette | toAssign).count() == palette.count()) {
/*
Expand Down Expand Up @@ -180,9 +180,28 @@ AssignResult assignBreadthFirst(PtContext &ctx, AssignState &initialState, std::

const ColorSet &toAssign = unassigneds.at(currentState.unassignedCount - 1);

// FIXME : handle secondary sets properly, see how depth-first does it
bool foundPrimaryMatch = false;
if (!primaryPalettes.empty()) {
throw std::runtime_error{"TODO : support secondary set compilation with BFS backend"};
for (std::size_t i = 0; i < primaryPalettes.size(); i++) {
const ColorSet &palette = primaryPalettes.at(i);
if ((palette | toAssign).count() == palette.count()) {
std::vector<ColorSet> hardwarePalettesCopy;
std::copy(std::begin(currentState.hardwarePalettes), std::end(currentState.hardwarePalettes),
std::back_inserter(hardwarePalettesCopy));
AssignState updatedState = {hardwarePalettesCopy, currentState.unassignedCount - 1};
stateQueue.push_back(updatedState);
visitedStates.insert(updatedState);
foundPrimaryMatch = true;
}
}
}

/*
* If we found a matching primary palette for the current assignment, go ahead and skip ahead to the next toAssign.
* No need to process anything further for this toAssign.
*/
if (foundPrimaryMatch) {
continue;
}

std::stable_sort(std::begin(currentState.hardwarePalettes), std::end(currentState.hardwarePalettes),
Expand Down

0 comments on commit 1fe1316

Please sign in to comment.