note
Abigail-II
Despite what I just said about NP-completeness, the following algorithm
might give a reasonable solution (certainly not optimal).
<ol>
<li>Let C be the set of all complaints.
<li>For each complaint c in C find the set S(c) of all complaints d in C
such that the distance between c and d is less than X (X is user defined).
<li>Find complaint e in C such that |S(e)| <= |S(f)| for all f in C;
that is, find the complaint who has the most other complaints nearby.
Pick a random one in case of a tie.
<li>Make a clump out of e and S(e).
<li>Remove all complaints g in S(e) from C. For all h remaining in C,
remove from S(h) all g in S(e).
<li>If C is empty, we're done. Else, goto 3.
</ol>
Some pseudo code:
<code>
# Get set of all complaints.
my @C = get_all_complaints;
# Find all the associated sets.
my %D = map {my $c = $_;
$c => {map {$_ => 1}
grep {$c ne $_ && distance ($c, $_) < $X} @C}} @C;
while (%D) {
# Find complaint with the most nearby.
my ($complaint, $size) = (undef, 0);
while (my ($c, $set) = each %D) {
($complaint = $c, $size = keys %$set) if keys %$set > $size;
}
# Found largest, make a clump.
make_clump ($complaint, @{$D {$complaint}});
# Delete largest from set.
my $set = delete $D {$complaint};
# Delete associated set from set.
delete @D {keys %$set};
# Delete associated set from associated sets.
delete @{$_} {keys %$set} for values %D;
}
</code>
The performance will be quadratic, I'm afraid.
<p>
Abigail
182629
182777