7std::map<std::size_t, std::size_t>
10 std::map<std::size_t, std::size_t> multiplicity;
12 auto count_colors = [&multiplicity](
const std::vector<PackableTile> &tile_list) {
13 for (
const auto &tile : tile_list) {
14 for_each_color(tile.color_set(), [&multiplicity](std::size_t color_idx) { multiplicity[color_idx]++; });
28 if (global_mult.empty()) {
33 std::size_t cardinality = 0;
34 for (
const auto &count : global_mult | std::views::values) {
39 const std::size_t
num_colors = global_mult.size();
42 return static_cast<double>(cardinality) /
static_cast<double>(
num_colors);
46 const PackedPalette &palette,
const std::map<PackableTile::Id, ColorSet> &tile_colors_map)
48 std::map<std::size_t, std::size_t> local_mult;
51 if (
auto it = tile_colors_map.find(tile_id); it != tile_colors_map.end()) {
52 for_each_color(it->second, [&local_mult](std::size_t color_idx) { local_mult[color_idx]++; });
62 const std::map<PackableTile::Id, ColorSet> &tile_colors_map)
66 double weighted_cost = 0.0;
67 for_each_color(tile_colors, [&weighted_cost, &local_mult](std::size_t color_idx) {
68 std::size_t count = 0;
69 if (
const auto it = local_mult.find(color_idx); it != local_mult.end()) {
72 weighted_cost += 1.0 /
static_cast<double>(1 + count);
82 if (color_count == 0) {
89 double weighted_cost = 0.0;
90 for_each_color(tile_colors, [&weighted_cost, &local_mult](std::size_t color_idx) {
91 std::size_t count = 1;
92 if (
const auto it = local_mult.find(color_idx); it != local_mult.end()) {
95 weighted_cost += 1.0 /
static_cast<double>(count);
98 return 1.0 - (weighted_cost /
static_cast<double>(color_count));
103 double weighted_cost = 0.0;
104 for_each_color(tile_colors, [&weighted_cost, &palette](std::size_t color_idx) {
106 weighted_cost += 1.0 /
static_cast<double>(1 + count);
108 return weighted_cost;
114 if (color_count == 0) {
121 double weighted_cost = 0.0;
122 for_each_color(tile_colors, [&weighted_cost, &palette](std::size_t color_idx) {
123 const std::size_t count = std::max(palette.
color_multiplicity(color_idx), std::size_t{1});
124 weighted_cost += 1.0 /
static_cast<double>(count);
127 return 1.0 - (weighted_cost /
static_cast<double>(color_count));
A set of colors represented as a bitset.
Represents a hardware palette after packing with accumulated colors and assigned tiles.
const std::vector< PackableTile::Id > & assigned_tile_ids() const
std::size_t color_multiplicity(std::size_t color_idx) const
void for_each_color(const ColorSet &set, Func &&func)
Iterates over each color index in a ColorSet.
double compute_palette_local_efficiency(const ColorSet &tile_colors, const std::map< std::size_t, std::size_t > &local_mult)
Computes the palette-local efficiency of a tile within its palette.
double compute_weighted_cost_in_palette_fast(const ColorSet &tile_colors, const PackedPalette &palette)
Computes the weighted cost of placing a tile in a palette using cached counts.
double compute_weighted_cost_in_palette(const ColorSet &tile_colors, const PackedPalette &palette, const std::map< PackableTile::Id, ColorSet > &tile_colors_map)
Computes the weighted cost of placing a tile in a specific palette.
std::map< std::size_t, std::size_t > build_global_multiplicity_map(const std::vector< PackableTile > &tiles, const std::vector< PackableTile > &hints)
Builds a GLOBAL multiplicity map from all input tiles.
std::map< std::size_t, std::size_t > build_palette_local_multiplicity(const PackedPalette &palette, const std::map< PackableTile::Id, ColorSet > &tile_colors_map)
Builds a PALETTE-LOCAL multiplicity map for a specific palette.
double compute_average_multiplicity(const std::vector< PackableTile > &tiles, const std::vector< PackableTile > &hints)
Computes the average multiplicity of the input tiles (problem difficulty metric).
constexpr std::size_t num_colors
Maximum allowable color count for GBA hardware.
double compute_palette_local_efficiency_fast(const ColorSet &tile_colors, const PackedPalette &palette)
Computes the palette-local efficiency of a tile using cached counts.
std::size_t color_set_count(const ColorSet &set)
Counts the number of colors in a ColorSet.
Metrics for Bin Packing with Overlapping Items (Pagination problem).