Skip to content

Commit

Permalink
Add tentative skipping of unnatural partitions
Browse files Browse the repository at this point in the history
An unnatural partition is a partition of size greater than two with all
of their parts already explored.
  • Loading branch information
tschijnmo committed Dec 25, 2017
1 parent 4453d70 commit 433dae7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/libparenth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ class Parenther {
return mem_entry->second.evals.front().cost;
}

// If the purpose is for the optimal solution only (without asking for
// extra information).
bool if_for_opt = mode != Mode::EXHAUST && !if_incl;

// The actual summations and externals will be computed later based on
// the current candidate values.
auto mem_stat = mem.emplace(subprobl, Interm(cand_sums, cand_exts));
Expand Down Expand Up @@ -714,6 +718,20 @@ class Parenther {
kept_sums ^= bsums.sums;
auto chunks = form_chunks(subprobl, kept_sums);

// No enough broken summations.
if (chunks.size() < 2) {
continue;
}

// Unnatural partition.
if (if_for_opt && chunks.size() > 2
&& std::all_of(
chunks.cbegin(), chunks.cend(), [&mem](const Subset& i) {
return mem.count(i.factors) != 0;
})) {
continue;
}

for (Bipart_it bipart_it(chunks, bsums, n_total_factors, n_dims());
bipart_it; ++bipart_it) {

Expand Down Expand Up @@ -747,6 +765,7 @@ class Parenther {
}
}

assert(!evals.empty());
return evals.front().cost;
}

Expand Down

0 comments on commit 433dae7

Please sign in to comment.