hi all

i use gecode solver to solve my model ; but i get this error

 Access Violation when reading of the location 0x0000001c

and i don't konw how to fix it

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[count] = g[i][j];
                             count++;
                             X1[count1] = X(i,j);
                             count1++;
                             rel(*this,z==res[count]*X1[count1]);
                             f[count2]=z;
                             count2++;

                         }
                 }



            // 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;
}

so can you help me with this think you very much for your help

in this ligne :

rel(*this,z==res[count]*X1[count1]);

i found the one solution :)

   for (int i=0; i<n; i++)
                     {
                         for (int j=0; j<m; j++) 
                         {
                             res[count] = g[i][j];

                             X1[count] = X(i,j);

                             z=expr(*this,res[count]*X1[count]);
                             f[count]=z;
                             count++;
                         }
                 }

rel(this,z==res[count]X1[count1]);

It was probably the == boolean operator that caused the problem

rel(*this,(z=res[count]*X1[count1]));

@Ancient Dragon : thank you very much but it was not the "==" beacuse that's how we post a constraint in the Gecode solvor , it seems that i uses the wrong constraint

Thank you very much for your help

But a c/c++ compiler won't look at it that way. It will pass either 0 or 1 as the parameter because it's a boolean expression (true/false).

This question has already been answered. Start a new discussion instead.