Algorithm-Evolutionary

 view release on metacpan or  search on metacpan

lib/Algorithm/Evolutionary/Op/SimulatedAnnealing.pm  view on Meta::CPAN

use strict;
use warnings;

use lib qw( ../../../../lib ); # mainly to avoid syntax errors when saving

=head1 NAME

SimulatedAnnealing - An operator that performs the simulated annealing algorithm
                          on an individual, using an external freezing schedule

=head1 SYNOPSIS

  #Define an algorithm
  my $m  = new Algorithm::Evolutionary::Op::BitFlip; #Changes a single bit
  my $freezer = new Algorithm::Evolutionary::Op:LinearFreezer( $initTemp );
  my $sa = new Algorithm::Evolutionary::Op::SimulatedAnnealing( $eval, $m, $freezer, $initTemp, $minTemp, $numChanges );

=head1 Base Class

L<Algorithm::Evolutionary::Op::Base>

=head1 DESCRIPTION

Simulated Annealing

=head1 METHODS

=cut

package Algorithm::Evolutionary::Op::SimulatedAnnealing;

our $VERSION = '3.1';
use Carp;

use Algorithm::Evolutionary::Op::LinearFreezer;
use base 'Algorithm::Evolutionary::Op::Base';


=head2 new( $evaluation_function, $change_operator, $freezer[,
    $initial_temperature] [,$minimum_temperature]
    [,$number_of_changes], [,$verbose] )

Creates a simulated annealing object

=cut

sub new {
  my $class = shift;
  my $self = {};
  $self->{_eval} = shift || croak "No eval function found";
  $self->{_op} = shift || croak "No operator found";
  $self->{_freezer} = shift || croak "No freezer found";
  $self->{_initTemp} = shift || 0.2;
  $self->{_minTemp} = shift || 0.001;
  $self->{_numChanges} = shift || 7;
  $self->{_verbose} = shift || 0;

  bless $self, $class;
  return $self;
}

=head2 run( $individual )

Applies the algorithm to the individual, returns the resulting



( run in 1.128 second using v1.01-cache-2.11-cpan-4991d5b9bd9 )