[gecode-users] Access Violation when reading of the location

Guido Tack tack at gecode.org
Wed Dec 4 07:35:37 CET 2013


That's an internal function, you don't have to understand what it does. The point is that it accesses a variable that has either not been initialised  in the constructor or not been updated in the copy constructor.

Cheers,
Guido

On 4 Dec 2013, at 3:37 pm, lana light <lanalight1989 at gmail.com> wrote:

> thank you 
> 
> i did that but i get the some error !!!!!
> 
> any way what  does this function do because the compiler reffers to it 
> 
>  IntVarImp::RangeList::min(void) const {
>     return _min;
>   }
> 
> thank you very much Lana 
> 
> 
> 2013/12/4 Guido Tack <tack at gecode.org>
> You have to update gain1 in your constructor for cloning.
> 
> Cheers,
> Guido
> 
> On 4 Dec 2013, at 1:08 pm, lana light <lanalight1989 at gmail.com> wrote:
> 
>> hi all!
>> 
>> So sorry to bother you , but  this is my first model with gecode , when i run it it gave m this errer: "Access Violation when reading of the location0x0000001c"
>> 
>> and the compiler redirect me to this function in int.hpp 
>> IntVarImp::RangeList::min(void) const {
>>     return _min;
>>   }
>>   here is my code : 
>> 
>> #include <gecode/driver.hh>
>> #include <gecode/int.hh>
>> #include <gecode/minimodel.hh>
>> #include <iostream>
>> 
>> 
>> #include <vector>
>> using namespace Gecode;
>> using namespace std;
>> class manel : public MaximizeScript {
>> protected:
>> 		 
>>   IntVar gain1;
>> 
>>   static const int n=6;//nbre des testeurs 
>>   static const int m=6;//  nbre des noeuds
>> 		IntVarArray a;
>>  
>> public:
>>   manel(void)
>> 	  : a(*this,m*n,0,1),gain1(*this,0,100000) {
>> 
>> 		Matrix <IntVarArray> X (a,m,n);
>> 
>> 		
>> 			vector<int> R1;
>> 			R1.push_back(20);R1.push_back(10);R1.push_back(15);R1.push_back(5);R1.push_back(25);R1.push_back(30);
>> 			
>> 	    vector<int> C1;
>> 		    C1.push_back(50);C1.push_back(30);C1.push_back(15);C1.push_back(15);C1.push_back(60);C1.push_back(20);
>>         vector<int> B1;
>> 		    B1.push_back(10);B1.push_back(15);B1.push_back(40);B1.push_back(50);B1.push_back(60);B1.push_back(70);
>> 
>> 		vector<int> Dr1;
>> 		    Dr1.push_back(1);Dr1.push_back(1);Dr1.push_back(10);Dr1.push_back(5);Dr1.push_back(15);Dr1.push_back(15);
>> 		vector<int> Dc1;
>> 		    Dc1.push_back(1);Dc1.push_back(2);Dc1.push_back(20);Dc1.push_back(15);Dc1.push_back(15);Dc1.push_back(15);
>> 		vector<int> Db1;
>> 		    Db1.push_back(1);Db1.push_back(2);Db1.push_back(10);Db1.push_back(10);Db1.push_back(20);Db1.push_back(20);
>> 		/*int g [n][m] ;
>> 			//for(unsigned int i=0; i < n; ++i)
>>             // g.emplace_back(std::vector<int>(m));
>> 			g[0][0]=125;g[0][1]=150;g[0][2]=1;g[0][3]=0;g[0][4]=0;g[0][5]=0;
>> 			g[1][0]=125;g[1][1]=150;g[1][2]=1;g[1][3]=0;g[1][4]=0;g[1][5]=0;
>> 			g[2][0]=125;g[2][1]=150;g[2][2]=1;g[2][3]=0;g[2][4]=0;g[2][5]=0;
>> 			g[3][0]=125;g[3][1]=150;g[3][2]=1;g[3][3]=0;g[3][4]=0;g[3][5]=0;
>> 			g[4][0]=125;g[4][1]=150;g[4][2]=1;g[4][3]=0;g[4][4]=0;g[4][5]=0;
>> 			g[5][0]=125;g[5][1]=150;g[5][2]=1;g[5][3]=0;g[5][4]=0;g[5][5]=0;
>> 		/*for(int i=0; i<n; i++)
>> 		{
>> 			for (int j =0; j<m;j++)
>> 				g[i][j]=50;
>> 		}*/
>> 			//creation of constraints 
>> 			// ... over rows
>> 		
>> 		for ( int j=0; j<n;j++)
>> 		{
>> 
>> 				linear(*this , X.row(j),IRT_EQ,1);
>> 			
>> 		}
>> 
>> 		//... over columns
>> 			
>> 		         for (int i = 0; i < m; i++) {
>> 
>> 					 linear(*this, Dr1,X.col(i),IRT_LQ,R1[i]);
>> 		                                     }
>> 
>> 		        for (int i = 0; i < m; i++) {
>> 		           	linear (*this, Dc1, X.col(i), IRT_LQ,C1[i]);
>> 
>> 		                                 }
>> 		
>> 		         for (int i = 0; i <m; i++) {
>> 			         linear (*this, Db1, X.col(i), IRT_LQ,B1[i]);
>> 			
>> 		                           }
>> 	
>> 
>> 		
>> 				 //objectiv function
>> 				/* IntArgs res(m*n);
>> 				 IntVarArgs X1(m*n);
>> 				 IntVarArgs f(n*m);
>> 				 IntVar z;
>> 				 int count=0;
>> 				  int count1=0;
>> 				  int count2=0;
>> 				  int count3=0;
>> 				 
>>                  //for (int i=0; i<n; i++)
>> 		             //{
>> 						 
>>                          //for (int j=0; j<m; j++) 
>> 	            
>> 				          // {
>> 							  
>> 							/* res[0] = g[0][0];
>> 							 X1[0] = X(0,0);
>> 							  z =expr(*this,res[0]*X1[0]);
>> 							 f[0]=z;
>> 
>> 							  res[1] = g[0][1];
>> 							 X1[1] = X(0,1);
>> 							  z =expr(*this,res[1]*X1[1]);
>> 							 f[1]=z;
>> 							  
>> 							  res[2] = g[0][2];
>> 							 X1[2] = X(0,2);
>> 							  z =expr(*this,res[2]*X1[2]);
>> 							 f[2]=z;
>> 
>> 							  res[3] = g[0][3];
>> 							 X1[3] = X(0,3);
>> 							  z =expr(*this,res[3]*X1[3]);
>> 							 f[3]=z;
>> 
>>                              res[4] = g[0][4];
>> 							 X1[4] = X(0,4);
>> 							  z =expr(*this,res[4]*X1[4]);
>> 							 f[4]=z;
>> 
>> 							  res[5] = g[0][5];
>> 							 X1[5] = X(0,5);
>> 							  z =expr(*this,res[5]*X1[5]);
>> 							 f[5]=z;
>> 							  //////////////////////////////////////////////////////
>> 							  res[6] = g[1][0];
>> 							 X1[6] = X(1,0);
>> 							  z =expr(*this,res[6]*X1[6]);
>> 							 f[6]=z;
>> 
>> 							  res[7] = g[1][1];
>> 							 X1[7] = X(1,1);
>> 							  z =expr(*this,res[7]*X1[7]);
>> 							 f[7]=z;
>> 
>> 							 res[8] = g[1][2];
>> 							 X1[8] = X(1,2);
>> 							  z =expr(*this,res[8]*X1[8]);
>> 							 f[8]=z;
>> 
>> 							  res[9] = g[1][3];
>> 							 X1[9] = X(1,3);
>> 							  z =expr(*this,res[9]*X1[9]);
>> 							 f[9]=z;
>> 							  
>> 							  res[10] = g[1][4];
>> 							 X1[10] = X(1,4);
>> 							  z =expr(*this,res[10]*X1[10]);
>> 							 f[10]=z;
>> 
>> 							  res[11] = g[1][5];
>> 							 X1[11] = X(1,5);
>> 							  z =expr(*this,res[11]*X1[11]);
>> 							 f[11]=z;
>> 							 ///////////////////////////////////////////////////////////////////////
>> 							 res[12] = g[2][0];
>> 							 X1[12] = X(2,0);
>> 							  z =expr(*this,res[12]*X1[12]);
>> 							 f[12]=z;
>> 
>> 							  res[13] = g[2][1];
>> 							 X1[13] = X(2,1);
>> 							  z =expr(*this,res[13]*X1[13]);
>> 							 f[13]=z;
>> 							  
>> 							  res[14] = g[2][2];
>> 							 X1[14] = X(2,2);
>> 							  z =expr(*this,res[14]*X1[14]);
>> 							 f[14]=z;
>> 
>> 							  res[15] = g[2][3];
>> 							 X1[15] = X(2,3);
>> 							  z =expr(*this,res[15]*X1[15]);
>> 							 f[15]=z;
>> 
>> 							 res[16] = g[2][4];
>> 							 X1[16] = X(2,4);
>> 							  z =expr(*this,res[16]*X1[16]);
>> 							 f[16]=z;
>> 
>> 							  res[17] = g[2][5];
>> 							 X1[17] = X(2,5);
>> 							  z =expr(*this,res[17]*X1[17]);
>> 							 f[17]=z;
>> 							  /////////////////////////////////////////////////////////////
>> 							  res[18] = g[3][0];
>> 							 X1[18] = X(3,0);
>> 							  z =expr(*this,res[18]*X1[18]);
>> 							 f[18]=z;
>> 
>> 							  res[19] = g[3][1];
>> 							 X1[19] = X(3,1);
>> 							  z =expr(*this,res[19]*X1[19]);
>> 							 f[19]=z;
>> 
>> 							 res[20] = g[3][2];
>> 							 X1[20] = X(3,2);
>> 							  z =expr(*this,res[20]*X1[20]);
>> 							 f[20]=z;
>> 
>> 							  res[21] = g[3][3];
>> 							 X1[21] = X(3,3);
>> 							  z =expr(*this,res[21]*X1[21]);
>> 							 f[21]=z;
>> 							  
>> 							  res[22] = g[3][4];
>> 							 X1[22] = X(3,4);
>> 							  z =expr(*this,res[22]*X1[22]);
>> 							 f[22]=z;
>> 
>> 							  res[23] = g[3][5];
>> 							 X1[23] = X(3,5);
>> 							  z =expr(*this,res[23]*X1[23]);
>> 							 f[23]=z;
>> 							 //////////////////////////////////////////////////////////////////////
>> 							 res[24] = g[4][0];
>> 							 X1[24] = X(4,0);
>> 							  z =expr(*this,res[24]*X1[24]);
>> 							 f[24]=z;
>> 
>> 							  res[25] = g[4][1];
>> 							 X1[25] = X(4,1);
>> 							  z =expr(*this,res[25]*X1[25]);
>> 							 f[25]=z;
>> 							  
>> 							  res[26] = g[4][2];
>> 							 X1[26] = X(4,2);
>> 							  z =expr(*this,res[26]*X1[26]);
>> 							 f[26]=z;
>> 
>> 							  res[27] = g[4][3];
>> 							 X1[27] = X(4,3);
>> 							  z =expr(*this,res[27]*X1[27]);
>> 							 f[27]=z;
>> 
>> 							 res[28] = g[4][4];
>> 							 X1[28] = X(4,4);
>> 							  z =expr(*this,res[28]*X1[28]);
>> 							 f[28]=z;
>> 
>> 							  res[29] = g[4][5];
>> 							 X1[29] = X(4,5);
>> 							  z =expr(*this,res[29]*X1[29]);
>> 							 f[29]=z;
>> 							  ///////////////////////////////////////////////////
>> 							  res[30] = g[5][0];
>> 							 X1[30] = X(5,0);
>> 							  z =expr(*this,res[30]*X1[30]);
>> 							 f[30]=z;
>> 
>> 							  res[31] = g[5][1];
>> 							 X1[31] = X(5,1);
>> 							  z =expr(*this,res[31]*X1[31]);
>> 							 f[31]=z;
>> 
>> 							  res[32] = g[5][2];
>> 							 X1[32] = X(5,2);
>> 							  z =expr(*this,res[32]*X1[32]);
>> 							 f[32]=z;
>> 
>> 							  res[33] = g[5][3];
>> 							 X1[33] = X(5,3);
>> 							  z =expr(*this,res[33]*X1[33]);
>> 							 f[33]=z;
>> 
>> 							  res[34] = g[5][4];
>> 							 X1[34] = X(5,4);
>> 							  z =expr(*this,res[34]*X1[34]);
>> 							 f[34]=z;
>> 
>> 							  res[35] = g[5][5];
>> 							 X1[35] = X(5,5);
>> 							  z =expr(*this,res[35]*X1[35]);
>> 							 f[35]=z;
>> 
>> 			              // }
>> 						// res1=res*X1;
>> 						 
>> 		             //}
>> 				 
>> 			// constraint over the objective function	 
>> 		 
>> 		 
>> 		//  linear(*this, f, IRT_EQ, gain);*/
>> 		
>> 		  //Branching
>>         branch(*this, a, INT_VAR_SIZE_MAX(), INT_VAL_MAX());
>> 
>>   }
>>     
>>   virtual IntVar cost(void) const {
>>     return gain1;
>>   }
>>   /// Print solution
>>   virtual void print(void) const {
>>    std::cout << a << std::endl;
>> 	
>> 	 
>>   }
>>   // Constructor for cloning \a s
>>   manel(bool share, manel& s)
>>     : MaximizeScript(share,s) {
>>    // gain.update(*this, share, s.gain);
>> 	a.update(*this, share, s.a);
>>   }
>>   // Copy during cloning
>>   virtual Space* copy(bool share) {
>>     return new manel(share,*this);
>>   }
>>  
>> 
>> };
>> 
>> int main(int argc, char* argv[]) {
>> 	  manel* m = new manel;
>>    if (manel* s = bab(m)) {
>>      s->print(); delete s; //Or whatever
>> }
>>  
>>   system("pause");
>>   return 0;
>> }
>>  
>> 
>> i really don't know where do i have the error and how to fix it 
>> 
>> Tha,k you very much for your help 
>> _______________________________________________
>> Gecode users mailing list
>> users at gecode.org
>> https://www.gecode.org/mailman/listinfo/gecode-users
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20131204/bea2e031/attachment-0001.html>


More information about the users mailing list