Algorithm-Evolutionary

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

t/0304-trap.t
t/0305-ecc.t
t/0306-any.t
t/0307-rastrigin.t
t/0307-zdt1.t
t/0333-mmdp.t
t/0400-noveltym.t
t/0401-genebx.t
t/0402-bitflip.t
t/0403-uxover.t
t/0404-quadxover.t
t/0404-string-mutation.t
t/0405-permutation.t
t/0406-quadxover-diff.t
t/04067-uxover-diff.t
t/0407-tournament.t
t/0408-gaussian-mutation.t
t/0444-stored.t
t/0499-breeder-diverser.t
t/0499-breeder.t
t/0500-generation-skel.t
t/0501-convergence-term.t

t/0302-knapsack.t  view on Meta::CPAN


use warnings;
use strict;

use lib qw( ../../lib ../lib lib ); #Just in case we are testing it in-place
use Algorithm::Evolutionary::Individual::BitString;

use_ok( "Algorithm::Evolutionary::Fitness::Knapsack", "using A::E::Fitness::Knapsack OK" );

#Weights and profits. Created with a generator
my @profits=(13.76, 8.40465, 7.06637, 14.066, 6.92841, 13.0597, 8.08657, 9.78078, 7.69908, 11.3133, 11.5659, 9.03571, 14.9824, 9.77511, 6.96194, 12.4665, 14.5813, 9.76035, 10.4337, 11.443, 12.8197, 10.4104, 14.1428, 7.15892, 10.8211, 7.30107, 7.86628...
my @weights=(8.75995, 3.40465, 2.06637, 9.06605, 1.92841, 8.05966, 3.08657, 4.78078, 2.69908, 6.31326, 6.56593, 4.03571, 9.98242, 4.77511, 1.96194, 7.46651, 9.58128, 4.76035, 5.4337, 6.44295, 7.8197, 5.41039, 9.14283, 2.15892, 5.82114, 2.30107, 2.866...

my $Nmax=100;  #Max. number of elements to choose
my $capacity=286; #Max. Capacity of the knapsack
my $rho=5.0625; #Penalizations coeficient

my $knap = new Algorithm::Evolutionary::Fitness::Knapsack( $Nmax, $capacity, $rho, \@profits, \@weights );
isa_ok( $knap,  "Algorithm::Evolutionary::Fitness::Knapsack" );

my $indi = new Algorithm::Evolutionary::Individual::BitString $Nmax ; # Build random bitstring with length 10
ok( $knap->_apply( $indi ) > 0, "Works on indis" );



( run in 0.683 second using v1.01-cache-2.11-cpan-39bf76dae61 )