Your skill will accomplishwhat the force of many cannot PerlMonks

### Comment on

 Need Help??
Here is how I understand the terminology, so that we don't talk past each other. Please let me know if I get it wrong.

A 'gene' has a 'name' and a 'value'. A set of genes values is a 'person'. This person has a single number for 'fitness'. Fitness can be computed from the values of the genes. The end result of evolution process is the most fit person.

In this problem a person represents an entire schedule. The genes are the individual schedule entries. There are stringent restrictions on the data types for the genes. One hard part of using a genetic algorithms is the work needed to map the problem space into the limited data types of the GA package.

The fitness evaluator looks at the person and sees how well it satisfies the student sign-ups and other constraints. Efficienty of the fitness evaluator is important. Any tests that disqualify a particular person can be checked first. In these cases the fitness is zero and the routine can use a short-cut return, without evaluating all the other fitness criteria.

I tried your first suggested solution, where the genes represent the timeslots for each classroom, and the values are the class for that slot. This way of doing it moves the complexity away from the mapping problem into the fitness evaluation function, where I think it is much easier to deal with.

In my trivial example a single instructor sequentially teaches two different classes out of a possible three classes. One class will be cancelled due to 'lack of interest'. The students can sign up for one or two classes and can optionally specify a priority of 1 or 2. The three classes are called 'genetic', 'neural', and 'fuzzy'.

```use strict;
use warnings;
use AI::Genetic;

my %signup;
\$signup{bob}{genetic}   = 2;
\$signup{ted}{genetic}   = 1;
\$signup{alice}{genetic} = 1;
\$signup{carol}{genetic} = 0;
\$signup{joe}{genetic}   = 0;
\$signup{biff}{genetic}  = 0;
\$signup{sneezy}{genetic}= 0;

\$signup{bob}{neural}   = 0;
\$signup{ted}{neural}   = 0;
\$signup{alice}{neural} = 1;
\$signup{carol}{neural} = 2;
\$signup{joe}{neural}   = 1;
\$signup{biff}{neural}  = 1;
\$signup{sneezy}{neural}= 0;

\$signup{bob}{fuzzy}   = 0;
\$signup{ted}{fuzzy}   = 1;
\$signup{alice}{fuzzy} = 0;
\$signup{carol}{fuzzy} = 1;
\$signup{joe}{fuzzy}   = 0;
\$signup{biff}{fuzzy}  = 0;
\$signup{sneezy}{fuzzy}= 2;

my \$generations= 0;

sub fitness
{
my (\$classes)= @_;
my \$class1= \$classes->[0];
my \$class2= \$classes->[1];
return 0 if \$class1 eq \$class2;
my \$fitness=0;
foreach my \$student_name (keys %signup)
{
if (\$signup{\$student_name}{\$class1} > \$signup{\$student_name}{\$clas
+s2})
{
\$fitness += \$signup{\$student_name}{\$class1};
}
else
{
\$fitness += \$signup{\$student_name}{\$class2};
}
}
return \$fitness;
}

my \$ga = new AI::Genetic(
-fitness    => \&fitness,
-type       => 'listvector',
-population => 500,
-crossover  => 0.9,
-mutation   => 0.01,
-terminate  => sub { \$generations++;
return 1 if \$generations > 100;
return 0 },
);
\$ga->init([
[qw/genetic neural fuzzy/ ],
[qw/genetic neural fuzzy/ ],
]);
\$ga->evolve('rouletteTwoPoint', 100);
print "Best score = ", \$ga->getFittest->score, ".\n";
print "Best genes = ", join(' ',\$ga->getFittest->genes), ".\n";

It should work perfectly the first time! - toma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-05-27 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (194 votes). Check out past polls.

Notices?