[gecode-users] Segmentation fault in a very simple model

Guido Tack tack at ps.uni-sb.de
Tue Aug 4 16:08:25 CEST 2009


Dear Alfredo,

I think the problem lies in the initialization of the BoolVarArray.   
Even for BoolVars, you have to give an initial domain, so you should  
change the code to
   m_vars = BoolVarArray(*this,900, 0,1);

The way you wrote it, you just allocated an array of size 900 with  
uninitialized variables, that's probably why it crashed.

Hope this helps,
	Guido

Alfredo Esteban wrote:

> Hello,
>
> I'm getting started with Gecode reading "Modeling with Gecode". I  
> have experience in Constraint Programming using iLog software.
>
> I installed Gecode and I created a project to test it. I used  
> SendMoreMoney example. Everything is ok and I can compile and  
> execute this example.
>
> However, when I tried to build my own simple model, compilation is  
> ok but I get a segmentation fault when posting a linear constraint.  
> It is very strange because I imitated SendMoreMoney example. I  
> searched in mailing list but I didn't find anything.
>
> I show you the code. In main.cpp we have:
>
> int main(int argc, char* argv[]) {
>   SchoolTimeTable* problem = new SchoolTimeTable();
> [...]
>   return 0;
> }
>
> In schoolTimeTable.h we have:
>
> #include <gecode/int.hh>
>
> using namespace Gecode;
>
> class SchoolTimeTable : public Space {
> protected:
>   BoolVarArray m_vars;
> public:
>   SchoolTimeTable(void);
>   SchoolTimeTable(bool share, SchoolTimeTable& s);
>   virtual Space* copy(bool share);
>   void print(void) const;
> };
>
> In schoolTimeTable.cpp we have:
>
> #include "schoolTimeTable.h"
> #include <gecode/search.hh>
>
> SchoolTimeTable::SchoolTimeTable(void){
>   m_vars = BoolVarArray(*this,900);
>
>   BoolVarArgs borrame(3);
>   for (int i=0; i<3; i++) borrame[i]=m_vars[i];
>   linear(*this,borrame,IRT_EQ,2); // SIGSEGV IS HERE
> }
>
> SchoolTimeTable::SchoolTimeTable(bool share, SchoolTimeTable& s)
>   : Space(share, s) {
>   m_vars.update(*this, share, s.m_vars);
> }
>
> Space* SchoolTimeTable::copy(bool share) {
>   return new SchoolTimeTable(share,*this);
> }
>
> Technical data:
>
> OS: Debian GNU/Linux Squeeze
> Gecode version: 3.1.0
> gcc version: 4.3.3
> gdb version: 6.8
>
> Thank you very much,
>
> Alfredo
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users





More information about the gecode-users mailing list