- 论坛徽章:
- 0
|
求教结构体问题(急)
原帖由 "Aragorn" 发表:
你是学什么的? 这是用于哪方面的寻优? - typedef struct indiv
- { float x[MAXVECSIZE]; /* variables */
- float obj; /* objective fn. value */
- float mod_obj; /* modified objective */
- unsigned *chrom; /* chrosome string */
- int parent1;
- int parent2; /* s.no. of parents */
- float cross_var; /* cross over variable */
- }INDIVIDUAL;
- typedef struct pop
- {
- INDIVIDUAL *individual; /* indiv of each populatin */
- int pop_id; /* the ID of the poputation in the multi-pop~. */
- float x_pop_lower[MAXVECSIZE];
- float x_pop_upper[MAXVECSIZE];
- }POPULATION;
- POPULATION *oldpop, *newpop;
- ..........
- oldpop = (POPULATION *)malloc(pop_size*sizeof(POPULATION));
- newpop = (POPULATION *)malloc(pop_size*sizeof(POPULATION));
- for (k=0; k<= pop_size-1; k++)
- {
- oldpop[i].individual = (INDIVIDUAL*) malloc(indiv_size*sizeof(INDIVIDUAL));
- newpop[i].individual = (INDIVIDUAL*) malloc(indiv_size*sizeof(INDIVIDUAL));
- for (l=0; l<= indiv_size-1; l++)
- {
- oldpop[k].individual[l].parent1 = oldpop[k].individual[l].parent2 = 0;
- for (j=0; j<=num_var-1; j++)
- {
- u = randomperc();
- oldpop[k].individual[l].x[j] = x_lower[j] * (1-u) + x_upper[j] * u;
- }
- ..........
- 修改后的这样,但是还是执行到
- oldpop[i].individual = (INDIVIDUAL*) malloc(indiv_size*sizeof(INDIVIDUAL)); 出错,是不是我定义的population 类型的指针newpop,和oldpop,不能用 oldpop[i].individual 这么访问,不过我觉应该没问题的。
- 谢谢。
复制代码 |
|