[gecode-users] Adding restart-based search to ECLiPSe's interface to Gecode
Christian Schulte
cschulte at kth.se
Sun Sep 1 18:19:08 CEST 2013
Hi Kish,
No, the engine can only restart based on the number of failures. But, it
will also restart when it has found a solution. So what you could do is to
use an embarrassingly large number of failures (ULONG_MAX) and a constant
cutoff generator (Search::Cutoff::constant(ULONG_MAX)).
Cheers
Christian
--
Christian Schulte, www.ict.kth.se/~cschulte/
> -----Original Message-----
> From: Kish Shen [mailto:kisshen at cisco.com]
> Sent: Friday, August 30, 2013 8:01 PM
> To: cschulte at kth.se
> Cc: users at gecode.org
> Subject: Re: [gecode-users] Adding restart-based search to ECLiPSe's
interface
> to Gecode
>
> Hi Christian,
>
> Thanks for the code. This code looks to be more C++ like than what I have
now,
> where my GecodeSearch class (equivalent to EngineBase here) has several
> private engine pointers for the different engine types, and the functions
like
> next() switch on the search methods to call the function of the correct
engine
> type. I will change my code to be more like what you are doing here.
Thanks
> again.
>
> My next question is now about doing the restart: are there any
alternatives to
> doing restart based on the number of failures? One alternative is to do
restart
> only with a new solution. I assume this is what the old RESTART engine
did. As
> the current gfd interface supports this engine, I would like to continue
to
> support it. As I said in my previous posting, I am not sure if the next
solution is
> done via restart in RBS, because it seem to use DFS or BAB as the "actual"
search
> engine, and these engines don't restart (as far as I can tell) with the
next
> solution.
>
> Thanks and cheers,
>
> Kish
>
> On 27/08/2013 09:51, Christian Schulte wrote:
> > Hi Kish,
> >
> > Here is a solution built on top of Gecode. It defines a type
> > Kish::EngineBase that can be passed around irrespective of which
> > engine it actual is. The other stuff is just for illustration and how
> > to recast Gecode's engines as engines of type Kish::EngineBase.
> >
> > Hope this helps.
> >
> > Best
> > Christian
> >
> >
> > namespace Kish {
> >
> > class EngineBase {
> > public:
> > EngineBase(void) {}
> > virtual Gecode::Space* next(void) = 0;
> > virtual Gecode::Search::Statistics statistics(void) const = 0;
> > virtual bool stopped(void) const = 0;
> > virtual ~EngineBase(void) {}
> > };
> >
> > class DFS : public EngineBase {
> > protected:
> > Gecode::DFS<Gecode::Space> e;
> > public:
> > DFS(Gecode::Space* s, const Gecode::Search::Options& o)
> > : e(s,o) {}
> > virtual Gecode::Space* next(void) {
> > return e.next();
> > }
> > virtual Gecode::Search::Statistics statistics(void) const {
> > return e.statistics();
> > }
> > virtual bool stopped(void) const {
> > return e.stopped();
> > }
> > virtual ~DFS(void) {}
> > };
> >
> > class BAB : public EngineBase {
> > protected:
> > Gecode::BAB<Gecode::Space> e;
> > public:
> > BAB(Gecode::Space* s, const Gecode::Search::Options& o)
> > : e(s,o) {}
> > virtual Gecode::Space* next(void) {
> > return e.next();
> > }
> > virtual Gecode::Search::Statistics statistics(void) const {
> > return e.statistics();
> > }
> > virtual bool stopped(void) const {
> > return e.stopped();
> > }
> > virtual ~BAB(void) {}
> > };
> >
> > template<template<class> class E>
> > class RBS : public EngineBase {
> > protected:
> > Gecode::RBS<E,Gecode::Space> e;
> > public:
> > RBS(Gecode::Space* s, const Gecode::Search::Options& o)
> > : e(s,o) {}
> > virtual Gecode::Space* next(void) {
> > return e.next();
> > }
> > virtual Gecode::Search::Statistics statistics(void) const {
> > return e.statistics();
> > }
> > virtual bool stopped(void) const {
> > return e.stopped();
> > }
> > virtual ~RBS(void) {}
> > };
> >
> > enum WhichEngine {
> > WE_DFS, WE_BAB,
> > WE_RBS_DFS, WE_RBS_BAB
> > };
> >
> > EngineBase* engine(WhichEngine we,
> > Gecode::Space* s,
> > const Gecode::Search::Options& o) {
> > switch (we) {
> > case WE_DFS: return new DFS(s,o);
> > case WE_BAB: return new BAB(s,o);
> > case WE_RBS_DFS: return new RBS<Gecode::DFS>(s,o);
> > case WE_RBS_BAB: return new RBS<Gecode::BAB>(s,o);
> > }
> > }
> > }
> >
> >
> > --
> > Christian Schulte, Professor of Computer Science, KTH,
> > www.ict.kth.se/~cschulte/
> >
> >
> > -----Original Message-----
> > From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On
> > Behalf Of Christian Schulte
> > Sent: Thursday, August 22, 2013 9:50 AM
> > To: 'Kish Shen'
> > Cc: users at gecode.org
> > Subject: Re: [gecode-users] Adding restart-based search to ECLiPSe's
> > interface to Gecode
> >
> > Hi Kish,
> >
> > My bad... There is really no common basetype for search engines, the
> > type I mentioned is actually for the implementations and not the
interfaces...
> >
> > I think you will have to wait until I have added a common basetype
> > (there is a basetype, but it is not powerful enough), I might be able
> > to do it until the end of the week.
> >
> > Sorry for the confusion!
> >
> > Cheers
> > Christian
> >
> > --
> > Christian Schulte, Professor of Computer Science, KTH,
> > www.ict.kth.se/~cschulte/
> >
> >
> >
> > -----Original Message-----
> > From: Kish Shen [mailto:kisshen at cisco.com]
> > Sent: Thursday, August 22, 2013 9:45 AM
> > To: cschulte at kth.se
> > Cc: users at gecode.org
> > Subject: Re: [gecode-users] Adding restart-based search to ECLiPSe's
> > interface to Gecode
> >
> > Hi Christian,
> >
> > Thanks again!
> >
> > On 21/08/2013 19:17, Christian Schulte wrote:
> >> Try to avoid the Gecode::Search::bab .... functions. Just create as
> > follows:
> >> Gecode::Search::Engine* e = new Gecode::BAB(...) Then it also will
> >> work for RBS, and you do not have to create a second engine yourself,
> >> this will the RBS class do for you.
> >>
> >> And do not forget to delete e eventually!
> >>
> >
> > This is the part that I don't know how to do correct -- probably
> > because of my lack of C++ knowledge, but as far as I can tell,
> > Gecode::DFS etc are not of class Engine*, according to the doc:
> >
> > template<class T>
> > class Gecode::DFS<T>
> >
> > for subclasses T of Space
> >
> > T is GecodeSpace in my case, I assume. I am not sure what class DFS
> > is, but I can't see how it could be Engine*.
> >
> > Anway, I tried to do the assignment as you suggested:
> >
> >
> > Search::Engine* segine;
> > ...
> > sengine = new DFS<GecodeSpace>(solver, o); and indeed I get the error
> >
> > cannot convert 'Gecode::DFS<GecodeSpace>*' to 'Gecode::Search::Engine*'
> >
> > (I first tried sengine = new DFS(solver, o) but got an error 'expected
> > type-specifier')
> >
> > So I am not sure what to do -- do I need to change the type of
> > sengine, and/or the way I assign an engine to sengine?
> >
> > Cheers,
> >
> > Kish
> >
> >
> >
> >
> >
> > _______________________________________________
> > Gecode users mailing list
> > users at gecode.org
> > https://www.gecode.org/mailman/listinfo/gecode-users
> >
More information about the users
mailing list