Hi,

I've written a custom propagator. It is based on one of the existing templates, Gecode:BinaryPropagator, with an array of boolean views as the template argument. It works, but the compiler (g++ 4.1.2) is having serious trouble with the code: if I try to use any compiler optimisation (that is, anything other than -O0), the compiler eats up all memory (including swap) and never finishes. I know that using many and/or nested templates tends to increase compiler memory use, but this case is worse than anything I've encountered before. Is this a known problem? (perhaps fixed in some more recent g++ compiler). Is there some way to work around it? (other than disabling compiler optimisation, because that *really* slows down the solver). The only other option I can think of is to write the propagator from scratch, without relying on any base template.

Attached is a simplified version of the code (it doesn't contain any actual functionality, just the minimum that is needed to cause the compiler to behave this way).

Thanks,
                        /[EMAIL PROTECTED]
#include "gecode/kernel.hh"
#include "gecode/int.hh"
#include "gecode/minimodel.hh"
#include "gecode/search.hh"

typedef Gecode::ViewArray<Gecode::Int::BoolView> BoolViewArray;

typedef Gecode::BinaryPropagator
<BoolViewArray, Gecode::Int::PC_INT_VAL>
PropBaseType;

class ThePropagator : public PropBaseType {
 public:
  // constructor for posting
  ThePropagator(Gecode::Space* home,
		BoolViewArray& va0,
		BoolViewArray& va1)
    : PropBaseType(home, va0, va1) { };
  // constructor for cloning
  ThePropagator(Gecode::Space* home, bool share, ThePropagator& pp)
    : PropBaseType(home, share, pp) { };

  // copy of a propagator during cloning
  virtual Gecode::Actor* copy(Gecode::Space* home, bool share)
  {
    return new (home) ThePropagator(home, share, *this);
  };

  // preform propagation
  virtual Gecode::ExecStatus propagate
  (Gecode::Space* home, Gecode::ModEventDelta med);

  // Post the propagator
  static Gecode::ExecStatus post
  (Gecode::Space* home,
   const Gecode::BoolVarArray& bv0,
   const Gecode::BoolVarArray& bv1)
  {
    BoolViewArray va0(home, bv0.size());
    for (int k = 0; k < bv0.size(); k++)
      va0[k] = Gecode::Int::BoolView(bv0[k]);
    BoolViewArray va1(home, bv1.size());
    for (int k = 0; k < bv1.size(); k++)
      va1[k] = Gecode::Int::BoolView(bv1[k]);
    new (home) ThePropagator(home, va0, va1);
    return Gecode::ES_OK;
  };
};

Gecode::ExecStatus ThePropagator::propagate
(Gecode::Space* home, Gecode::ModEventDelta med)
{
  return Gecode::ES_FIX;
}

class TheSpace : public Gecode::Space
{
 protected:
  Gecode::BoolVarArray bv0;
  Gecode::BoolVarArray bv1;

 public:
  TheSpace(int n0, int n1);
  TheSpace(bool share, TheSpace& s);
  virtual Gecode::Space* copy(bool share);
};

TheSpace::TheSpace(int n0, int n1)
  : bv0(this, n0, 0, 1),
    bv1(this, n1, 0, 1)
{
  ThePropagator::post(this, bv0, bv1);
}

TheSpace::TheSpace(bool share, TheSpace& cc)
  : Gecode::Space(share, cc)
{
  bv0.update(this, share, cc.bv0);
  bv1.update(this, share, cc.bv1);
}

Gecode::Space* TheSpace::copy(bool share)
{
  return new TheSpace(share, *this);
}

int main(int argc, char** argv)
{
  TheSpace* cc = new TheSpace(10, 10);
  std::cout << cc->status() << std::endl;
}
_______________________________________________
Gecode users mailing list
[EMAIL PROTECTED]
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to