AI-SimulatedAnnealing
view release on metacpan or search on metacpan
lib/AI/SimulatedAnnealing.htm view on Meta::CPAN
temperature by 0.95 and then rounds the result down to the nearest
integer (if the result isn't already an integer). When the
temperature reaches zero, annealing is immediately terminated.</p>
<p style="margin-left: 13px;"><b>Note:</b> Annealing can sometimes
complete before the temperature reaches zero if, after a particular
temperature reduction, a brute-force optimization approach (that is,
testing every possible combination of numbers within the subranges
determined by the new temperature) would produce a number of tests
that is less than or equal to the specified cycles per temperature.
In that case, the <code>anneal()</code> function performs the
brute-force optimization to complete the annealing process.</p>
<p>After a temperature reduction, the <code>anneal()</code> function
determines each new subrange such that the current optimal integer
from the total range is as close as possible to the center of the new
subrange. When there is a tie between two possible positions for the
subrange within the total range, a "coin flip" decides.</p>
<hr/>
<h1><a name="prerequisites">PREREQUISITES</a></h1>
<p>This module requires Perl 5, version 5.10.1 or later.</p>
<hr/>
<h1><a name="methods">METHODS</a></h1>
lib/AI/SimulatedAnnealing.pm view on Meta::CPAN
my $FALSE = 0;
my $TEMPERATURE_MULTIPLIER = 0.95;
# The anneal() function takes a reference to an array of number
# specifications (which are references to hashes containing "LowerBound",
# "UpperBound", and "Precision" fields), a reference to a cost function
# (which takes a list of numbers matching the specifications and returns a
# number representing a cost to be minimized), and a positive integer
# specifying the number of randomization cycles to perform at each
# temperature during the annealing process.
#
# The function returns a reference to an array containing the
# optimized list of numbers.
sub anneal {
my $number_specs = validate_number_specs($_[0]);
my $cost_function = $_[1];
my $cycles_per_temperature = $_[2];
my $current_temperature;
my $lowest_cost;
lib/AI/SimulatedAnnealing.pm view on Meta::CPAN
} # end sub
# The validate_number_specs() function takes a reference to an array of
# number specifications (which are references to hashes with "LowerBound",
# "UpperBound", and "Precision" fields) and returns a reference to a version
# of the array in which bounds with higher precision than that specified
# have been rounded inward. If a number specification is not valid, the
# function calls "die" with an error message.
sub validate_number_specs {
my $raw_number_specs = $_[0];
my @processed_number_specs = @{ $raw_number_specs };
for my $number_spec (@processed_number_specs) {
my $lower_bound = $number_spec->{"LowerBound"};
my $upper_bound = $number_spec->{"UpperBound"};
my $precision = $number_spec->{"Precision"};
unless (looks_like_number($precision)
&& int($precision) == $precision
&& $precision >= 0 && $precision <= 4) {
die "ERROR: In a number specification, the precision must be "
. "an integer in the range 0 to 4.\n";
} # end unless
lib/AI/SimulatedAnnealing.pm view on Meta::CPAN
# Round the bounds inward as necessary:
my $integral_lower_bound = ceil( $lower_bound * (10 ** $precision));
my $integral_upper_bound = floor($upper_bound * (10 ** $precision));
$number_spec->{"LowerBound"}
= $integral_lower_bound / (10 ** $precision);
$number_spec->{"UpperBound"}
= $integral_upper_bound / (10 ** $precision);
} # next $number_spec
return \@processed_number_specs;
} # end sub
# Module return value:
1;
__END__
=head1 NAME
AI::SimulatedAnnealing - optimize a list of numbers according to a specified
cost function.
lib/AI/SimulatedAnnealing.pm view on Meta::CPAN
isn't already an integer). When the temperature reaches zero,
annealing is immediately terminated.
NOTE: Annealing can sometimes complete before the temperature
reaches zero if, after a particular temperature reduction, a
brute-force optimization approach (that is, testing every possible
combination of numbers within the subranges determined by the new
temperature) would produce a number of tests that is less than or
equal to the specified cycles per temperature. In that case, the
anneal() function performs the brute-force optimization to complete
the annealing process.
After a temperature reduction, the anneal() function determines each
new subrange such that the current optimal integer from the total
range is as close as possible to the center of the new subrange.
When there is a tie between two possible positions for the subrange
within the total range, a "coin flip" decides.
=head1 PREREQUISITES
This module requires Perl 5, version 5.10.1 or later.
( run in 0.288 second using v1.01-cache-2.11-cpan-8d75d55dd25 )