AI-SimulatedAnnealing

 view release on metacpan or  search on metacpan

t/annealing_tests.t  view on Meta::CPAN

#!/usr/bin/perl

####
# annealing_tests.t:  Test the AI::SimulatedAnnealing module.
#
# Usage:
#
#     perl -w annealing_tests.t market_distances.csv
####
use 5.010001;
use strict;
use warnings;
use utf8;

use English "-no_match_vars";
use List::Util ("max", "min");

use AI::SimulatedAnnealing;
use Text::BSV::BsvFileReader;

# Probability enumeration:
package Probability;

our $ONE_FIFTH  = 5;
our $ONE_FOURTH = 4;
our $ONE_THIRD  = 3;
our $ONE_HALF   = 2;

# Redeclaration of the main package:
package main;

# Constants:
my $POUND     = "#";
my $SQ        = "'";
my $DQ        = "\"";
my $SEMICOLON = ";";
my $CR        = "\r";
my $LF        = "\n";
my $SPACE     = " ";
my $EMPTY     = "";
my $TRUE      = 1;
my $FALSE     = 0;

my $CYCLES_PER_TEMPERATURE = 1_250;

# Main script:

# Get the input file path:
my $bsv_file_path = $ARGV[0];

unless (scalar @ARGV) {
    die "ERROR:  No command-line argumment.  Please provide the path to a "
      . "valid BSV (or simple CSV) file containing market distances.\n";
} # end unless

# Create a reader for the BSV file:
my $bsv_file_reader;

eval {
    $bsv_file_reader = Text::BSV::BsvFileReader->new($bsv_file_path);
};

if ($EVAL_ERROR) {
    my $exception = $EVAL_ERROR;

    given ($exception->get_type()) {
        when ($Text::BSV::Exception::FILE_NOT_FOUND) {
            say STDERR "$DQ$bsv_file_path$DQ is not a valid file path.";
            exit(1);
        }
        when ($Text::BSV::Exception::IO_ERROR) {
            say STDERR "Couldn't open $DQ$bsv_file_path$DQ for reading.";
            exit(1);



( run in 2.146 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )