[ create a new paste ] login | about

Link: http://codepad.org/RWrPSXiE    [ raw code | output | fork | 1 comment ]

C++, pasted on Sep 11:
/* 
 * File:   main.cpp
 *
 * Created on September 7, 2011, 11:10 AM
 */

//Big Pic:
//Randomly determine the starting pool. 
//Generational with elitism. Top parents survive, everyone else is replaced. repeat.

//My representation solution or genotype is a float array of length 30. Each float can take a different value between -65.536 and 65.536. The phenotype is a collection of 30 variables. The objective is to minimize that string.


#include <cstdlib>
#include <iostream>
#include <time.h>

using namespace std;

class Genotype {
public:
    float solution[30]; //30 variable solution.
    float fitness; // a score of the fitness
};
const int populationSize = 10; // population of 10;
Genotype individual[populationSize]; //population of individuals
void fitnessScore(Genotype individual[]);
srand(time(NULL));

int main() {
    //Randomize initial population first gen parents
    for (int i = 0; i < populationSize; i++) { // population of 10
        for (int j = 0; j < 30; j++) {
            individual[i].solution[j] = ((rand() % 1000) / 100.0) - 5.0; // quick fix randomish value between -5 and 5 ~ supposed to have been -5.12 to 5.12
        }

    }

    //evaluate fitness of first gen parents ie the value of the sum squared
    fitnessScore(Genotype individual);


    //breed good parents together



    return 0;
}

void crossover() {

}

void fitnessScore(Genotype individual[]) { // This will be where I plug in the different benchmark problems
    float fitness(0);
    for (int i = 0; i < populationSize; i++) { // population of 10
        for (int j = 0; j < 30; j++) { // p of 30
            fitness += individual[i].solution[j]*individual[i].solution[j];
        }
        individual[i].fitness = fitness;
    }
}

void mutation() {

}


Output:
1
2
Line 28: error: expected constructor, destructor, or type conversion before '(' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments:
posted by FrogCity on Sep 11
What is the proper way to pass a class into a function?
reply