Algorithm-Evolutionary-Fitness
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Fitness/wP_Peaks.pm view on Meta::CPAN
use strict;
use warnings;
use lib qw( ../../../../lib );
=head1 NAME
Algorithm::Evolutionary::Fitness::wP_Peaks - wP Peaks problem generator - weighted version of P_Peaks
=head1 SYNOPSIS
my $number_of_bits = 32;
my @weights = (1);
for (my $i = 0; $i < 99; $i ++ ) {
push @weights, 0.99;
}
my $wp_peaks = Algorithm::Evolutionary::Fitness::wP_Peaks->new( $number_of_bits, @weights ); #Number of peaks = scalar @weights
# Or use an alternative ctor
my $descriptor = { number_of_peaks => 100,
weight => 0.99 };
my $wp_peaks = Algorithm::Evolutionary::Fitness::wP_Peaks->new( $number_of_bits, $descriptor)
=head1 DESCRIPTION
wP-Peaks fitness function, weighted version of the P-Peaks fitness function, which has now a single peak
=head1 METHODS
=cut
package Algorithm::Evolutionary::Fitness::wP_Peaks;
our $VERSION = "3.2";
use String::Random;
use Algorithm::Evolutionary::Utils qw(hamming);
use base qw(Algorithm::Evolutionary::Fitness::String);
=head2 new( $number_of_bits, @weights_array )
or new( $number_of_bits, $hash_with_number_of_peaks_and_weight )
Creates a new instance of the problem, with the said number of bits and peaks
=cut
sub new {
my $class = shift;
my ( $bits ) = shift;
my @weights;
if ( ref $_[0] eq 'HASH' ) {
push @weights, 1;
for (my $i = 0; $i < $_[0]->{'number_of_peaks'}-1; $i ++ ) {
push @weights, $_[0]->{'weight'};
}
} else {
@weights = @_;
}
my $self = $class->SUPER::new();
#Generate peaks
( run in 0.707 second using v1.01-cache-2.11-cpan-39bf76dae61 )