Skip to content

Commit

Permalink
Adjust get_bit_size_for_range() for size-1 domains.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Jan 10, 2024
1 parent c98c187 commit 846b14a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/search/algorithms/int_packer.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "int_packer.h"

#include <algorithm>
#include <cassert>

using namespace std;
Expand All @@ -24,6 +23,11 @@ static IntPacker::Bin get_bit_mask(int from, int to) {
}

static int get_bit_size_for_range(int range) {
assert(range >= 1);
// Domains in domain-abstracted tasks may have size one.
if (range == 1) {
return 1;
}
int num_bits = 0;
while ((1U << num_bits) < static_cast<unsigned int>(range))
++num_bits;
Expand Down Expand Up @@ -84,8 +88,6 @@ void IntPacker::set(Bin *buffer, int var, int value) const {

void IntPacker::pack_bins(const vector<int> &ranges) {
assert(var_infos.empty());
assert(all_of(ranges.begin(), ranges.end(),

This comment has been minimized.

Copy link
@FlorianPommerening

FlorianPommerening Jan 10, 2024

Member

I'm not sure but a range of 0 (or -1) could still cause an issue so the assertion might be useful with a >= 1 instead of the >1. But since the assertion wasn't there before, not adding it just leave things as they were, so no need to add it if you think it's not worth the hassle.

This comment has been minimized.

Copy link
@jendrikseipp

jendrikseipp Jan 10, 2024

Author Contributor

I moved the assertion into the get_bit_size_for_range() function.

[](int range) {return range > 1;}));

int num_vars = ranges.size();
var_infos.resize(num_vars);
Expand Down
8 changes: 3 additions & 5 deletions src/search/task_utils/task_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ PerTaskInformation<int_packer::IntPacker> g_state_packers(
vector<int> variable_ranges;
variable_ranges.reserve(variables.size());
for (VariableProxy var : variables) {
/* IntPacker expects all variables to have at least a domain size of
two. This is not the case for some domain-abstracted tasks. */
int domain_size = max(2, var.get_domain_size());
variable_ranges.push_back(domain_size);
variable_ranges.push_back(var.get_domain_size());
}
return utils::make_unique_ptr<int_packer::IntPacker>(variable_ranges);
});
}
);
}

0 comments on commit 846b14a

Please sign in to comment.