求教!!!!!visual studio:写入位置 0x3e800000 时发生访问冲突
运行时出现:nsga2.exe 中的 0x00402f19 处未处理的异常: 0xC0000005: 写入位置 0x3e800000 时发生访问冲突。都说是指针问题,可是我就是看不出来哪的问题啊,代码贴上,在线等指导,非常感谢!!!!!!
/*This is the program used to evaluate the value of the function & errors
************************************************************************/
void func(population *pop_ptr);
void func(population *pop_ptr)
{
float *realx_ptr, /*Pointer to the array of x values*/
*binx_ptr, /* Pointer to the binary variables */
/*Pointer to the array of fitness function*/
x[2*maxvar], /* problem variables */
/*array of fitness values*/
*err_ptr, /*Pointer to the error */
cstr[maxcons];
int *gene_ptr;
float *fitn_ptr, f[maxfun];
int i,j,k,o;
float error, cc;
double Ec=32; //给定T,Q,C,R的极限值
double Eq=0.3; //给定T,Q,C,R的极限值
double Er=0.3; //给定T,Q,C,R的极限值
double Et=40; //给定T,Q,C,R的极限值
pop_ptr->ind_ptr= &(pop_ptr->ind[0]);
/*Initializing the max rank to zero*/
pop_ptr->maxrank = 0;
for(i = 0;i < popsize;i++)
{
pop_ptr->ind_ptr = &(pop_ptr->ind[i]);
realx_ptr = &(pop_ptr->ind_ptr->xreal[0]);
gene_ptr = &(pop_ptr->ind_ptr->genes[0]);
for(j = 0; j < nvar; j++)
{ // Real-coded variables
x[j] = *realx_ptr++; //每个个体
}
for(j = 0; j < chrom; j++)
{ // Binary-codced variables
x[nvar+j] = *gene_ptr++; ////指向每个基因
}
fitn_ptr= &(pop_ptr->ind_ptr->fitness[0]);
err_ptr = &(pop_ptr->ind_ptr->error);
f[0]=0;
f[1]=0;
f[2]=0;
f[3]=0;
for(o=0;o<chrom;o++)
{
if(x[o]==1)
{
f[0]+=T[o]+transT[o];
f[1]+=Q[o]*q[o];
f[2]+=C[o]+transC[o];
if(f[3]<R[o])
{ f[o]=R[o];}
}
}
f[0]=(f[0]/Et);
f[1]=(f[1]/Eq);
f[2]=(f[2]/Ec);
f[3]=(f[3]/Er);
for(k = 0 ; k < nfunc ;k++)
{
*(fitn_ptr+k)=f[k]; !!!!!!!!!!!!!!!!!!运行时候就停在这一行
}
for (k = 0;k < ncons; k++)
{
pop_ptr->ind_ptr->constr[k] = cstr[k];
}
error = 0.0;
for (k = 0;k < ncons;k++)
{
cc = cstr[k];
if(cc < 0.0)
error = error - cc;
}
*err_ptr = error;
}
/*---------------------------* RANKING *------------------------------*/
if(ncons == 0)
ranking(pop_ptr);
else
rankcon(pop_ptr);
return;
}