control changes for gecode
This commit is contained in:
parent
90c70459be
commit
ef82f25594
@ -70,6 +70,13 @@ namespace generic_gecode
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericRestartDFS: GenericEngine
|
||||
{
|
||||
RBS<DFS,GenericSpace> engine;
|
||||
GenericRestartDFS(GenericSpace* s,Search::Options& opt) : engine(s,opt) {}
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericBAB: GenericEngine
|
||||
{
|
||||
BAB<GenericSpace> engine;
|
||||
@ -77,6 +84,13 @@ namespace generic_gecode
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericRestartBAB: GenericEngine
|
||||
{
|
||||
RBS<BAB,GenericSpace> engine;
|
||||
GenericRestartBAB(GenericSpace* s,Search::Options& opt) : engine(s,opt) {}
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
#ifdef OLD
|
||||
struct GenericRestart: GenericEngine
|
||||
{
|
||||
@ -270,11 +284,13 @@ namespace generic_gecode
|
||||
{
|
||||
freeze();
|
||||
return (optim.what == Optimizing::OPT_NONE)
|
||||
? static_cast<GenericEngine*>(new GenericDFS(this,opt))
|
||||
: //(restart
|
||||
// ? static_cast<GenericEngine*>(new GenericRestart(this,opt))
|
||||
// :
|
||||
static_cast<GenericEngine*>(new GenericBAB(this,opt));
|
||||
? ( restart
|
||||
? static_cast<GenericEngine*>(new GenericRestartDFS(this,opt))
|
||||
: static_cast<GenericEngine*>(new GenericDFS(this,opt)) )
|
||||
: (restart
|
||||
? static_cast<GenericEngine*>(new GenericRestartBAB(this,opt))
|
||||
:
|
||||
static_cast<GenericEngine*>(new GenericBAB(this,opt)) );
|
||||
}
|
||||
|
||||
int _new_ivar(IntVar& v)
|
||||
|
@ -454,6 +454,8 @@ extern "C"
|
||||
static YAP_opaque_tag_t gecode_engine_tag;
|
||||
static YAP_opaque_handler_t gecode_engine_handler;
|
||||
|
||||
static RestartMode gecode_RestartMode_from_term(YAP_Term t);
|
||||
|
||||
static int gecode_new_engine(void)
|
||||
{
|
||||
YAP_Term arg1 = YAP_ARG1;
|
||||
@ -463,10 +465,70 @@ extern "C"
|
||||
double threads = YAP_FloatOfTerm(YAP_ArgOfTerm(2, arg3));
|
||||
unsigned int c_d = YAP_IntOfTerm(YAP_ArgOfTerm(3, arg3));
|
||||
unsigned int a_d = YAP_IntOfTerm(YAP_ArgOfTerm(4, arg3));
|
||||
unsigned int nogoods_limit = YAP_IntOfTerm(YAP_ArgOfTerm(6, arg3));
|
||||
bool clone = ( YAP_IntOfTerm(YAP_ArgOfTerm(7, arg3)) == 0 ? FALSE : TRUE );
|
||||
RestartMode md;
|
||||
YAP_Term t = YAP_ArgOfTerm(5, arg3);
|
||||
if (YAP_IsAtomTerm(t)) {
|
||||
md = gecode_RestartMode_from_term(t);
|
||||
} else if (YAP_IsApplTerm(t)) {
|
||||
md = gecode_RestartMode_from_term(YAP_MkAtomTerm(YAP_NameOfFunctor(YAP_FunctorOfTerm(t))));
|
||||
} else {
|
||||
cerr << "bad engine cutoff option" << endl; exit(1);
|
||||
}
|
||||
Search::Cutoff* cutoff;
|
||||
YAP_Term t_s, t_b;
|
||||
switch (md) {
|
||||
case RM_CONSTANT:
|
||||
YAP_Term t_a;
|
||||
if (YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)) == 1 &&
|
||||
YAP_IsIntTerm(t_a = YAP_ArgOfTerm(1,t))) {
|
||||
unsigned long int a = YAP_IntOfTerm(t_a);
|
||||
cutoff = Search::Cutoff::constant(a);
|
||||
} else {
|
||||
cerr << "bad parameter for constant" << endl; exit(1);
|
||||
}
|
||||
break;
|
||||
case RM_GEOMETRIC:
|
||||
if (YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)) == 2 &&
|
||||
YAP_IsIntTerm(t_s = YAP_ArgOfTerm(1,t)) &&
|
||||
YAP_IsIntTerm(t_b = YAP_ArgOfTerm(2,t))) {
|
||||
unsigned long int s = YAP_IntOfTerm(t_s);
|
||||
unsigned long int b = YAP_IntOfTerm(t_b);
|
||||
cutoff = Search::Cutoff::geometric(s,b);
|
||||
} else {
|
||||
cerr << "bad parameter for geometric" << endl; exit(1);
|
||||
}
|
||||
break;
|
||||
case RM_LUBY:
|
||||
if (YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)) == 1 &&
|
||||
YAP_IsIntTerm(t_s = YAP_ArgOfTerm(1,t))) {
|
||||
unsigned long int s = YAP_IntOfTerm(t_s);
|
||||
cutoff = Search::Cutoff::luby(s);
|
||||
} else {
|
||||
cerr << "bad parameter for luby" << endl; exit(1);
|
||||
}
|
||||
break;
|
||||
case RM_LINEAR:
|
||||
if (YAP_ArityOfFunctor(YAP_FunctorOfTerm(t)) == 1 &&
|
||||
YAP_IsIntTerm(t_s = YAP_ArgOfTerm(1,t))) {
|
||||
unsigned long int s = YAP_IntOfTerm(t_s);
|
||||
cutoff = Search::Cutoff::linear(s);
|
||||
} else {
|
||||
cerr << "bad parameter for linear" << endl; exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cutoff = NULL;
|
||||
}
|
||||
Search::Options opt;
|
||||
opt.threads = threads;
|
||||
opt.c_d = c_d;
|
||||
opt.a_d = a_d;
|
||||
opt.cutoff = cutoff;
|
||||
opt.nogoods_limit = nogoods_limit;
|
||||
opt.clone = clone;
|
||||
opt.stop = NULL;
|
||||
GenericSpace* space = gecode_Space_from_term(arg1);
|
||||
GenericEngine* engine = space->new_engine(restart,opt);
|
||||
YAP_Term y_engine =
|
||||
|
@ -567,11 +567,15 @@ reify(Space,BVar,Mode,R) :-
|
||||
gecode_new_reify(Space_,BVar_,Mode_,R_),
|
||||
R = 'Reify'(R_).
|
||||
|
||||
gecode_search_options_init(search_options(0,1.0,8,2)).
|
||||
gecode_search_options_init(search_options(0,1.0,8,2,'RM_NONE',0,0,0)).
|
||||
gecode_search_options_offset(restart,1).
|
||||
gecode_search_options_offset(threads,2).
|
||||
gecode_search_options_offset(c_d ,3).
|
||||
gecode_search_options_offset(a_d ,4).
|
||||
gecode_search_options_offset(cutoff, 5).
|
||||
gecode_search_options_offset(nogoods_limit, 6).
|
||||
gecode_search_options_offset(clone, 7).
|
||||
gecode_search_options_offset(stop, 8). % unimplemented
|
||||
|
||||
gecode_search_option_set(O,V,R) :-
|
||||
gecode_search_options_offset(O,I),
|
||||
@ -601,6 +605,18 @@ gecode_search_options_process1(a_d=N,R) :- !,
|
||||
(integer(N) -> V=N
|
||||
; throw(bad_search_option_value(a_d=N))),
|
||||
gecode_search_option_set(a_d,V,R).
|
||||
gecode_search_options_process1(cutoff=C,R) :- !,
|
||||
(is_RestartMode(C,C_) -> V=C_
|
||||
; throw(bad_search_option_value(cutoff=C))),
|
||||
gecode_search_option_set(cutoff,C_,R).
|
||||
gecode_search_options_process1(nogoods_limit=N,R) :- !,
|
||||
(integer(N), N >= 0 -> V=N
|
||||
; throw(bad_search_option_value(nogoods_limit=N))),
|
||||
gecode_search_option_set(nogoods_limit,N,R).
|
||||
gecode_search_options_process1(clone=N,R) :- !,
|
||||
((N == 0 ; N == 1)-> V=N
|
||||
; throw(bad_search_option_value(clone=N))),
|
||||
gecode_search_option_set(clone,N,R).
|
||||
gecode_search_options_process1(O,_) :-
|
||||
throw(gecode_error(unrecognized_search_option(O))).
|
||||
|
||||
|
Reference in New Issue
Block a user