Hi
I run a c++ program in VC++ 2008 expression edition. The program was running perpectly in VC++ 6.0 edition. But when i execute the program in VC++ 2008 expression edition, the following error is shown

Debug assertion failed
Expression: Vector subscription out of range.

I define the two dimentional vector in the follwing way

vector<vector<int> > maclu;
maclu1.resize(nclus);
for(i=0;i<nclus;i++)
maclu1.resize( m );


Please help me to solve this issue.

Could you show more of the surrounding code? (any data that's put into the vectors beforehand)

VC++ 6.0 has a compiler that is much less standards compliant than the more recent ones, so it's no surprise that 2008 kicked out the code and 6.0 didn't.

I do not believe that you are showing us the actual code. My reason for this disbelief is that you define a variable named maclu but then you use a variable named maclu1 . In order for this code to work, therefore, you must have defined maclu1 somewhere, but you have not shown us where.

My programe is very lengthly to give here. I give here a part of my code where the error occurs.

To my surprise the code run for first iteration in a particular loop, duirng the second itertion, the error is shown.

In the function heuristics
The loop while (temBest>temBest1) is run for the first time without error, during second time
The error is shown at line 56, ie when the function
TransAssign(tempMachiClus,tempComClus,tcn1) is called

Please let me clear that i have defined all the variables in the complete programme. I did not prove that part due to the length of the code.

//local heuristic to improve the quality of the ant solution
float objective::heuristic(vector<int> &tbs1, vector<vector<int> > &ttclus1, vector<int> &tcn1, vector<int> &tnmachi1)
{
	
	counter1++;
	int i,j;
	float temBest; int temp1, temp2; 	
	float temBest1=0.0f; 
	VectorResize(m,n);
	inverse=0;
	//assignment of machine cluster
	for( i=0;i<nclus;i++)
	{
		for(j=0;ttclus1[i][j]!=0;j++)
		{
			tempMachiClus[i][j]=ttclus1[i][j];	
		}
		tempMachiClus[i][j]=0;
	}
	//assignment of best solutuion
	for(i=0;i<m;i++)
	{
		tempBestSol[i]=tbs1[i];
	}
	//assignment of number of machines
	for(i=0; i<nclus; i++)
	{
		numItem[i]=tnmachi1[i];
	}
	temBest=cal_object(tempBestSol,tempMachiClus,tcn1,numItem,tempComClus);

	AssignCompclus(ttclus1,comp.tcoclu);
	//Generation of seed solution
	for(i=0;i<nclus;i++)
	{
		for( j=0;ttclus1[i][j]!=0;j++)
		{
		      int temp=ttclus1[i][j];
			bs1[temp-1]=tcn1[i];
		}
		tnmachi1[i]=j;

	}

	while (temBest>temBest1)
	{
	//Assignment of machine cluster
	temBest1=temBest;
	inverse=(inverse==1)? 0:1;
	temp1=(inverse==0)? m:n;
	temp2=(inverse==0)? n:m;
	VectorResize(temp1,temp2);
	if(inverse==1)
	{
          	TransAssign(tempMachiClus,tempComClus,tcn1);
		
	}
	temBest=cal_object(tempBestSol,tempMachiClus,tcn1,numItem,tempComClus);
	if(temBest>temBest1)
	{
		VectorResize(m,n);
		if(inverse==0)
		{
			AssignCompclus(ttclus1,comp.tcoclu);
			//Generation of seed solution
			for(i=0;i<nclus;i++)
			{
				for( j=0;ttclus1[i][j]!=0;j++)
	            		{
					int temp=ttclus1[i][j];
					tbs1[temp-1]=tcn1[i];
				}
		          	tnmachi1[i]=j;
			}
		}
		else
		{
			AssignCompclus(comp.tcoclu,ttclus1);
			//Generation of seed solution
			for( i=0;i<nclus;i++)
			{
          			for( j=0;ttclus1[i][j]!=0;j++)
	          		{
					int temp=ttclus1[i][j];
					tbs1[temp-1]=tcn1[i];
				}
				tnmachi1[i]=j;
			}
		}	
	}
	//temBest=cal_object(tempBestSol,tempMachiClus,tcn1,numItem,tempComClus);
     }
     return temBest1;
}
//Resizing the vector according to the position of the machine component incident matrix
void objective::VectorResize(int count, int count1)
{

	int i;
	tempBestSol.resize(count);
	numItem.resize(nclus);
	//memory allocation for tempMachiClus
	tempMachiClus.resize(nclus);
	for( i=0; i<nclus; i++)
		tempMachiClus[i].resize(count);	
	//memory allocation for tempComClus
	tempComClus.resize(nclus);
	for(i=0; i<nclus; i++)
		tempComClus[i].resize(count1);
	//allocating memory for temporary machine number
	comp.tmachi.resize(count1);
	/*if(count==m)
	{
		comp.tmachi.resize(n);
	}
	else
	{
		comp.tmachi.resize(m);
	}*/

}
//selection of either machine cluster or component cluster
void objective::TransAssign(vector<vector<int> > &tempMachiClus,vector<vector<int> > &tempComClus,vector<int> &tcn1)
{

	int i,j,temp;
	
	for( i=0;i<nclus;i++)
	{
		for(j=0;tempComClus[i][j]!=0;j++)
		{
			tempMachiClus[i][j]=tempComClus[i][j];	
		}
		tempMachiClus[i][j]=0;
		numItem[i]=j;					//assignment of number of items
	}
	for(i=0;i<nclus;i++)
	{
		for(j=0;tempMachiClus[i][j]!=0;j++)
		{
			temp=tempMachiClus[i][j];
			tempBestSol[temp-1]=tcn1[i];
		}

	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.