- 论坛徽章:
- 0
|
定义结构体
- 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;
- 在运行时:
- for (k=0; k<= pop_size-1; k++)
- {
- 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;
- }
- ……
复制代码
出错,请大虾帮我分析一下,是不是内存分配的原因,应该怎么分配,初学请指教。 |
|