[gecode-users] Unexpected propagation/search behaviour

Lars Otten ottenl at student.chalmers.se
Mon Jan 23 17:07:21 CET 2006


Attached you find all code related to my propagator, below are the essential
parts of the main program. I hope that is sufficient...

Any ideas will be greatly appreciated!

/Lars


/*
 * tailassi.cc (excerpts)
 */

using namespace std;

class Activity;
vector<Activity> activities;

class Tail : public Example {
protected:
  // predecessor, successor and vehicle variables
  IntVarArray suc, pre, veh;
public:

  using Space::nextRand; // int (*nextRand) (const int&)

  /// Actual model
  Tail(const Options& opt);

  /// Constructor for cloning \a s
  Tail(bool share, Tail& s) : Example(share,s) {
    nextRand = s.nextRand;
    pre.update(this, share, s.pre);
    suc.update(this, share, s.suc);
    veh.update(this, share, s.veh);
  }

  /// Print solution
  virtual void print(void);

  /// Copy during cloning
  virtual Space* copy(bool share) {
    return new Tail(share,*this);
  }
};

int nextRandom(const int& max);

int main(int argc, char** argv) {
  Options opt("Tail assignment");
  opt.iterations = 20000;
  opt.parse(argc,argv);
  parseData(opt.file); // parses the datafile

  opt.fptr = &nextRandom;
  srand(opt.seed);

  Example::run<Tail,DFS>(opt);

  return 0;
}


Tail::Tail(const Options& opt) :
  suc(this,noOfAct),
  pre(this,noOfAct),
  veh(this,noOfAct)
{

//... Variable initialisation

  distinct(this,suc);

  // check for overlaps in case of restricted acitivities
  for (int i=0; i<noOfAct; ++i) {
    if (activities[i].restricted) {
      const set<int>& s = activities[i].overlappingActs;
      if (s.size() != 0) {
        IntVarArray arr(this,s.size() + 1);
        int j=0;
        for (set<int>::iterator it = s.begin(); it != s.end(); ++it) {
          arr[j++] = veh[*it];
        }
        arr[j] = veh[i]; // add current act. no to set
        distinct(this,arr);
      }
    }
  }

  inverse(this,suc,pre);
  tunneling(this,suc,pre,veh, &fwOverlap);

  branch(this, suc, BVAR_DEGREE_MIN, BVAL_MAX);

}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tunneling.cc
Type: text/x-c++src
Size: 425 bytes
Desc: not available
Url : http://www.ps.uni-sb.de/pipermail/gecode-users/attachments/20060123/22cdfe70/tunneling.cc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tunneling.hh
Type: text/x-c++hdr
Size: 1419 bytes
Desc: not available
Url : http://www.ps.uni-sb.de/pipermail/gecode-users/attachments/20060123/22cdfe70/tunneling.hh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tunneling.cc
Type: text/x-c++src
Size: 1755 bytes
Desc: not available
Url : http://www.ps.uni-sb.de/pipermail/gecode-users/attachments/20060123/22cdfe70/tunneling-0001.cc
-------------- next part --------------

namespace Gecode { namespace Int { namespace Tunneling {

  /*
   * "Tunneling" propagator
   *
   */

  // not used in practice at the moment
  forceinline
  Tunneling::Tunneling(Space* home, ViewArray<IntView>& y0, ViewArray<IntView>& y1, ViewArray<IntView>& y2, std::set<int>* (*fptr)(const int&))
    : Propagator(home), suc(y0), pre(y1), veh(y2), overlapping(fptr) {
    suc.subscribe(home,this,PC_INT_VAL);
    pre.subscribe(home,this,PC_INT_VAL);	
    veh.subscribe(home,this,PC_INT_VAL);
  }

  forceinline
  Tunneling::Tunneling(Space* home, bool share, Tunneling& p)
    : Propagator(home,share,p), procSuc(p.procSuc), procPre(p.procPre), procVeh(p.procVeh), overlapping(p.overlapping) {
    suc.update(home,share,p.suc);
    pre.update(home,share,p.pre);
    veh.update(home,share,p.veh);
  }
  
  forceinline ExecStatus
  Tunneling::post(Space* home, ViewArray<IntView>& x, ViewArray<IntView>& y, ViewArray<IntView>& z, std::set<int>* (*fptr)(const int&)) {
    (void) new (home) Tunneling(home,x,y,z,fptr);
    return ES_OK;
  }

}}}



More information about the gecode-users mailing list