support search options, added 'restart'
This commit is contained in:
parent
d9ce468a03
commit
7c78f52a89
@ -73,6 +73,13 @@ namespace generic_gecode
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericRestart: GenericEngine
|
||||
{
|
||||
Restart<GenericSpace> engine;
|
||||
GenericRestart(GenericSpace* s): engine(s) {}
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericSpace: Space
|
||||
{
|
||||
Optimizing optim;
|
||||
@ -137,12 +144,14 @@ namespace generic_gecode
|
||||
BoolVar get_bvar(int i) const { return (_bvars) ? (*_bvars)[i] : bvars[i]; }
|
||||
SetVar get_svar(int i) const { return (_svars) ? (*_svars)[i] : svars[i]; }
|
||||
|
||||
GenericEngine* new_engine()
|
||||
GenericEngine* new_engine(bool restart=false)
|
||||
{
|
||||
freeze();
|
||||
return (optim.what == Optimizing::OPT_NONE)
|
||||
? static_cast<GenericEngine*>(new GenericDFS(this))
|
||||
: static_cast<GenericEngine*>(new GenericBAB(this));
|
||||
: (restart
|
||||
? static_cast<GenericEngine*>(new GenericRestart(this))
|
||||
: static_cast<GenericEngine*>(new GenericBAB(this)));
|
||||
}
|
||||
|
||||
int _new_ivar(IntVar& v)
|
||||
|
@ -156,8 +156,10 @@ extern "C"
|
||||
{
|
||||
YAP_Term arg1 = YAP_ARG1;
|
||||
YAP_Term arg2 = YAP_ARG2;
|
||||
YAP_Term arg3 = YAP_ARG3;
|
||||
bool restart = YAP_IntOfTerm(YAP_ArgOfTerm(1, arg3));
|
||||
GenericSpace* space = gecode_Space_from_term(arg1);
|
||||
GenericEngine* engine = space->new_engine();
|
||||
GenericEngine* engine = space->new_engine(restart);
|
||||
YAP_Term y_engine =
|
||||
YAP_NewOpaqueObject(gecode_engine_tag, sizeof(GenericEngine*));
|
||||
GenericEngine** ptr =
|
||||
@ -1045,7 +1047,7 @@ extern "C"
|
||||
gecode_engine_handler.fail_handler = gecode_engine_fail_handler;
|
||||
gecode_engine_handler.write_handler = gecode_engine_write_handler;
|
||||
gecode_engine_tag = YAP_NewOpaqueType(&gecode_engine_handler);
|
||||
YAP_UserCPredicate("gecode_new_engine", gecode_new_engine, 2);
|
||||
YAP_UserCPredicate("gecode_new_engine", gecode_new_engine, 3);
|
||||
#ifdef DISJUNCTOR
|
||||
// opaque disjunctors and clauses
|
||||
gecode_disjunctor_handler.write_handler = gecode_disjunctor_write_handler;
|
||||
|
@ -344,13 +344,38 @@ maximize(Space,IVar1,IVar2) :-
|
||||
assert_is_IntVar(IVar2,IVar2_),
|
||||
gecode_space_maximize_ratio(Space_,IVar1_,IVar2_).
|
||||
|
||||
gecode_search_options_init(search_options(0)).
|
||||
|
||||
gecode_search_options_offset(restart,0).
|
||||
|
||||
gecode_search_options_from_alist(L,O) :-
|
||||
gecode_search_options_init(O),
|
||||
gecode_search_options_process_alist(L,O).
|
||||
|
||||
gecode_search_options_process_alist([],O).
|
||||
gecode_search_options_process_alist([F=V|L],O) :- !,
|
||||
gecode_search_options_set(F,V,O),
|
||||
gecode_search_options_process_alist(L,O).
|
||||
gecode_search_options_process_alist([F|L],O) :- !,
|
||||
gecode_search_options_set(F,1,O),
|
||||
gecode_search_options_process_alist(L,O).
|
||||
|
||||
gecode_search_options_set(F,V,O) :-
|
||||
gecode_search_options_offset(F,I),
|
||||
setarg(I,O,V).
|
||||
|
||||
search(Space, Solution) :-
|
||||
search(Space, Solution, []).
|
||||
|
||||
search(Space, Solution, Alist) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
assert_var(Solution),
|
||||
gecode_new_engine(Space_,Engine_),
|
||||
gecode_search_options_from_alist(Alist,O),
|
||||
gecode_new_engine(Space_,Engine_,O),
|
||||
gecode_engine_search(Engine_,Solution_),
|
||||
Solution='Space'(Solution_).
|
||||
|
||||
|
||||
%% INSPECTING VARIABLES
|
||||
|
||||
get_for_vars([],Space,[],F).
|
||||
@ -647,6 +672,7 @@ new_setvars_(L,Space,N,X1,X2) :- length(L,N), new_setvars(L,Space,X1,X2).
|
||||
(X := clause(Disj)) :- !, new_clause(X,Disj).
|
||||
|
||||
(X := search(Y)) :- !, search(Y,X).
|
||||
(X := search(Y,L)) :- !, search(Y,X,L).
|
||||
|
||||
% these should be autogenerated:
|
||||
(C += forward(X,Y)) :- !, new_forward(C,X,Y).
|
||||
|
Reference in New Issue
Block a user