Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cbs branching for compact table problems. #1

Open
wants to merge 1 commit into
base: upir
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion gecode/int/branch/cbs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ namespace Gecode { namespace Int { namespace Branch {
// Lambda we pass to propagators via solndistrib to query solution densities
auto SendMarginal = [this](unsigned int prop_id, unsigned int var_id,
int val, double dens) {
if (!varIdToPos.isIn(var_id)) return;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avez-vous trouvé pourquoi il y a des variables dans le propagateur qui ne se retrouvent pas dans le brancher? J'avais ajouté ce fix pour cette raison et je ne sais pas si c'est un comportement normal.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non on n'a pas trouvé, désolée :(

if (logProp[prop_id].dens < dens) {
logProp[prop_id].var_id = var_id;
logProp[prop_id].val = val;
Expand All @@ -157,6 +159,11 @@ namespace Gecode { namespace Int { namespace Branch {
for (auto& kv : logProp)
kv.second.visited = false;

// We can change rho's value. Actually, there is no memory exception
// with rho = 1. But with other values of rho, there is a memory
// exception for some crossword problems.
float rho = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gilles m'a dit qu'il y avait des fuites de mémoire avec rho < 1. Je vais regarder ça.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouais exact :(


for (Propagators p(home, PropagatorGroup::all); p(); ++p) {
unsigned int prop_id = p.propagator().id();
unsigned int domsum;
Expand All @@ -181,7 +188,7 @@ namespace Gecode { namespace Int { namespace Branch {
// If the domain size sum of all variables in the propagator has changed
// since the last time we called this function, we need to recompute
// solution densities. Otherwise, we can reuse them.
if (logProp[prop_id].domsum != domsum) {
if (domsum < rho * logProp[prop_id].domsum || logProp[prop_id].domsum == 0) {
logProp[prop_id].dens = -1;
// Solution density computation
p.propagator().solndistrib(home, SendMarginal);
Expand Down
73 changes: 73 additions & 0 deletions gecode/int/extensional/compact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,79 @@ namespace Gecode { namespace Int { namespace Extensional {
return sizeof(*this);
}

#ifdef GECODE_HAS_CBS
template<class View, class Table>
void
void
PosCompact<View,Table>::solndistrib(Space& home,
Propagator::SendMarginal send) const {

int minVal = std::numeric_limits<int>::max();
int maxVal = std::numeric_limits<int>::min();

for (Advisors<CTAdvisor> as(c); as(); ++as) {
CTAdvisor& a = as.advisor();
View x = a.view();

minVal = std::min(x.min(), minVal);
maxVal = std::max(x.max(), maxVal);
}

Region r;
unsigned long long int* solCounts = r.alloc<unsigned long long int>(maxVal - minVal + 1);

for (Advisors<CTAdvisor> as(c); as(); ++as) {
CTAdvisor& a = as.advisor();
View x = a.view();

if (x.assigned()) continue;

// Normalization constant for keeping densities values between 0 and 1
double normalization = 0;

for (ValidSupports vs(*this, a); vs(); ++vs) {
assert(vs.val() >= minVal);
assert(vs.val() <= maxVal);

unsigned long long int cbsSupports = table.ones(vs.supports());
solCounts[vs.val() - minVal] = cbsSupports;
normalization += cbsSupports;
}

// Because we approximate the permanent of each value for the variable, we
// assign densities in a separate loop where we normalize solution densities.
for (ValidSupports vs(*this, a); vs(); ++vs) {
send(this->id(),
x.id(),
x.baseval(vs.val()),
solCounts[vs.val() - minVal] / normalization);
}
}

r.free();
}

template<class View, class Table>
void
PosCompact<View,Table>::domainsizesum(Propagator::InDecision in,
unsigned int& size,
unsigned int& size_b) const {
size = 0;
size_b = 0;

for (Advisors<CTAdvisor> as(c); as(); ++as) {
CTAdvisor& a = as.advisor();
View x = a.view();

if (!x.assigned()) {
size += x.size();
if (in(x.id()))
size_b += x.size();
}
}
}
#endif

template<class View, class Table>
void
PosCompact<View,Table>::reschedule(Space& home) {
Expand Down