Can't figure out a vector<struct> error
Aug 7, 2010 at 2:31am UTC
I'm learning genetic algorithms and have started writing a program to test some stuff out. Right now all the program does is seed a struct and push it into a vector. Any clue as to what is causing this linking error. I'm usually visual express 2008.
error LNK2019: unresolved external symbol impCrtDbgReportW referenced in function "public: struct gastruct & thiscall std::vector<struct gastruct,class std::allocator<struct gastruct> >::operator[](unsigned int)" (??A?$vector@Ugastruct@@V?$allocator@Ugastruct@@@std@@@std@@QAEAAUga_struct@@I@Z)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
#include "SDL.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <time.h>
#include <math.h>
define GA_POPSIZE 2048 // ga population size
define GA_MAXITER 16384 // maximum iterations
define GA_MUTATIONRATE .05f // mutation percentage rate
define GA_TARGET 60 // top fitness
define GA_MOVES 80 // movement points
using namespace std;
struct ga_struct {
string str;
unsigned int fitness;
float matingPossiblity;
};
typedef vector<ga_struct> ga_vector;
void init_population(ga_vector &population) {
int tsize = GA_MOVES * 3;
int psize = GA_POPSIZE;
for (int i = 0; i < psize; i++)
{
ga_struct citizen;
citizen.fitness = 0;
citizen.matingPossiblity = 0.0f;
citizen.str.erase();
for (int j = 0; j < tsize; j++)
citizen.str.at(j) = (rand() % 2) + 48;
population.push_back(citizen);
}
}
void calc_fitness(ga_vector &population) {
// do nothing
}
void sort_fitness(ga_vector &population) {
// do nothing
}
void mutate(ga_vector &member) {
int tsize = GA_MOVES * 3;
int psize = GA_POPSIZE;
double mutation = GA_MUTATIONRATE * 100.0;
int random = 0;
for (int j = 0; j < psize; j++)
{
for (int i = 0;i < tsize; i++)
{
random = (rand() % 100) + 1;
if (random < mutation)
{
if (member[j].str.at(i) == '0' )
member[j].str.at(i) = '1' ;
else
member[j].str.at(i) = '0' ;
}
}
}
}
void mate(ga_vector &population) {
// do nothing at this time
}
void draw_best(ga_vector &population) {
// do nothing at this time
}
int main( int argc, char * args[] ) {
//Start SDL
SDL_Init(SDL_INIT_VIDEO);
srand(unsigned (time(NULL)));
ga_vector pop_alpha;
ga_vector *population;
init_population(pop_alpha);
population = &pop_alpha;
// game loop
for ( int i = 0; i < GA_MAXITER; i++)
{
calc_fitness(*population);
sort_fitness(*population);
draw_best(*population);
// if((*population)[0].fitness == 100)
// break;
mate(*population);
mutate(*population);
}
// move between best fitness screen
//Quit SDL
SDL_Quit();
return 0;
}
Thank you for any help and thank you for at least reading over it.
Topic archived. No new replies allowed.