As halley pointed out to me in node 433726, there is in fact a way to avoid the necessity of changing AI::Genetic at all, though it requires a small use of prototyping, which I know you abhor, to make it work.
In my version, you just have to write the make_config sub like this:
sub make_config {
my (@genes) = @_;
# sort classes in order by genes:
# stupid #!@#!#$! sort bug
my $sortsub = sub ($$) {
my ($a,$b) = @_;
$genes[$a] <=> $genes[$b];
};
my (@sclasses) = @CLASSES[sort $sortsub (0..$#CLASSES)];
push(@sclasses, (qw{XXX}) x ($SLOTS * $ROOMS));
my ($config) = [];
for my $s (0..$SLOTS-1) {
push @$config, [];
for my $r (0..$ROOMS-1) {
my $i=0;
while (!is_acceptable($sclasses[$i],$s,$r,$config)) {$i++;}
push @{$config->[-1]}, splice(@sclasses,$i,1);
}
}
$config;
}
--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/;
map{y/X_/\n /;print}map{pop@$_}@/for@/
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|