Algorithm-Evolutionary
view release on metacpan or search on metacpan
scripts/rectangle-coverage.pl view on Meta::CPAN
#!/usr/bin/env perl
=head1 NAME
rectangle-coverage.pl - Find the dot maximally covered by (random) rectangles
=head1 SYNOPSIS
You might have to do
prompt% cpanm --installdeps .
first, since that module is not installed by default with L<Algorithm::Evolutionary>. Use C<sudo> if appropriate.
prompt% ./rectangle-coverage.pl <number-of-rectangles> <arena-side> <bits-per-coordinate> <population> <number of generations> <selection rate>
Or
prompt% ./rectangle-coverage.pl
And change variable values from the user interface
=head1 DESCRIPTION
A demo that combines the L<Algorithm::Evolutionary::Op::Easy> module
with L<Tk> to create a visual demo of the evolutionary
algorithm. It generates randomly a number of rectangles, and shows
how the population evolves to find the solution. The best point is
shown in darkening yellow color, the rest of the population in
green.
Use "Start" to start the algorithm after setting the variables, and
then Finish to stop the EA, Exit to close the window.
Default values are as follows
=over
=item *
I<number of rectangles>: 300
=item *
I<arena-side>: 10 This is independent from the number of pixels, set
by default to 600x600.
=item *
I<bits-per-coordinate>: 32 (this is the chromosome length divided by two;
there are two "genes")
=item *
I<population size>: 64
=item *
I<number of generations>: 200
=item *
I<selection rate>: 20% (will be replaced each generation); this means it's a steady state algorithm, which only changes a part of the population each generation.
=back
This program also demonstrates the use of caches in the fitness
evaluation, so be careful if you use too many bits or too many
generations, check out memory usage.
Console output shows the number of generations, the winning chromosome, and
fitness. After finishing, it outputs time, cache ratio and some other
things.
=cut
use Tk;
use strict;
use warnings;
use Algorithm::RectanglesContainingDot;
use lib qw(lib ../lib);
use Algorithm::Evolutionary qw( Individual::BitString Op::Easy
Op::Bitflip Op::Crossover );
my $width = 600;
( run in 0.335 second using v1.01-cache-2.11-cpan-e93a5daba3e )