Skip to content

Commit

Permalink
rand_curveball: no need to consider groups with maximum richness
Browse files Browse the repository at this point in the history
These can be added to the final result directly.
  • Loading branch information
shawnlaffan committed Feb 5, 2024
1 parent 39aed15 commit 067576d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Biodiverse/Randomise/CurveBall.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ END_PROGRESS_TEXT
printf "[RANDOMISE] Randomise using curveball algorithm for %s labels from %s groups\n",
scalar @sorted_labels, scalar @sorted_groups;

# No need to consider groups that cannot be swapped out.
# Could use a binary search but this is only done once per iteration.
if (keys %has_max_richness) {
@sorted_groups = grep {!exists $has_max_richness{$_}} @sorted_groups;
}

$progress_bar->reset;

# Basic algorithm:
Expand Down
9 changes: 9 additions & 0 deletions t/28-Randomisation.t
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ sub test_rand_structured_richness_same {
my $gp = "$x:$y";
$bd->add_element (group => $gp, allow_empty_groups => 1);
}
# add a cell with all possible labels
{
my $x = -100 * $c + $c / 2;
my $y = -$c / 2;
my $gp = "$x:$y";
foreach my $label ($bd->get_labels) {
$bd->add_element(group => $gp, label => $label);
}
}

# name is short for test_rand_calc_per_node_uses_orig_bd
my $sp = $bd->add_spatial_output (name => 'sp');
Expand Down

0 comments on commit 067576d

Please sign in to comment.