"expected an expression"

hello, i have this bug, evaluate functions are declared but every time i call it
there is an error. if you see please tell me what is wrong
thank you!


#include<iostream>
#include<ctime>
#include<random>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int maxgeneration = 100;
const int popsize = 50;
const int mutation = 1;
const double crossover = 0.8; // unused
const int gensize = 20;
const int vl = 0;
const int vu = 4;


default_random_engine dre(time(0));
uniform_int_distribution<int> di(vl, vu);
int k = di(dre);

struct phage;
struct bacteria {
int fitness = 0;
int m[gensize] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
void evaluate(phage pa[]);

void init() {
for (int i = 0; i<gensize; i++)
m[i] = di(dre);
}
void show() {
{
for (int i = 0; i<gensize; i++)
cout << m[i];
}
cout << endl << endl;
}
}b;
struct phage {


int fitness = 0;

int m[gensize] = { 1,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,1,0 };

void evaluate(bacteria ba[]) {

for (int i = 0; i<popsize; i++)
for(int j=0; j<gensize; j++)
fitness += m[i] == ba[i].m[j];
}


void init() {
for (int i = 0; i<gensize; i++)
m[i] = di(dre);
}
void show() {
{
for (int i = 0; i<gensize; i++)
cout << m[i];
}
cout << endl << endl;
}
}b1;
void bacteria :: evaluate(phage pa[]) {
for (int i = 0; i<popsize; i++)
for (int j = 0; j<gensize; j++)
fitness += m[i] == pa[i].m[j];
}



// pg is time

default_random_engine dre1(time(0));
uniform_int_distribution <int> di1(0, 19);


default_random_engine dre2(time(0)); // albatobistvis
uniform_int_distribution<int> di2(1, 100);

default_random_engine dre3(time(0)); // mutaciistvis
uniform_int_distribution<int> di3(vl, vu);

// pg is time


phage crosmut(phage p1, phage p2) {
phage shvili;
// krosoveri
for (int i = 0; i < gensize; i++)
shvili.m[i] = -1;

int k = di1(dre);

int k1 = di1(dre);

for (int i = 0; i < k1; i++)
shvili.m[i] = p1.m[i];

for (int i = k1; i < gensize; i++)
shvili.m[i] = p2.m[i];
// mutacia





for (int i = 0; i < gensize; i++)
if (di2(dre2) <= mutation) shvili.m[i] = di3(dre3);



return shvili;
}


void pg(phage population[]) {




for (int i = popsize / 2; i < (popsize / 2) + (popsize / 4); i++)
population[i] = population[popsize - 1];



for (int i = (popsize / 2) + (popsize / 4); i < popsize - 1; i++)
population[i] = crosmut(population[popsize - 2], population[popsize - 3]);


for (int i = 2; i < popsize; i++)
population[i].fitness = 0;

for (int i = 0; i < popsize; i++)
population[i].evaluate(population[]);

sort(population, population + popsize, [](phage p, phage p1) {return p.fitness < p1.fitness; });
}

bacteria crosmut(bacteria p1, bacteria p2) {
bacteria shvili;

for (int i = 0; i < gensize; i++)
shvili.m[i] = -1;

int k = di1(dre);

int k1 = di1(dre);

for (int i = 0; i < k1; i++)
shvili.m[i] = p1.m[i];

for (int i = k1; i < gensize; i++)
shvili.m[i] = p2.m[i];





for (int i = 0; i < gensize; i++)
if (di2(dre2) <= mutation) shvili.m[i] = di3(dre3);



return shvili;
}


void pg(bacteria population1[]) {




for (int i = popsize / 2; i < (popsize / 2) + (popsize / 4); i++)
population1[i] = population1[popsize - 1];



for (int i = (popsize / 2) + (popsize / 4); i < popsize - 1; i++)
population1[i] = crosmut(population1[popsize - 2], population1[popsize - 3]);


for (int i = 2; i < popsize; i++)
population1[i].fitness = 0;

for (int i = 0; i < popsize; i++)
population1[i].evaluate(population1[]);



sort(population1, population1 + popsize, [](bacteria p, bacteria p1) {return p.fitness < p1.fitness; });
}

int main() {
bacteria population1[popsize];
for (int i = 0; i < popsize; i++)
population1[i].init();


for (int i = 0; i < popsize; i++)
population1[i].evaluate(population1[]); // it does not work
sort(population1, population1 + popsize, [](bacteria p, bacteria p1) {return p.fitness < p1.fitness; });

for (int i = 0; i <maxgeneration; i++) {
cout << population1[popsize - 1].fitness << endl;
population1[popsize - 1].show();
pg(population1); // population
cout << population1[popsize - 1].fitness << endl;
population1[popsize - 1].show();
}

cout << "phage" << endl;

phage population[popsize];
for (int i = 0; i < popsize; i++)
population[i].init();


for (int i = 0; i < popsize; i++)
population[i].evaluate(b);
sort(population, population + popsize, [](phage p, phage p1) {return p.fitness < p1.fitness; });

for (int i = 0; i <maxgeneration; i++) {
cout << population[popsize - 1].fitness << endl;
population[popsize - 1].show();
pg(population); // population
cout << population[popsize - 1].fitness << endl;
population[popsize - 1].show();
}

}
http://www.cplusplus.com/forum/general/195154/

Hi,

Please don't start a new post about the same subject. It is ultimately a time water for those who reply.

Also, please always use code tags and indent the code properly: http://www.cplusplus.com/articles/z13hAqkS/
Amongst other things it provides line numbers.

if you see please tell me what is wrong
thank you!


If you pasted the exact error and the line number on which it occurred, that would help a great deal. My crystal ball is on vacation at the moment :+)
The first error that my compiler found is that a primary expression is expected before "]" in line 133.

Maybe it has something to do with your phage struct not containing:
1
2
3
4
    void evaluate(phage bla[])
    {
              fitness = 42;
    }


While you are calling a function with the footprint "void evaluate(phage bla[])" that is supposed to be a member of struct population[i] and population[i] is a phage struct.

But like TheIdeasMan pointed out, it could be that you are looking for something completely different because you did not tell us what error you are having trouble with.

Kind regards, Nico
population[i].evaluate(population []);

The population[] is incorrect. If you're using the square brackets outside of initialization, they should always surround an index into the array. If you're passing an array into a function, there is no reason to use the brackets at all: xx.evaluate(population);.

Of course, that's going to cause you problems too, as Nico noted. elements of population are of type phage and phage doesn't have an evaluate function that takes an array of phage elements.
Topic archived. No new replies allowed.