January 8, 2012 - Leave a Response

Installing PIL for Google App Engine Windows 7

November 24, 2011 - Leave a Response
NotImplementedError: Unable to find the Python PIL library.

1)

There problem is that you have not installed PIL into Python25/Lib/site-packages/

Download it here

2)

If error still comes up, make sure to explicitly tell the development server (Google App Engine Launcher) which Python distribution you are using as you may have multiple installations of Python (2.5, 2.7 etc..) and it registered by default with a different distribution.

Go into Edit -> Preferences

In “Python Path”, specify path to Python exe : C:\Python25\pythonw.exe

Dawkins the weasel, and a program

November 12, 2009 - Leave a Response

Darwinian Evolution does not work, period. Below I have written (in about 1 hours time) Dawkins Weasel Evolutionary Algorithm.

I will explain more thoroughly why Darwinian Evolution is speculation coupled with wishful thinking.


#include
#include
#include
#include

#define ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
#define ALPHA_LENGTH 27

typedef enum { FALSE = 0, TRUE = 1 } boolean;

void upString(char *);
void mutate(char *, char *, int);
void shuffle(char *);
int randInt(int, int);
int fitness(char *);
boolean isLocked(char *);

char TARGET_STRING[100];
int TARGET_LENGTH;

int main(int argc, char **argv) {

 float rate = 0.0;
 FILE* file = (argv[1] == NULL) ? fopen("output.txt", "w") : fopen(argv[1], "w");

 if(file == NULL) {
    return 1;
 }

 fprintf(stdout,"\nEnter a target string:\t");gets(TARGET_STRING);

 fprintf(stdout,"\nEnter a mutation rate:\t");fscanf(stdin,"%f", &rate);

 TARGET_LENGTH = strlen(&TARGET_STRING[0]);

 float mutation_rate = ceil((rate / 100) * TARGET_LENGTH);int m_rate = (int)mutation_rate;

 upString(&TARGET_STRING[0]);

 char *current_ptr;
 char current[TARGET_LENGTH];

 current_ptr = &current[0];

 strcpy(&current_ptr[0], &TARGET_STRING[0]);

 shuffle(&current_ptr[0]);

 char *buffer_ptr;
 char buffer[TARGET_LENGTH];

 buffer_ptr = &buffer[0];

 int gen_count = 0;    char str_gc[100];
 int i;

 while(!isLocked(buffer_ptr)) {

 if (system("cls")) system("clear");

 mutate(current_ptr, buffer_ptr, m_rate);

 if(fitness(&buffer_ptr[0]) >= fitness(&current_ptr[0])) {
    strcpy(&current_ptr[0], &buffer_ptr[0]);
 }

 puts(current_ptr);
 fputs(current_ptr, file);
 fputs("\n", file);
 gen_count++;
 }

 fprintf(stdout,"\nNumber of trials to reach target: %d", gen_count);

 fputs("\n", file);
 fputs("\nNumber of trials to reach target: ", file);
 fputs(itoa(gen_count, str_gc, 10), file);

 fclose(file);

return 0;
}

void upString(char *string) {
 int i;
 for(i=0;i    string[i] = toupper(string[i]);
}

void mutate(char* cPtr, char* bPtr, int m_rate) {
 strcpy(&bPtr[0], &cPtr[0]);
 int i;
 for(i=0;i    bPtr[randInt(0, (TARGET_LENGTH - 1))] = ALPHABET[randInt(0,(ALPHA_LENGTH - 1))];
 }
}

void shuffle(char *string) {
 int j, k;
 for(j=0; j for(k=0; k   int r = randInt(0, TARGET_LENGTH - 1);
   int temp = string[k];

    string[k] = string[r];
    string[r] = temp;
 }
 }

}

int fitness(char *cString) {
 int i;int count = 0;
 for(i=0;i    if(*(cString + i) == TARGET_STRING[i]) {
    count++;
 }
 }
return count;
}

int randInt(int min, int max) {
 static int kState = 0;int i;
 if(kState == 0) {
   srand(time(NULL));
    kState = 1;
 }
 i = (rand() % (max - min + 1) + min);

return i;
}

boolean isLocked(char *curPtr) {
 boolean state = FALSE;
 if(strcmp(&curPtr[0], &TARGET_STRING[0]) == 0) {
   state = TRUE;
 }
return state;
}

Example output on string METHINKS DAWKINS IS A WEASEL

T SEAASMENQKAIWLSW IIS HDNE
T SEAASMENQKAIWLSW  IS HDNE
T SEAASMENQKJIWLSW  IS HDNE
K SEAASMENQKJIWLSW  IS HDNE
S SEAASMENQKJIWLSW  IS HDNE
S SEAASMENQKJIWLSW IIS HDNE
S SEAASMENQKJIWLSW IISRHDNE
G SEAASMENQKJIWLSW IISRHDNE
………
METHINKS DASKINS IS A WEASEL
METHINKS DAJKINS IS A WEASEL
METHINKS DAJKINS IS A WEASEL
METHINKS DAJKINS IS A WEASEL
METHINKS DAWKINS IS A WEASEL

Number of trials to reach target: 3703

Follow

Get every new post delivered to your Inbox.