Merge branch 'master' of git@git.dcc.fc.up.pt:yap-6.3
This commit is contained in:
commit
0eefb3c0b8
4
C/eval.c
4
C/eval.c
@ -269,9 +269,11 @@ p_logsum( USES_REGS1 )
|
||||
} else if (IsIntegerTerm(t1)) {
|
||||
f1 = IntegerOfTerm(t1);
|
||||
done = TRUE;
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(t1)) {
|
||||
f1 = Yap_gmp_to_float(t1);
|
||||
done = TRUE;
|
||||
#endif
|
||||
} else {
|
||||
while (!(t1 = Eval(t1 PASS_REGS))) {
|
||||
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
|
||||
@ -295,9 +297,11 @@ p_logsum( USES_REGS1 )
|
||||
} else if (IsIntegerTerm(t2)) {
|
||||
f2 = IntegerOfTerm(t2);
|
||||
done = TRUE;
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(t2)) {
|
||||
f2 = Yap_gmp_to_float(t2);
|
||||
done = TRUE;
|
||||
#endif
|
||||
} else {
|
||||
while (!(t2 = Eval(t2 PASS_REGS))) {
|
||||
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
|
||||
|
@ -4545,7 +4545,7 @@ remove_dirty_clauses_from_index(yamop *header)
|
||||
endop = Yap_opcode(_count_trust_logical);
|
||||
else if (ap->PredFlags & ProfiledPredFlag)
|
||||
endop = Yap_opcode(_profiled_trust_logical);
|
||||
while ((cl = curp->u.OtaLl.d)->ClFlags & ErasedMask) {
|
||||
while ((cl = curp->u.OtaLl.d) && (cl->ClFlags & ErasedMask)) {
|
||||
yamop *ocurp = curp;
|
||||
|
||||
header->u.Illss.e--;
|
||||
|
@ -260,6 +260,7 @@ read_int_overflow(const char *s, Int base, Int val, int sign)
|
||||
mpz_clear(new);
|
||||
return t;
|
||||
#else
|
||||
CACHE_REGS
|
||||
/* try to scan it as a float */
|
||||
return MkIntegerTerm(val);
|
||||
#endif
|
||||
|
@ -2187,6 +2187,8 @@ PL_open_foreign_frame(void)
|
||||
new->p = P;
|
||||
new->flags = 0;
|
||||
new->b = (CELL)(LCL0-(CELL*)B);
|
||||
new->envp = (CELL)(LCL0-ENV);
|
||||
new->asp = (CELL)(LCL0-ASP);
|
||||
new->slots = CurSlot;
|
||||
LOCAL_execution = new;
|
||||
{
|
||||
@ -2215,7 +2217,8 @@ PL_close_foreign_frame(fid_t f)
|
||||
P = env->p;
|
||||
CurSlot = env->slots;
|
||||
B = (choiceptr)(LCL0-env->b);
|
||||
ASP = (CELL *)(LCL0-CurSlot);
|
||||
ENV = (CELL *)(LCL0-env->envp);
|
||||
ASP = (CELL *)(LCL0-env->asp);
|
||||
EX = NULL;
|
||||
LOCAL_BallTerm = EX;
|
||||
LOCAL_execution = env->old;
|
||||
@ -2256,14 +2259,15 @@ PL_discard_foreign_frame(fid_t f)
|
||||
if (!env0)
|
||||
return;
|
||||
}
|
||||
CurSlot = env->slots;
|
||||
while (B->cp_b != (choiceptr)(LCL0-env->b))
|
||||
B = B->cp_b;
|
||||
backtrack();
|
||||
CurSlot = env->slots;
|
||||
ENV = (CELL *)(LCL0-env->envp);
|
||||
CP = env->cp;
|
||||
P = env->p;
|
||||
LOCAL_execution = env->old;
|
||||
ASP = LCL0-CurSlot;
|
||||
ASP = LCL0-env->asp;
|
||||
B = B->cp_b;
|
||||
//LOCAL_BallTerm = EX;
|
||||
//EX = NULL;
|
||||
|
@ -48,7 +48,7 @@ typedef struct open_query_struct {
|
||||
YAP_Term *g;
|
||||
PredEntry *pe;
|
||||
yamop *p, *cp;
|
||||
Int slots, b;
|
||||
Int slots, b, envp, asp;
|
||||
jmp_buf env;
|
||||
int flags;
|
||||
YAP_dogoalinfo h;
|
||||
|
@ -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 =
|
||||
@ -599,6 +661,17 @@ extern "C"
|
||||
return YAP_Unify(ivar, y_i);
|
||||
}
|
||||
|
||||
static int gecode_new_floatvar_from_bounds(void)
|
||||
{
|
||||
YAP_Term ivar = YAP_ARG1;
|
||||
GenericSpace* space = gecode_Space_from_term(YAP_ARG2);
|
||||
double lo = YAP_FloatOfTerm(YAP_ARG3);
|
||||
double hi = YAP_FloatOfTerm(YAP_ARG4);
|
||||
int i = space->new_fvar(lo, hi);
|
||||
YAP_Term y_i = YAP_MkIntTerm(i);
|
||||
return YAP_Unify(ivar, y_i);
|
||||
}
|
||||
|
||||
static int
|
||||
gecode_list_length(YAP_Term l)
|
||||
{
|
||||
@ -1707,6 +1780,8 @@ extern "C"
|
||||
gecode_new_intvar_from_bounds, 4);
|
||||
YAP_UserCPredicate("gecode_new_intvar_from_intset",
|
||||
gecode_new_intvar_from_intset, 3);
|
||||
YAP_UserCPredicate("gecode_new_floatvar_from_bounds",
|
||||
gecode_new_floatvar_from_bounds, 4);
|
||||
YAP_UserCPredicate("gecode_new_boolvar", gecode_new_boolvar, 2);
|
||||
YAP_UserCPredicate("gecode_new_setvar_1", gecode_new_setvar_1, 8);
|
||||
YAP_UserCPredicate("gecode_new_setvar_2", gecode_new_setvar_2, 7);
|
||||
|
@ -43,9 +43,9 @@ is_IntVarBranch_('IntVarBranch'(I,K),N) :-
|
||||
integer(K),
|
||||
nb_getval(gecode_space_use_keep_index,B),
|
||||
(B=true -> N=K ; N=I).
|
||||
is_FloatVar_('IntVar'(I,K),N) :-
|
||||
float(I),
|
||||
float(K),
|
||||
is_FloatVar_('FloatVar'(I,K),N) :-
|
||||
integer(I),
|
||||
integer(K),
|
||||
nb_getval(gecode_space_use_keep_index,B),
|
||||
(B=true -> N=K ; N=I).
|
||||
is_BoolVar_('BoolVar'(I,K),N) :-
|
||||
@ -144,6 +144,8 @@ assert_var(X,Y) :-
|
||||
var(X) -> X=Y; throw(gecode_error(expected(var))).
|
||||
assert_is_int(X,Y) :-
|
||||
integer(X) -> X=Y ; throw(gecode_error(expected(int))).
|
||||
assert_is_float(X,Y) :-
|
||||
float(X) -> X=Y ; throw(gecode_error(expected(int))).
|
||||
assert_is_Space(X,Y) :-
|
||||
is_Space(X,Y) -> true ; throw(gecode_error(expected(space))).
|
||||
assert_is_IntSet(X,Y) :-
|
||||
@ -173,6 +175,7 @@ assert_is_ReifyMode(X,Y) :-
|
||||
|
||||
assert_var(X) :- assert_var(X,_).
|
||||
assert_is_int(X) :- assert_is_int(X,_).
|
||||
assert_is_float(X) :- assert_is_float(X,_).
|
||||
assert_is_Space(X) :- assert_is_Space(X,_).
|
||||
assert_is_IntSet(X) :- assert_is_IntSet(X,_).
|
||||
assert_is_IntVar(X) :- assert_is_IntVar(X,_).
|
||||
@ -410,6 +413,14 @@ new_intvar(IVar, Space, IntSet) :- !,
|
||||
gecode_new_intvar_from_intset(Idx,Space_,L),
|
||||
IVar='IntVar'(Idx,-1).
|
||||
|
||||
new_floatvar(FVar, Space, Lo, Hi) :- !,
|
||||
assert_var(IVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
assert_float(Lo),
|
||||
assert_float(Hi),
|
||||
gecode_new_floatvar_from_bounds(Idx,Space_,Lo,Hi),
|
||||
FVar='FloatVar'(Idx,-1).
|
||||
|
||||
new_boolvar(BVar, Space) :- !,
|
||||
assert_var(BVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
@ -556,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,1,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),
|
||||
@ -590,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