our
$VERSION
=
sprintf
"%d.%03d"
,
q$Revision: 3.2 $
=~ /(\d+)\.(\d+)/g;
our
$APPLIESTO
=
'ARRAY'
;
our
$ARITY
= 1;
sub
new {
my
$class
=
shift
;
my
$self
= {};
$self
->{
'_eval'
} =
shift
|| croak
"No eval function found"
;
bless
$self
,
$class
;
return
$self
;
}
sub
set {
my
$self
=
shift
;
my
$hashref
=
shift
|| croak
"No params here"
;
my
$codehash
=
shift
|| croak
"No code here"
;
my
$opshash
=
shift
|| croak
"No ops here"
;
for
(
keys
%$codehash
) {
$self
->{
"_$_"
} =
eval
"sub { $codehash->{$_} } "
;
}
$self
->{_ops} =();
for
(
keys
%$opshash
) {
push
@{
$self
->{_ops}},
Algorithm::Evolutionary::Op::Base::fromXML(
$_
,
$opshash
->{
$_
}->[1],
$opshash
->{
$_
}->[0] ) ;
}
}
sub
apply ($) {
my
$self
=
shift
;
my
$pop
=
shift
|| croak
"No population here"
;
croak
"Incorrect type "
.(
ref
$pop
)
if
ref
(
$pop
) ne
$APPLIESTO
;
my
$eval
=
$self
->{_eval};
my
%fitness_vector_of
;
for
my
$p
(
@$pop
) {
$p
->evaluate(
$eval
);
$fitness_vector_of
{
$p
->as_string} =
$p
->Fitness();
}
my
@dominated_by
;
my
$i
;
for
(
$i
= 0;
$i
<
@$pop
;
$i
++ ) {
for
(
my
$j
=
$i
+1;
$j
<
@$pop
;
$j
++ ) {
my
$result
=
vector_compare(
$fitness_vector_of
{
$pop
->[
$i
]->as_string },
$fitness_vector_of
{
$pop
->[
$j
]->as_string } );
$dominated_by
[
$j
]++
if
$result
== -1;
$dominated_by
[
$i
]++
if
$result
== 1;
}
}
for
(
$i
= 0;
$i
<
@$pop
;
$i
++ ) {
$dominated_by
[
$i
]++;
$pop
->[
$i
]->Fitness( 1/
$dominated_by
[
$i
] );
}
}
"The truth is out there"
;