Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
68
Task/Evolutionary-algorithm/Aime/evolutionary-algorithm.aime
Normal file
68
Task/Evolutionary-algorithm/Aime/evolutionary-algorithm.aime
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
integer
|
||||
fitness(data t, data b)
|
||||
{
|
||||
integer c, f, i;
|
||||
|
||||
f = 0;
|
||||
|
||||
for (i, c in b) {
|
||||
f += sign(t[i] ^ c);
|
||||
}
|
||||
|
||||
f;
|
||||
}
|
||||
|
||||
void
|
||||
mutate(data e, data b, data u)
|
||||
{
|
||||
integer c;
|
||||
|
||||
for (, c in b) {
|
||||
e.append(drand(15) ? c : u[drand(26)]);
|
||||
}
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
data b, t, u;
|
||||
integer f, i;
|
||||
|
||||
t = "METHINK IT IS LIKE A WEASEL";
|
||||
u = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
|
||||
|
||||
i = ~t;
|
||||
while (i) {
|
||||
i -= 1;
|
||||
b.append(u[drand(26)]);
|
||||
}
|
||||
|
||||
f = fitness(t, b);
|
||||
while (f) {
|
||||
data n;
|
||||
integer a;
|
||||
|
||||
o_form("/lw4/~\n", f, b);
|
||||
|
||||
n = b;
|
||||
|
||||
i = 32;
|
||||
while (i) {
|
||||
data c;
|
||||
|
||||
i -= 1;
|
||||
mutate(c, b, u);
|
||||
a = fitness(t, c);
|
||||
if (a < f) {
|
||||
f = a;
|
||||
n = c;
|
||||
}
|
||||
}
|
||||
|
||||
b = n;
|
||||
}
|
||||
|
||||
o_form("/lw4/~\n", f, b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue