Merge branch 'master' of git@git.dcc.fc.up.pt:yap-6.3

This commit is contained in:
Fabrizio Riguzzi 2013-09-04 19:11:28 +02:00
commit 842b7f25ab
48 changed files with 16627 additions and 15849 deletions

30
.gitmodules vendored
View File

@ -1,48 +1,48 @@
[submodule "packages/chr"]
path = packages/chr
url = git://yap.git.sourceforge.net/gitroot/yap/chr
url = git://git.code.sf.net/p/yap/chr
[submodule "packages/clpqr"]
path = packages/clpqr
url = git://yap.git.sourceforge.net/gitroot/yap/clpqr
url = git://git.code.sf.net/p/yap/clpqr
[submodule "packages/jpl"]
path = packages/jpl
url = git://yap.git.sourceforge.net/gitroot/yap/jpl
url = git://git.code.sf.net/p/yap/jpl
[submodule "packages/zlib"]
path = packages/zlib
url = git://yap.git.sourceforge.net/gitroot/yap/zlib
url = git://git.code.sf.net/p/yap/zlib
[submodule "packages/http"]
path = packages/http
url = git://yap.git.sourceforge.net/gitroot/yap/http
url = git://git.code.sf.net/p/yap/http
[submodule "packages/clib"]
path = packages/clib
url = git://yap.git.sourceforge.net/gitroot/yap/clib
url = git://git.code.sf.net/p/yap/clib
[submodule "packages/sgml"]
path = packages/sgml
url = git://yap.git.sourceforge.net/gitroot/yap/sgml
url = git://git.code.sf.net/p/yap/sgml
[submodule "packages/RDF"]
path = packages/RDF
url = git://yap.git.sourceforge.net/gitroot/yap/RDF
url = git://git.code.sf.net/p/yap/RDF
[submodule "packages/semweb"]
path = packages/semweb
url = git://yap.git.sourceforge.net/gitroot/yap/semweb
url = git://git.code.sf.net/p/yap/semweb
[submodule "packages/plunit"]
path = packages/plunit
url = git://yap.git.sourceforge.net/gitroot/yap/plunit
url = git://git.code.sf.net/p/yap/plunit
[submodule "packages/R"]
path = packages/R
url = git://yap.git.sourceforge.net/gitroot/yap/R
url = git://git.code.sf.net/p/yap/R
[submodule "packages/pldoc"]
path = packages/pldoc
url = git://yap.git.sourceforge.net/gitroot/yap/pldoc
url = git://git.code.sf.net/p/yap/pldoc
[submodule "packages/real"]
path = packages/real
url = git://www.swi-prolog.org/home/pl/git/packages/real.git
url = vsc://www.swi-prolog.org/home/pl/git/packages/real.git
[submodule "packages/archive"]
path = packages/archive
url = git://yap.git.sourceforge.net/gitroot/yap/archive
url = git://git.code.sf.net/p/yap/archive
[submodule "packages/odbc"]
path = packages/odbc
url = git://yap.git.sourceforge.net/gitroot/yap/odbc
url = git://git.code.sf.net/p/yap/odbc
[submodule "packages/udi"]
path = packages/udi
url = https://github.com/davidvaz/yap-udi-indexers.git

View File

@ -2313,6 +2313,8 @@ init_sub_atom( USES_REGS1 )
Yap_unify(ARG1, ARG5) &&
Yap_unify(ARG2, MkIntegerTerm(0)) &&
Yap_unify(ARG4, MkIntegerTerm(0));
} else if (len > sz) {
cut_fail();
} else {
mask |= SUB_ATOM_HAS_SIZE;
min = 0;

View File

@ -144,15 +144,15 @@ AllocCMem (UInt size, struct intermediates *cip)
}
#else
char *p;
p = cip->freep;
cip->freep += size;
if (ASP <= CellPtr (cip->freep) + 256) {
CACHE_REGS
LOCAL_Error_Size = 256+((char *)cip->freep - (char *)H);
save_machine_regs();
siglongjmp(cip->CompilerBotch, OUT_OF_STACK_BOTCH);
}
return (p);
}
p = cip->freep;
cip->freep += size;
return p;
#endif
}

View File

@ -727,6 +727,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
/* first thing, store a link to the list before we move on */
*StoPoint++ = AbsAppl(CodeMax);
/* next, postpone analysis to the rest of the current list */
CheckVisitOverflow();
#ifdef RATIONAL_TREES
to_visit[0] = pt0+1;
to_visit[1] = pt0_end;
@ -742,7 +743,6 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
to_visit += 3;
}
#endif
CheckVisitOverflow();
d0 = ArityOfFunctor(f);
pt0 = ap2+1;
pt0_end = ap2 + d0;

127
C/eval.c
View File

@ -198,6 +198,130 @@ p_is( USES_REGS1 )
return Yap_unify_constant(ARG1,out);
}
static Int
p_isnan( USES_REGS1 )
{ /* X is Y */
Term out = 0L;
while (!(out = Eval(Deref(ARG1) PASS_REGS))) {
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
if (IsVarTerm(out)) {
Yap_Error(INSTANTIATION_ERROR, out, "isnan/1");
return FALSE;
}
if (!IsFloatTerm(out)) {
Yap_Error(TYPE_ERROR_FLOAT, out, "isnan/1");
return FALSE;
}
return isnan(FloatOfTerm(out));
}
static Int
p_isinf( USES_REGS1 )
{ /* X is Y */
Term out = 0L;
while (!(out = Eval(Deref(ARG1) PASS_REGS))) {
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
if (IsVarTerm(out)) {
Yap_Error(INSTANTIATION_ERROR, out, "isinf/1");
return FALSE;
}
if (!IsFloatTerm(out)) {
Yap_Error(TYPE_ERROR_FLOAT, out, "isinf/1");
return FALSE;
}
return isinf(FloatOfTerm(out));
}
static Int
p_logsum( USES_REGS1 )
{ /* X is Y */
Term t1 = Deref(ARG1);
Term t2 = Deref(ARG2);
int done = FALSE;
Float f1, f2;
while (!done) {
if (IsFloatTerm(t1)) {
f1 = FloatOfTerm(t1);
done = TRUE;
} else if (IsIntegerTerm(t1)) {
f1 = IntegerOfTerm(t1);
done = TRUE;
} else if (IsBigIntTerm(t1)) {
f1 = Yap_gmp_to_float(t1);
done = TRUE;
} else {
while (!(t1 = Eval(t1 PASS_REGS))) {
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
}
}
done = FALSE;
while (!done) {
if (IsFloatTerm(t2)) {
f2 = FloatOfTerm(t2);
done = TRUE;
} else if (IsIntegerTerm(t2)) {
f2 = IntegerOfTerm(t2);
done = TRUE;
} else if (IsBigIntTerm(t2)) {
f2 = Yap_gmp_to_float(t2);
done = TRUE;
} else {
while (!(t2 = Eval(t2 PASS_REGS))) {
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) {
Yap_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
}
}
if (f1 >= f2) {
Float fi = exp(f2-f1);
return Yap_unify(ARG3,MkFloatTerm(f1+log(1+fi)));
} else {
Float fi = exp(f1-f2);
return Yap_unify(ARG3,MkFloatTerm(f2+log(1+fi)));
}
}
Int
Yap_ArithError(yap_error_number type, Term where, char *format,...)
{
@ -360,6 +484,9 @@ Yap_InitEval(void)
Yap_InitUnaryExps();
Yap_InitBinaryExps();
Yap_InitCPred("is", 2, p_is, 0L);
Yap_InitCPred("isnan", 1, p_isnan, TestPredFlag);
Yap_InitCPred("isinf", 1, p_isinf, TestPredFlag);
Yap_InitCPred("logsum", 3, p_logsum, TestPredFlag);
Yap_InitCPredBack("between", 3, 2, init_between, cont_between, 0);
}

46
C/exo.c
View File

@ -69,10 +69,10 @@ inline BITS32 fmix32 ( BITS32 h )
return h;
}
//-----------------------------------------------------------------------------
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_MURMUR3_32 (UInt arity, CELL *cl, UInt bnds[], UInt sz);
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_MURMUR3_32 (UInt arity, CELL *cl, UInt bnds[], UInt sz)
{
UInt hash;
@ -121,10 +121,10 @@ HASH_MURMUR3_32 (UInt arity, CELL *cl, UInt bnds[], UInt sz)
/*DJB2*/
#define DJB2_OFFSET 5381
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_DJB2(UInt arity, CELL *cl, UInt bnds[], UInt sz);
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_DJB2(UInt arity, CELL *cl, UInt bnds[], UInt sz)
{
BITS32 hash;
@ -147,11 +147,11 @@ HASH_DJB2(UInt arity, CELL *cl, UInt bnds[], UInt sz)
return hash;
}
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_RS(UInt arity, CELL *cl, UInt bnds[], UInt sz);
/* RS Hash Function */
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_RS(UInt arity, CELL *cl, UInt bnds[], UInt sz)
{
UInt hash=0;
@ -176,7 +176,7 @@ HASH_RS(UInt arity, CELL *cl, UInt bnds[], UInt sz)
return hash;
}
extern inline BITS32
INLINE_ONLY inline BITS32
HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz);
/* Simple hash function:
@ -185,14 +185,14 @@ HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz);
hash0 spreads extensions coming from different elements.
spread over j quadrants.
*/
extern inline BITS32
HASH_FVN_1A(UInt ar, CELL *cl, UInt bnds[], UInt sz)
INLINE_ONLY inline BITS32
HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz)
{
UInt hash;
UInt j=0;
hash = FNV32_OFFSET;
while (j < ar) {
while (j < arity) {
if (bnds[j]) {
unsigned char *i=(unsigned char*)(cl+j);
unsigned char *m=(unsigned char*)(cl+(j+1));
@ -219,12 +219,18 @@ HASH_FVN_1A(UInt ar, CELL *cl, UInt bnds[], UInt sz)
#else
/* Default: TEST_HASH_FVN */
# define HASH(...) HASH_FVN_1A(__VA_ARGS__)
# define HASH1(...) HASH_MURMUR3_32(__VA_ARGS__)
#endif
static BITS32
NEXT(UInt hash)
NEXT(UInt arity, CELL *cl, UInt bnds[], UInt sz, BITS32 hash)
{
return (hash*997);
int i = 0;
BITS32 hash1;
while (bnds[i]==0) i++;
hash1 = HASH1(arity, cl, bnds, sz);
return (hash + hash1 +cl[i]);
}
/* search for matching elements */
@ -289,6 +295,8 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt bnds[])
/* simple case, new entry */
it->nentries++;
it->key[hash % it->hsize ] = EXO_ADDRESS_TO_OFFSET(it, cl);
if (coll_count > it -> max_col_count)
it->max_col_count = coll_count;
return TRUE;
} else if (MATCH(kvp, cl, arity, bnds)) {
it->ntrys++;
@ -296,11 +304,9 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt bnds[])
return TRUE;
} else {
coll_count++;
if (coll_count == 32)
return FALSE;
it->ncollisions++;
// printf("#");
hash = NEXT(hash);
hash = NEXT(arity, cl, bnds, it->hsize, hash);
//if (exo_write) printf("N=%ld\n", hash);
goto next;
}
@ -330,7 +336,7 @@ LOOKUP(struct index_t *it, UInt arity, UInt j, UInt bnds[])
return NEXTOP(NEXTOP(it->code,lp),lp);
} else {
/* collision */
hash = NEXT(hash);
hash = NEXT(arity, XREGS+1, bnds, it->hsize, hash);
goto next;
}
}
@ -409,6 +415,9 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
i->ncollisions = i->nentries = i->ntrys = 0;
i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *));
i->bcls= i->cls-i->arity;
i->udi_free_args = 0;
i->is_udi = FALSE;
i->udi_arg = 0;
*ip = i;
while (count) {
if (!fill_hash(bmap, i, bnds)) {
@ -428,7 +437,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
continue;
}
#if DEBUG
fprintf(stderr, "entries=%ld collisions=%ld trys=%ld\n", i->nentries, i->ncollisions, i->ntrys);
fprintf(stderr, "entries=%ld collisions=%ld (max=%ld) trys=%ld\n", i->nentries, i->ncollisions, i->max_col_count, i->ntrys);
#endif
if (!i->ntrys && !i->is_key) {
i->is_key = TRUE;
@ -533,7 +542,8 @@ Yap_ExoLookup(PredEntry *ap USES_REGS)
return code;
if (i->is_udi)
return ((CEnterExoIndex)i->udi_first)(i PASS_REGS);
else return code;
else
return code;
} else if(i->is_udi) {
return ((CEnterExoIndex)i->udi_first)(i PASS_REGS);
} else {

View File

@ -47,30 +47,47 @@ compar(const void *ip0, const void *jp0) {
return IntOfTerm(i)-IntOfTerm(j);
}
static Int
cmp_extra_args(CELL *si, CELL *sj, struct index_t *it)
{
UInt m = it->udi_free_args;
UInt m0 = 1, x;
for (x=0; x< it->arity; x++) {
if (m0 & m) {
if (si[x] != sj[x]) {
if (IsIntTerm(si[x]))
return IntOfTerm(si[x])-IntOfTerm(sj[x]);
return AtomOfTerm(si[x])-AtomOfTerm(sj[x]);
}
m -= m0;
if (m == 0)
return 0;
}
m0 <<= 1;
}
return 0;
}
static int
compar2(const void *ip0, const void *jp0) {
CACHE_REGS
BITS32 *ip = (BITS32 *)ip0, *jp = (BITS32 *)jp0;
struct index_t *it = LOCAL_exo_it;
Term* si = EXO_OFFSET_TO_ADDRESS(it, *ip);
Term* sj = EXO_OFFSET_TO_ADDRESS(it, *jp);
int cmp = cmp_extra_args(si, sj, it);
if (cmp)
return cmp;
return IntOfTerm(si[LOCAL_exo_arg])-IntOfTerm(sj[LOCAL_exo_arg]);
}
static int
compare(const BITS32 *ip, Int j USES_REGS) {
Term i = EXO_OFFSET_TO_ADDRESS(LOCAL_exo_it, *ip)[LOCAL_exo_arg];
//fprintf(stderr, "%ld-%ld\n", IntOfTerm(i), j);
return IntOfTerm(i)-j;
}
static int
same_free(BITS32 i, BITS32 j, struct index_t *it) {
CELL *ip = EXO_OFFSET_TO_ADDRESS(it, i);
CELL *jp = EXO_OFFSET_TO_ADDRESS(it, j);
UInt m = it->udi_free_args, m0 = 1, x;
for (x=0; x< it->arity; x++) {
if (m0 & m) {
if (ip[x] != jp[x])
return FALSE;
m -= m0;
if (!m)
return TRUE;
}
m0 <<= 1;
}
return TRUE;
}
}
static UInt free_args(UInt b[], UInt arity, UInt i) {
UInt j;
@ -83,46 +100,94 @@ static UInt free_args(UInt b[], UInt arity, UInt i) {
return rc;
}
static void
chain(BITS32 *p0, BITS32 *el, BITS32 n, struct index_t *it) {
UInt i;
static BITS32*
NEXT_DIFFERENT(BITS32 *pt0, BITS32 *pte, struct index_t *it)
{
Term* si = EXO_OFFSET_TO_ADDRESS(it, pt0[0]);
Term* sj;
for (i=0; i<n; i++) {
UInt j, k = i;
if (p0[i])
continue;
p0[i] = i;
for (j=i+1; j<n; j++) {
if (same_free(el[i], el[j], it)) {
p0[j] = k;
k = j;
}
}
}
do {
pt0++;
if (pt0 == pte)
return NULL;
sj = EXO_OFFSET_TO_ADDRESS(it, *pt0);
} while (!cmp_extra_args(si, sj, it));
return pt0;
}
static Int
NEXT_DIFFERENT(Int x0, Int x, BITS32 *p, Int xe)
static BITS32*
PREV_DIFFERENT(BITS32 *pt0, BITS32 *pte, struct index_t *it)
{
while (x <= xe) {
x++;
if (p[x] < x0 || p[x] >= x)
return x;
}
return x;
Term* si = EXO_OFFSET_TO_ADDRESS(it, pt0[0]);
Term* sj;
do {
pt0--;
if (pt0 == pte)
return NULL;
sj = EXO_OFFSET_TO_ADDRESS(it, *pt0);
} while (!cmp_extra_args(si, sj, it));
return pt0;
}
static Int
BIGGEST_EL(Int x0, BITS32 *p, Int xe)
static BITS32*
NEXT_MIN(BITS32 *pt0, BITS32 *pte, Term tmin, Term tmax, struct index_t *it)
{
Int x = x0;
Term* si = EXO_OFFSET_TO_ADDRESS(it, pt0[0]);
int do_min, do_max;
Int min = 0, max = 0;
while (x <= xe) {
if (p[x] == x0)
x0 = x;
x++;
if (IsVarTerm(tmin)) {
do_min = FALSE;
} else {
do_min = TRUE;
min = IntOfTerm(tmin);
}
return x0;
if (IsVarTerm(tmax)) {
do_max = FALSE;
} else {
do_max = TRUE;
max = IntOfTerm(tmax);
}
while ((do_min && IntOfTerm(si[it->udi_arg]) < min) ||
(do_max && IntOfTerm(si[it->udi_arg]) > max)) {
pt0++;
if (pt0 == pte)
return NULL;
si = EXO_OFFSET_TO_ADDRESS(it, *pt0);
}
return pt0;
}
static BITS32*
NEXT_MAX(BITS32 *pt0, BITS32 *pte, Term tmin, Term tmax, struct index_t *it)
{
Term* si = EXO_OFFSET_TO_ADDRESS(it, pt0[0]);
int do_min, do_max;
Int min = 0, max = 0;
if (IsVarTerm(tmin)) {
do_min = FALSE;
} else {
do_min = TRUE;
min = IntOfTerm(tmin);
}
if (IsVarTerm(tmax)) {
do_max = FALSE;
} else {
do_max = TRUE;
max = IntOfTerm(tmax);
}
while ((do_min && IntOfTerm(si[it->udi_arg]) < min) ||
(do_max && IntOfTerm(si[it->udi_arg]) > max)) {
pt0--;
if (pt0 == pte)
return NULL;
si = EXO_OFFSET_TO_ADDRESS(it, *pt0);
}
return pt0;
}
static void
@ -161,11 +226,11 @@ IntervalUDIRefitIndex(struct index_t **ip, UInt b[] USES_REGS)
/* be conservative */
if (it->udi_free_args)
sz = sizeof(BITS32)*(3*it->ntrys+3*it->nentries);
sz = sizeof(BITS32)*(2*it->ntrys+3*it->nentries);
else
sz = sizeof(BITS32)*(2*it->ntrys+2*it->nentries);
sz = sizeof(BITS32)*(it->ntrys+2*it->nentries);
/* allocate space */
if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz)))
if (!(it->udi_data = (BITS32*)malloc(sz)))
return;
sorted0 = sorted = (BITS32 *)it->udi_data;
sorted++; /* leave an initial hole */
@ -189,18 +254,16 @@ IntervalUDIRefitIndex(struct index_t **ip, UInt b[] USES_REGS)
*s0 = sorted - (s0+1);
qsort(s0+1, (size_t)*s0, sizeof(BITS32), compar);
it->links[offset0] = s0-sorted0;
// fprintf(stderr," %d links %d=%d \n", offset0, s0-sorted0, s0[0]);
if (it->udi_free_args) {
bzero(sorted, sizeof(BITS32)*(*s0));
/* chain elements with same unbound vars together */
chain(sorted, s0+1, *s0, it);
memcpy(sorted, s0+1, sizeof(BITS32)*(*s0));
qsort(sorted, (size_t)*s0, sizeof(BITS32), compar2);
sorted += *s0;
}
}
}
}
sz = sizeof(BITS32)*(sorted-sorted0);
it->udi_data = (BITS32 *)Yap_ReallocCodeSpace((char *)it->udi_data, sz);
it->udi_data = (BITS32 *)realloc((char *)it->udi_data, sz);
}
it->is_udi = i+1;
code = it->code;
@ -362,43 +425,48 @@ Interval(struct index_t *it, Term min, Term max, Term op, BITS32 off USES_REGS)
return FAILCODE;
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
} else if (at == AtomMin) {
Int x0, xe, x;
if (!(it->udi_free_args)) {
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
if (it->udi_free_args) {
BITS32 *ptn;
pt = c+(it->links[off]+n+1);
end = pt+n;
pt = NEXT_MIN(pt, end, min, max, it);
if (!pt)
return FAILCODE;
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
} else {
x0 = pt-pt0;
xe = end-pt0;
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
x = NEXT_DIFFERENT(x0, x0, end0, xe);
if (x < xe ) {
YENV[-5] = (CELL)( pt0 ); // base for array of pointed pointers
YENV[-4] = MkIntegerTerm( x ); // where we are in pt0 array
YENV[-3] = MkIntegerTerm( xe ); // our visit will end here
YENV[-2] = MkIntegerTerm( x0 ); // our visit started here
YENV[-1] = (CELL)( end0 ); // base for array into pt
ptn = NEXT_DIFFERENT(pt, end, it);
if (ptn)
ptn = NEXT_MIN(ptn, end, min, max, it);
if ( ptn ) {
YENV[-1] = min; // what we are doing
YENV[-2] = max; // what we are doing
YENV[-3] = (CELL) end; // what we are doing
YENV[-4] = MkAtomTerm(AtomMin); // what we are doing
YENV[-5] = (CELL)( ptn ); // where we are in pt0 array
YENV -= 5;
return it->code;
}
}
return NEXTOP(NEXTOP(it->code,lp),lp);
} else if (at == AtomMax) {
Int x0, xe, x, y;
if (!(it->udi_free_args)) {
S = EXO_OFFSET_TO_ADDRESS(it, end[0]);
} else {
x0 = pt-pt0;
xe = end-pt0;
y = BIGGEST_EL( x0, end0, xe );
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
if (it->udi_free_args) {
BITS32 *ptn;
end = c+(it->links[off]+n);
pt = end+n;
pt = NEXT_MAX(pt, end, min, max, it);
if (!pt)
return FAILCODE;
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
x = NEXT_DIFFERENT(x0, x0, end0, xe);
if (x < xe ) {
YENV[-5] = (CELL)( pt0 ); // base for array of pointed pointers
YENV[-4] = MkIntegerTerm( -x ); // where we are in pt0 array
YENV[-3] = MkIntegerTerm( xe ); // our visit will end here
YENV[-2] = MkIntegerTerm( x0 ); // our visit started here
YENV[-1] = (CELL)( end0 ); // base for array into pt
ptn = PREV_DIFFERENT(pt, end, it);
if (ptn)
ptn = NEXT_MAX(ptn, end, min, max, it);
if ( ptn ) {
YENV[-1] = min; // what we are doing
YENV[-2] = max; // what we are doing
YENV[-3] = (CELL) end; // what we are doing
YENV[-4] = MkAtomTerm(AtomMax); // what we are doing
YENV[-5] = (CELL)( ptn ); // where we are in pt0 array
YENV -= 5;
return it->code;
}
@ -450,28 +518,25 @@ IntervalRetryUDIIndex(struct index_t *it USES_REGS)
w[1] = (CELL)pt;
} else {
BITS32 *pt0 = (BITS32 *)w[1];
Int x = IntegerOfTerm( w[2] );
Int xe = IntegerOfTerm( w[3] );
Int x0 = IntegerOfTerm( w[4] );
BITS32 *base = (BITS32 *)w[5];
if ( x > 0) {
//Yap_DebugPlWrite( EXO_OFFSET_TO_ADDRESS(it, el[i])[1] ); fprintf(stderr,"\n");
S = EXO_OFFSET_TO_ADDRESS(it, pt0[x]);
//fprintf(stderr,"S=%p x=%d/%d %d %d %p %p \n", S, x, base[x], x0, xe, pt0, base);
x = NEXT_DIFFERENT(x0, x, base, xe);
if (x > xe) return FALSE;
w[2] = MkIntegerTerm(x);
BITS32 *pte = (BITS32 *)w[3];
Atom what = AtomOfTerm(w[2]);
Term min = w[5];
Term max = w[4];
S = EXO_OFFSET_TO_ADDRESS(it, pt0[0]);
if ( what == AtomMin ) {
pt0 = NEXT_DIFFERENT(pt0, pte, it);
if (pt0)
pt0 = NEXT_MIN(pt0, pte, min, max, it);
} else {
x = -x;
//Yap_DebugPlWrite( EXO_OFFSET_TO_ADDRESS(it, el[i])[1] ); fprintf(stderr,"\n");
S = EXO_OFFSET_TO_ADDRESS(it, pt0[BIGGEST_EL(x, base, xe) ]);
x = NEXT_DIFFERENT(x0, x, base, xe);
// fprintf(stderr,"S=%p x=%d/%d %d %d %p %p \n", S, x, base[x], x0, xe, pt0, base);
if (x > xe) {
return FALSE;
}
w[2] = MkIntegerTerm(-x);
pt0 = PREV_DIFFERENT(pt0, pte, it);
if (pt0)
pt0 = NEXT_MAX(pt0, pte, min, max, it);
}
if (!pt0) {
return FALSE;
}
w[1] = (CELL)pt0;
}
return TRUE;
}

View File

@ -1556,6 +1556,7 @@ mark_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
Int bmap = 0;
int currv = 0;
// printf("MARK %p--%p\n", gc_ENV, gc_ENV-size);
#ifdef DEBUG
if (size < 0 || size > 512)
fprintf(GLOBAL_stderr,"OOPS in GC: env size for %p is " UInt_FORMAT "\n", gc_ENV, (CELL)size);
@ -2007,6 +2008,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
// fprintf(stderr, "%s\n", Yap_op_names[opnum]);
#ifdef TABLING
}
// printf("MARK CP %p (%d)\n", gc_B, opnum);
if (aux_sg_fr && gc_B == SgFr_gen_cp(aux_sg_fr)) {
aux_sg_fr = SgFr_next(aux_sg_fr);
}
@ -2046,18 +2048,22 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
/* choicepoint with arguments */
register CELL_PTR saved_reg;
OPREG nargs;
//printf("gc_B=%p %ld\n", gc_B, opnum);
if (opnum == _Nstop)
mark_environments((CELL_PTR) gc_B->cp_env,
EnvSizeInCells,
NULL PASS_REGS);
else if (opnum != _trust_fail)
else if (opnum != _trust_fail) {
Int mark = TRUE;
#ifdef DETERMINISTIC_TABLING
if (!IS_DET_GEN_CP(gc_B))
mark &= !IS_DET_GEN_CP(gc_B);
#endif /* DETERMINISTIC_TABLING */
if (mark)
mark_environments((CELL_PTR) gc_B->cp_env,
EnvSize((yamop *) (gc_B->cp_cp)),
EnvBMap((yamop *) (gc_B->cp_cp)) PASS_REGS);
}
/* extended choice point */
restart_cp:
switch (opnum) {
@ -2169,10 +2175,10 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
CELL *vars_ptr, vars;
dep_fr_ptr dep_fr = CONS_CP(gc_B)->cp_dep_fr;
ans_node_ptr ans_node = DepFr_last_answer(dep_fr);
if (TrNode_child(ans_node)) {
if (TRUE || TrNode_child(ans_node)) {
/* unconsumed answers */
#ifdef MODE_DIRECTED_TABLING
if (IS_ANSWER_INVALID_NODE(TrNode_child(ans_node))) {
if (TrNode_child(ans_node) && IS_ANSWER_INVALID_NODE(TrNode_child(ans_node))) {
ans_node_ptr old_ans_node;
old_ans_node = ans_node;
ans_node = TrNode_child(ans_node);
@ -2183,15 +2189,15 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
} else
#endif /* MODE_DIRECTED_TABLING */
ans_node = TrNode_child(ans_node);
if (gc_B == DepFr_leader_cp(dep_fr)) { \
/* gc_B is a generator-consumer node */ \
/* never here if batched scheduling */ \
TABLING_ERROR_CHECKING(generator_consumer, IS_BATCHED_GEN_CP(gc_B)); \
vars_ptr = (CELL *) (GEN_CP(gc_B) + 1); \
vars_ptr += SgFr_arity(GEN_CP(gc_B)->cp_sg_fr); \
} else { \
vars_ptr = (CELL *) (CONS_CP(gc_B) + 1); \
} \
if (gc_B == DepFr_leader_cp(dep_fr)) {
/* gc_B is a generator-consumer node */
/* never here if batched scheduling */
TABLING_ERROR_CHECKING(generator_consumer, IS_BATCHED_GEN_CP(gc_B));
vars_ptr = (CELL *) (GEN_CP(gc_B) + 1);
vars_ptr += SgFr_arity(GEN_CP(gc_B)->cp_sg_fr);
} else {
vars_ptr = (CELL *) (CONS_CP(gc_B) + 1);
}
vars = *vars_ptr++;
while (vars--) {
@ -2867,6 +2873,7 @@ sweep_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap USES_REGS)
Int bmap = 0;
int currv = 0;
// printf("SWEEP %p--%p\n", gc_ENV, gc_ENV-size);
/* for each saved variable */
@ -3142,10 +3149,10 @@ sweep_choicepoints(choiceptr gc_B USES_REGS)
CELL *vars_ptr, vars;
dep_fr_ptr dep_fr = CONS_CP(gc_B)->cp_dep_fr;
ans_node_ptr ans_node = DepFr_last_answer(dep_fr);
if (TrNode_child(ans_node)) {
if (TRUE || TrNode_child(ans_node)) {
/* unconsumed answers */
#ifdef MODE_DIRECTED_TABLING
if (IS_ANSWER_INVALID_NODE(TrNode_child(ans_node))) {
if (TrNode_child(ans_node) && IS_ANSWER_INVALID_NODE(TrNode_child(ans_node))) {
ans_node_ptr old_ans_node;
old_ans_node = ans_node;
ans_node = TrNode_child(ans_node);

View File

@ -283,13 +283,9 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
ch = getchrq(inp_stream);
switch (ch) {
case 10:
do {
ch = getchrq(inp_stream);
if (ch == '\\') goto restart;
if (chtype(ch) != BS || ch == 10) {
return ch;
}
} while (TRUE);
return 0;
case '\\':
return '\\';
case 'a':
return '\a';
case 'b':
@ -364,12 +360,7 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
case 'v':
return '\v';
case 'z': /* Prolog end-of-file */
if (yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
return send_error_message("invalid escape sequence \\z");
} else
return -1;
case '\\':
return '\\';
return send_error_message("invalid escape sequence \\z");
case '\'':
return '\'';
case '"':
@ -486,16 +477,7 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
/* accept sequence. Note that the ISO standard does not
consider this sequence legal, whereas SICStus would
eat up the escape sequence. */
if (yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
return send_error_message("invalid escape sequence");
} else {
/* sicstus */
if (chtype(ch) == SL) {
goto restart;
} else {
return ch;
}
}
return send_error_message("invalid escape sequence");
}
}
@ -1142,8 +1124,9 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp)
ch = getchrq(inp_stream);
} else if (ch == '\\' && yap_flags[CHARACTER_ESCAPE_FLAG] != CPROLOG_CHARACTER_ESCAPES) {
int scan_next = TRUE;
ch = read_quoted_char(&scan_next, inp_stream);
add_ch_to_buff(ch);
if ((ch = read_quoted_char(&scan_next, inp_stream))) {
add_ch_to_buff(ch);
}
if (scan_next) {
ch = getchrq(inp_stream);
}

View File

@ -1825,7 +1825,7 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Ter
Term t2 = Deref(inp);
if (IsVarTerm(t2)) {
RESET_VARIABLE(H-1);
Yap_unify((CELL)(H-1),ARG2);
Yap_unify((CELL)(H-1),inp);
} else {
H[-1] = t2; /* don't need to trail */
}
@ -2140,7 +2140,7 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
Term t2 = Deref(inp);
if (IsVarTerm(t2)) {
RESET_VARIABLE(H-1);
Yap_unify((CELL)(H-1),ARG2);
Yap_unify((CELL)(H-1), t2);
} else {
H[-1] = t2; /* don't need to trail */
}

View File

@ -218,10 +218,22 @@ CpFloatUnaligned(CELL *ptr)
#if SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT
INLINE_ONLY inline EXTERN void AlignGlobalForDouble( USES_REGS1 );
#define DOUBLE_ALIGNED(ADDR) ((CELL)(ADDR) & 0x4)
INLINE_ONLY EXTERN inline void
AlignGlobalForDouble( USES_REGS1 );
INLINE_ONLY EXTERN inline void
AlignGlobalForDouble( USES_REGS1 )
{
/* Force Alignment for floats. Note that garbage collector may
break the alignment; */
if (!DOUBLE_ALIGNED(H)) {
RESET_VARIABLE(H);
H++;
}
}
#ifdef i386
INLINE_ONLY inline EXTERN Float
CpFloatUnaligned (CELL * ptr)

11
H/Yap.h
View File

@ -844,12 +844,6 @@ extern struct worker_local Yap_local;
#include "dlocals.h"
/*************************************************************************************************
unification support
*************************************************************************************************/
#include "YapCompoundTerm.h"
/*************************************************************************************************
unification routines
*************************************************************************************************/
@ -861,6 +855,11 @@ extern struct worker_local Yap_local;
#include "amiops.h"
#endif /* YAPOR_SBA */
/*************************************************************************************************
unification support
*************************************************************************************************/
#include "YapCompoundTerm.h"

View File

@ -165,6 +165,8 @@ VarOfTerm (Term t)
#ifdef YAPOR_SBA
#define RESET_VARIABLE(V) (*(CELL *)(V) = 0)
INLINE_ONLY inline EXTERN Term MkVarTerm__ ( USES_REGS1 );
INLINE_ONLY inline EXTERN Term
@ -186,6 +188,8 @@ IsUnboundVar (Term * t)
#else
#define RESET_VARIABLE(V) (*(CELL *)(V) = Unsigned(V))
INLINE_ONLY inline EXTERN Term MkVarTerm__ ( USES_REGS1 );
INLINE_ONLY inline EXTERN Term

View File

@ -100,24 +100,6 @@ A contains the address of the variable that is to be trailed
#define RESET_VARIABLE(V) (*(CELL *)(V) = Unsigned(V))
#if SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT
INLINE_ONLY EXTERN inline void
AlignGlobalForDouble( USES_REGS1 );
INLINE_ONLY EXTERN inline void
AlignGlobalForDouble( USES_REGS1 )
{
/* Force Alignment for floats. Note that garbage collector may
break the alignment; */
if (!DOUBLE_ALIGNED(H)) {
RESET_VARIABLE(H);
H++;
}
}
#endif
#ifdef TABLING
#define DO_TRAIL(TERM, VAL) \

View File

@ -168,6 +168,7 @@ typedef struct index_t {
int is_key;
int is_udi;
UInt ncollisions;
UInt max_col_count;
UInt ntrys;
UInt nentries;
UInt hsize;

View File

@ -6,6 +6,9 @@
while (TRUE) {
op_numbers op = Yap_op_from_opcode(cl->opc);
switch (op) {
case _ensure_space:
cl = NEXTOP(cl,Osbpa);
break;
case _native_me:
cl = NEXTOP(cl,aFlp);
break;

18463
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -133,6 +133,8 @@ return 0;
;;
esac
fi
GECODE_MAJOR=`echo $GECODE_VERSION| sed 's/\(^.\).*/\1/'`
AC_SUBST(GECODE_MAJOR)
AC_ARG_ENABLE(tabling,
[ --enable-tabling support tabling ],

View File

@ -4458,6 +4458,29 @@ The following predicates provide counting:
@cnindex plus/3
True if @var{Int3} = @var{Int1} + @var{Int2}. At least two of the
three arguments must be instantiated to integers.
@item logsum(+@var{Log1}, +@var{Log2}, -@var{Out} )
@findex logsum/3
@snindex logsum/3
@cnindex logsum/3
True if @var{Log1} is the logarithm of the positive number @var{A1},
@var{Log2} is the logarithm of the positive number @var{A2}, and
@var{Out} is the logarithm of the sum of the numbers @var{A1} and
@var{A2}. Useful in probability computation.
@item isnan(+@var{Float})
@findex isnan/1
@snindex isnan/1
@cnindex isnan/1
True if @var{Float} is not a number.
@item isinf(+@var{Float})
@findex isinf/1
@snindex isinf/1
@cnindex isinf/1
True if floating point expression @var{Float} evaluates to infinity.
@end table
@node I/O, Database, Arithmetic, Top
@ -9962,6 +9985,13 @@ Unify @var{Elems} with the list including all the elements in @var{Matrix}.
Unify @var{Elem} with the element of @var{Matrix} at position
@var{Position}.
@item matrix_get(+@var{Matrix}[+@var{Position}],-@var{Elem})
@findex matrix_get/2
@snindex matrix_get/2
@cnindex matrix_get/2
Unify @var{Elem} with the element @var{Matrix}[@var{Position}].
@item matrix_set(+@var{Matrix},+@var{Position},+@var{Elem})
@findex matrix_set/3
@snindex matrix_set/3
@ -9970,6 +10000,13 @@ Unify @var{Elem} with the element of @var{Matrix} at position
Set the element of @var{Matrix} at position
@var{Position} to @var{Elem}.
@item matrix_set(+@var{Matrix}[+@var{Position}],+@var{Elem})
@findex matrix_set/2
@snindex matrix_set/2
@cnindex matrix_set/2
Set the element of @var{Matrix}[@var{Position}] to @var{Elem}.
@item matrix_set_all(+@var{Matrix},+@var{Elem})
@findex matrix_set_all/2
@snindex matrix_set_all/2

View File

@ -0,0 +1 @@
4.2.0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
static RestartMode gecode_RestartMode_from_term(YAP_Term);
static FloatRelType gecode_FloatRelType_from_term(YAP_Term);
static ReifyMode gecode_ReifyMode_from_term(YAP_Term);
static IntRelType gecode_IntRelType_from_term(YAP_Term);
static BoolOpType gecode_BoolOpType_from_term(YAP_Term);
static IntConLevel gecode_IntConLevel_from_term(YAP_Term);
static TaskType gecode_TaskType_from_term(YAP_Term);
static ExtensionalPropKind gecode_ExtensionalPropKind_from_term(YAP_Term);
static SetRelType gecode_SetRelType_from_term(YAP_Term);
static SetOpType gecode_SetOpType_from_term(YAP_Term);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,630 @@
// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
{ YAP_Atom X= YAP_LookupAtom("RM_NONE");
gecode_RM_NONE = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_CONSTANT");
gecode_RM_CONSTANT = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_LINEAR");
gecode_RM_LINEAR = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_LUBY");
gecode_RM_LUBY = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_GEOMETRIC");
gecode_RM_GEOMETRIC = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("FRT_EQ");
gecode_FRT_EQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("FRT_NQ");
gecode_FRT_NQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("FRT_LQ");
gecode_FRT_LQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("FRT_LE");
gecode_FRT_LE = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("FRT_GQ");
gecode_FRT_GQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("FRT_GR");
gecode_FRT_GR = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_EQV");
gecode_RM_EQV = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_IMP");
gecode_RM_IMP = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("RM_PMI");
gecode_RM_PMI = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("IRT_EQ");
gecode_IRT_EQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("IRT_NQ");
gecode_IRT_NQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("IRT_LQ");
gecode_IRT_LQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("IRT_LE");
gecode_IRT_LE = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("IRT_GQ");
gecode_IRT_GQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("IRT_GR");
gecode_IRT_GR = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("BOT_AND");
gecode_BOT_AND = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("BOT_OR");
gecode_BOT_OR = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("BOT_IMP");
gecode_BOT_IMP = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("BOT_EQV");
gecode_BOT_EQV = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("BOT_XOR");
gecode_BOT_XOR = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("ICL_VAL");
gecode_ICL_VAL = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("ICL_BND");
gecode_ICL_BND = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("ICL_DOM");
gecode_ICL_DOM = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("ICL_DEF");
gecode_ICL_DEF = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("TT_FIXP");
gecode_TT_FIXP = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("TT_FIXS");
gecode_TT_FIXS = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("TT_FIXE");
gecode_TT_FIXE = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("EPK_DEF");
gecode_EPK_DEF = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("EPK_SPEED");
gecode_EPK_SPEED = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("EPK_MEMORY");
gecode_EPK_MEMORY = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_EQ");
gecode_SRT_EQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_NQ");
gecode_SRT_NQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_SUB");
gecode_SRT_SUB = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_SUP");
gecode_SRT_SUP = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_DISJ");
gecode_SRT_DISJ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_CMPL");
gecode_SRT_CMPL = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_LQ");
gecode_SRT_LQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_LE");
gecode_SRT_LE = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_GQ");
gecode_SRT_GQ = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SRT_GR");
gecode_SRT_GR = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SOT_UNION");
gecode_SOT_UNION = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SOT_DUNION");
gecode_SOT_DUNION = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SOT_INTER");
gecode_SOT_INTER = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
{ YAP_Atom X= YAP_LookupAtom("SOT_MINUS");
gecode_SOT_MINUS = YAP_MkAtomTerm(X);
YAP_AtomGetHold(X); }
YAP_UserCPredicate("gecode_constraint_unary_448", gecode_constraint_unary_448, 6);
YAP_UserCPredicate("gecode_constraint_unary_444", gecode_constraint_unary_444, 6);
YAP_UserCPredicate("gecode_constraint_nvalues_335", gecode_constraint_nvalues_335, 5);
YAP_UserCPredicate("gecode_constraint_nvalues_337", gecode_constraint_nvalues_337, 5);
YAP_UserCPredicate("gecode_constraint_nvalues_331", gecode_constraint_nvalues_331, 5);
YAP_UserCPredicate("gecode_constraint_nvalues_333", gecode_constraint_nvalues_333, 5);
YAP_UserCPredicate("gecode_constraint_max_292", gecode_constraint_max_292, 4);
YAP_UserCPredicate("gecode_constraint_max_290", gecode_constraint_max_290, 4);
YAP_UserCPredicate("gecode_constraint_max_291", gecode_constraint_max_291, 4);
YAP_UserCPredicate("gecode_constraint_max_295", gecode_constraint_max_295, 4);
YAP_UserCPredicate("gecode_constraint_dom_200", gecode_constraint_dom_200, 6);
YAP_UserCPredicate("gecode_constraint_dom_209", gecode_constraint_dom_209, 6);
YAP_UserCPredicate("gecode_constraint_convex_91", gecode_constraint_convex_91, 3);
YAP_UserCPredicate("gecode_constraint_nooverlap_319", gecode_constraint_nooverlap_319, 5);
YAP_UserCPredicate("gecode_constraint_assign_15", gecode_constraint_assign_15, 3);
YAP_UserCPredicate("gecode_constraint_assign_6", gecode_constraint_assign_6, 3);
YAP_UserCPredicate("gecode_constraint_assign_3", gecode_constraint_assign_3, 3);
YAP_UserCPredicate("gecode_constraint_assign_1", gecode_constraint_assign_1, 3);
YAP_UserCPredicate("gecode_constraint_assign_9", gecode_constraint_assign_9, 3);
YAP_UserCPredicate("gecode_constraint_assign_17", gecode_constraint_assign_17, 3);
YAP_UserCPredicate("gecode_constraint_assign_12", gecode_constraint_assign_12, 3);
YAP_UserCPredicate("gecode_constraint_assign_19", gecode_constraint_assign_19, 3);
YAP_UserCPredicate("gecode_constraint_element_220", gecode_constraint_element_220, 4);
YAP_UserCPredicate("gecode_constraint_element_224", gecode_constraint_element_224, 4);
YAP_UserCPredicate("gecode_constraint_element_214", gecode_constraint_element_214, 4);
YAP_UserCPredicate("gecode_constraint_element_212", gecode_constraint_element_212, 4);
YAP_UserCPredicate("gecode_constraint_element_219", gecode_constraint_element_219, 4);
YAP_UserCPredicate("gecode_constraint_element_227", gecode_constraint_element_227, 4);
YAP_UserCPredicate("gecode_constraint_element_230", gecode_constraint_element_230, 4);
YAP_UserCPredicate("gecode_constraint_element_236", gecode_constraint_element_236, 4);
YAP_UserCPredicate("gecode_constraint_element_228", gecode_constraint_element_228, 4);
YAP_UserCPredicate("gecode_constraint_sequence_427", gecode_constraint_sequence_427, 2);
YAP_UserCPredicate("gecode_constraint_notMax_325", gecode_constraint_notMax_325, 3);
YAP_UserCPredicate("gecode_constraint_ite_246", gecode_constraint_ite_246, 5);
YAP_UserCPredicate("gecode_constraint_unary_441", gecode_constraint_unary_441, 3);
YAP_UserCPredicate("gecode_constraint_nroot_329", gecode_constraint_nroot_329, 5);
YAP_UserCPredicate("gecode_constraint_circuit_85", gecode_constraint_circuit_85, 4);
YAP_UserCPredicate("gecode_constraint_circuit_76", gecode_constraint_circuit_76, 4);
YAP_UserCPredicate("gecode_constraint_dom_199", gecode_constraint_dom_199, 5);
YAP_UserCPredicate("gecode_constraint_dom_198", gecode_constraint_dom_198, 5);
YAP_UserCPredicate("gecode_constraint_dom_202", gecode_constraint_dom_202, 5);
YAP_UserCPredicate("gecode_constraint_dom_194", gecode_constraint_dom_194, 5);
YAP_UserCPredicate("gecode_constraint_dom_185", gecode_constraint_dom_185, 5);
YAP_UserCPredicate("gecode_constraint_dom_181", gecode_constraint_dom_181, 5);
YAP_UserCPredicate("gecode_constraint_dom_187", gecode_constraint_dom_187, 5);
YAP_UserCPredicate("gecode_constraint_dom_208", gecode_constraint_dom_208, 5);
YAP_UserCPredicate("gecode_constraint_dom_210", gecode_constraint_dom_210, 5);
YAP_UserCPredicate("gecode_constraint_dom_206", gecode_constraint_dom_206, 5);
YAP_UserCPredicate("gecode_constraint_channel_66", gecode_constraint_channel_66, 4);
YAP_UserCPredicate("gecode_constraint_channel_62", gecode_constraint_channel_62, 4);
YAP_UserCPredicate("gecode_constraint_channel_60", gecode_constraint_channel_60, 4);
YAP_UserCPredicate("gecode_constraint_nooverlap_321", gecode_constraint_nooverlap_321, 8);
YAP_UserCPredicate("gecode_constraint_nooverlap_324", gecode_constraint_nooverlap_324, 8);
YAP_UserCPredicate("gecode_constraint_element_222", gecode_constraint_element_222, 7);
YAP_UserCPredicate("gecode_constraint_element_216", gecode_constraint_element_216, 7);
YAP_UserCPredicate("gecode_constraint_element_218", gecode_constraint_element_218, 7);
YAP_UserCPredicate("gecode_constraint_element_226", gecode_constraint_element_226, 7);
YAP_UserCPredicate("gecode_constraint_element_234", gecode_constraint_element_234, 7);
YAP_UserCPredicate("gecode_constraint_element_232", gecode_constraint_element_232, 7);
YAP_UserCPredicate("gecode_constraint_max_288", gecode_constraint_max_288, 3);
YAP_UserCPredicate("gecode_constraint_max_289", gecode_constraint_max_289, 3);
YAP_UserCPredicate("gecode_constraint_max_294", gecode_constraint_max_294, 3);
YAP_UserCPredicate("gecode_constraint_unshare_453", gecode_constraint_unshare_453, 2);
YAP_UserCPredicate("gecode_constraint_unshare_451", gecode_constraint_unshare_451, 2);
YAP_UserCPredicate("gecode_constraint_path_348", gecode_constraint_path_348, 5);
YAP_UserCPredicate("gecode_constraint_path_347", gecode_constraint_path_347, 5);
YAP_UserCPredicate("gecode_constraint_branch_34", gecode_constraint_branch_34, 7);
YAP_UserCPredicate("gecode_constraint_branch_28", gecode_constraint_branch_28, 7);
YAP_UserCPredicate("gecode_constraint_branch_40", gecode_constraint_branch_40, 7);
YAP_UserCPredicate("gecode_constraint_mult_315", gecode_constraint_mult_315, 4);
YAP_UserCPredicate("gecode_constraint_mult_314", gecode_constraint_mult_314, 4);
YAP_UserCPredicate("gecode_constraint_clause_89", gecode_constraint_clause_89, 6);
YAP_UserCPredicate("gecode_constraint_clause_87", gecode_constraint_clause_87, 6);
YAP_UserCPredicate("gecode_constraint_precede_356", gecode_constraint_precede_356, 5);
YAP_UserCPredicate("gecode_constraint_distinct_160", gecode_constraint_distinct_160, 2);
YAP_UserCPredicate("gecode_constraint_member_302", gecode_constraint_member_302, 4);
YAP_UserCPredicate("gecode_constraint_member_301", gecode_constraint_member_301, 4);
YAP_UserCPredicate("gecode_constraint_member_298", gecode_constraint_member_298, 4);
YAP_UserCPredicate("gecode_constraint_member_297", gecode_constraint_member_297, 4);
YAP_UserCPredicate("gecode_constraint_mod_313", gecode_constraint_mod_313, 5);
YAP_UserCPredicate("gecode_constraint_cardinality_57", gecode_constraint_cardinality_57, 3);
YAP_UserCPredicate("gecode_constraint_atmostOne_53", gecode_constraint_atmostOne_53, 3);
YAP_UserCPredicate("gecode_constraint_channelSorted_73", gecode_constraint_channelSorted_73, 3);
YAP_UserCPredicate("gecode_constraint_linear_262", gecode_constraint_linear_262, 4);
YAP_UserCPredicate("gecode_constraint_linear_260", gecode_constraint_linear_260, 4);
YAP_UserCPredicate("gecode_constraint_linear_248", gecode_constraint_linear_248, 4);
YAP_UserCPredicate("gecode_constraint_linear_252", gecode_constraint_linear_252, 4);
YAP_UserCPredicate("gecode_constraint_linear_280", gecode_constraint_linear_280, 4);
YAP_UserCPredicate("gecode_constraint_linear_284", gecode_constraint_linear_284, 4);
YAP_UserCPredicate("gecode_constraint_circuit_82", gecode_constraint_circuit_82, 2);
YAP_UserCPredicate("gecode_constraint_rel_396", gecode_constraint_rel_396, 5);
YAP_UserCPredicate("gecode_constraint_rel_398", gecode_constraint_rel_398, 5);
YAP_UserCPredicate("gecode_constraint_rel_412", gecode_constraint_rel_412, 5);
YAP_UserCPredicate("gecode_constraint_rel_410", gecode_constraint_rel_410, 5);
YAP_UserCPredicate("gecode_constraint_rel_382", gecode_constraint_rel_382, 5);
YAP_UserCPredicate("gecode_constraint_rel_378", gecode_constraint_rel_378, 5);
YAP_UserCPredicate("gecode_constraint_rel_376", gecode_constraint_rel_376, 5);
YAP_UserCPredicate("gecode_constraint_rel_373", gecode_constraint_rel_373, 5);
YAP_UserCPredicate("gecode_constraint_rel_372", gecode_constraint_rel_372, 5);
YAP_UserCPredicate("gecode_constraint_rel_369", gecode_constraint_rel_369, 5);
YAP_UserCPredicate("gecode_constraint_rel_368", gecode_constraint_rel_368, 5);
YAP_UserCPredicate("gecode_constraint_rel_365", gecode_constraint_rel_365, 5);
YAP_UserCPredicate("gecode_constraint_rel_363", gecode_constraint_rel_363, 5);
YAP_UserCPredicate("gecode_constraint_rel_392", gecode_constraint_rel_392, 5);
YAP_UserCPredicate("gecode_constraint_rel_394", gecode_constraint_rel_394, 5);
YAP_UserCPredicate("gecode_constraint_rel_388", gecode_constraint_rel_388, 5);
YAP_UserCPredicate("gecode_constraint_rel_401", gecode_constraint_rel_401, 5);
YAP_UserCPredicate("gecode_constraint_rel_400", gecode_constraint_rel_400, 5);
YAP_UserCPredicate("gecode_constraint_rel_405", gecode_constraint_rel_405, 5);
YAP_UserCPredicate("gecode_constraint_rel_404", gecode_constraint_rel_404, 5);
YAP_UserCPredicate("gecode_constraint_rel_409", gecode_constraint_rel_409, 5);
YAP_UserCPredicate("gecode_constraint_rel_420", gecode_constraint_rel_420, 5);
YAP_UserCPredicate("gecode_constraint_rel_422", gecode_constraint_rel_422, 5);
YAP_UserCPredicate("gecode_constraint_rel_362", gecode_constraint_rel_362, 5);
YAP_UserCPredicate("gecode_constraint_rel_360", gecode_constraint_rel_360, 5);
YAP_UserCPredicate("gecode_constraint_min_308", gecode_constraint_min_308, 4);
YAP_UserCPredicate("gecode_constraint_min_306", gecode_constraint_min_306, 4);
YAP_UserCPredicate("gecode_constraint_min_307", gecode_constraint_min_307, 4);
YAP_UserCPredicate("gecode_constraint_min_311", gecode_constraint_min_311, 4);
YAP_UserCPredicate("gecode_constraint_cardinality_56", gecode_constraint_cardinality_56, 4);
YAP_UserCPredicate("gecode_constraint_cardinality_58", gecode_constraint_cardinality_58, 4);
YAP_UserCPredicate("gecode_constraint_count_109", gecode_constraint_count_109, 4);
YAP_UserCPredicate("gecode_constraint_count_106", gecode_constraint_count_106, 4);
YAP_UserCPredicate("gecode_constraint_count_100", gecode_constraint_count_100, 4);
YAP_UserCPredicate("gecode_constraint_count_99", gecode_constraint_count_99, 4);
YAP_UserCPredicate("gecode_constraint_count_96", gecode_constraint_count_96, 4);
YAP_UserCPredicate("gecode_constraint_sqrt_437", gecode_constraint_sqrt_437, 3);
YAP_UserCPredicate("gecode_constraint_sqrt_436", gecode_constraint_sqrt_436, 3);
YAP_UserCPredicate("gecode_constraint_cumulatives_157", gecode_constraint_cumulatives_157, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_155", gecode_constraint_cumulatives_155, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_153", gecode_constraint_cumulatives_153, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_151", gecode_constraint_cumulatives_151, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_149", gecode_constraint_cumulatives_149, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_147", gecode_constraint_cumulatives_147, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_145", gecode_constraint_cumulatives_145, 9);
YAP_UserCPredicate("gecode_constraint_cumulatives_143", gecode_constraint_cumulatives_143, 9);
YAP_UserCPredicate("gecode_constraint_nvalues_334", gecode_constraint_nvalues_334, 4);
YAP_UserCPredicate("gecode_constraint_nvalues_336", gecode_constraint_nvalues_336, 4);
YAP_UserCPredicate("gecode_constraint_nvalues_330", gecode_constraint_nvalues_330, 4);
YAP_UserCPredicate("gecode_constraint_nvalues_332", gecode_constraint_nvalues_332, 4);
YAP_UserCPredicate("gecode_constraint_binpacking_54", gecode_constraint_binpacking_54, 4);
YAP_UserCPredicate("gecode_constraint_linear_275", gecode_constraint_linear_275, 7);
YAP_UserCPredicate("gecode_constraint_linear_279", gecode_constraint_linear_279, 7);
YAP_UserCPredicate("gecode_constraint_linear_267", gecode_constraint_linear_267, 7);
YAP_UserCPredicate("gecode_constraint_linear_271", gecode_constraint_linear_271, 7);
YAP_UserCPredicate("gecode_constraint_abs_52", gecode_constraint_abs_52, 4);
YAP_UserCPredicate("gecode_constraint_convex_90", gecode_constraint_convex_90, 2);
YAP_UserCPredicate("gecode_constraint_div_163", gecode_constraint_div_163, 4);
YAP_UserCPredicate("gecode_constraint_div_162", gecode_constraint_div_162, 4);
YAP_UserCPredicate("gecode_constraint_rel_402", gecode_constraint_rel_402, 6);
YAP_UserCPredicate("gecode_constraint_rel_406", gecode_constraint_rel_406, 6);
YAP_UserCPredicate("gecode_constraint_rel_385", gecode_constraint_rel_385, 6);
YAP_UserCPredicate("gecode_constraint_rel_386", gecode_constraint_rel_386, 6);
YAP_UserCPredicate("gecode_constraint_rel_374", gecode_constraint_rel_374, 6);
YAP_UserCPredicate("gecode_constraint_rel_370", gecode_constraint_rel_370, 6);
YAP_UserCPredicate("gecode_constraint_rel_366", gecode_constraint_rel_366, 6);
YAP_UserCPredicate("gecode_constraint_rel_364", gecode_constraint_rel_364, 6);
YAP_UserCPredicate("gecode_constraint_rel_415", gecode_constraint_rel_415, 6);
YAP_UserCPredicate("gecode_constraint_rel_416", gecode_constraint_rel_416, 6);
YAP_UserCPredicate("gecode_constraint_rel_417", gecode_constraint_rel_417, 6);
YAP_UserCPredicate("gecode_constraint_rel_418", gecode_constraint_rel_418, 6);
YAP_UserCPredicate("gecode_constraint_weights_455", gecode_constraint_weights_455, 5);
YAP_UserCPredicate("gecode_constraint_max_293", gecode_constraint_max_293, 5);
YAP_UserCPredicate("gecode_constraint_path_343", gecode_constraint_path_343, 9);
YAP_UserCPredicate("gecode_constraint_unary_449", gecode_constraint_unary_449, 4);
YAP_UserCPredicate("gecode_constraint_unary_445", gecode_constraint_unary_445, 4);
YAP_UserCPredicate("gecode_constraint_unary_439", gecode_constraint_unary_439, 4);
YAP_UserCPredicate("gecode_constraint_unary_442", gecode_constraint_unary_442, 4);
YAP_UserCPredicate("gecode_constraint_nroot_328", gecode_constraint_nroot_328, 4);
YAP_UserCPredicate("gecode_constraint_nroot_327", gecode_constraint_nroot_327, 4);
YAP_UserCPredicate("gecode_constraint_sorted_430", gecode_constraint_sorted_430, 5);
YAP_UserCPredicate("gecode_constraint_circuit_80", gecode_constraint_circuit_80, 5);
YAP_UserCPredicate("gecode_constraint_circuit_77", gecode_constraint_circuit_77, 5);
YAP_UserCPredicate("gecode_constraint_circuit_74", gecode_constraint_circuit_74, 5);
YAP_UserCPredicate("gecode_constraint_dom_189", gecode_constraint_dom_189, 4);
YAP_UserCPredicate("gecode_constraint_dom_186", gecode_constraint_dom_186, 4);
YAP_UserCPredicate("gecode_constraint_dom_172", gecode_constraint_dom_172, 4);
YAP_UserCPredicate("gecode_constraint_dom_170", gecode_constraint_dom_170, 4);
YAP_UserCPredicate("gecode_constraint_dom_168", gecode_constraint_dom_168, 4);
YAP_UserCPredicate("gecode_constraint_dom_180", gecode_constraint_dom_180, 4);
YAP_UserCPredicate("gecode_constraint_dom_179", gecode_constraint_dom_179, 4);
YAP_UserCPredicate("gecode_constraint_dom_177", gecode_constraint_dom_177, 4);
YAP_UserCPredicate("gecode_constraint_dom_175", gecode_constraint_dom_175, 4);
YAP_UserCPredicate("gecode_constraint_dom_197", gecode_constraint_dom_197, 4);
YAP_UserCPredicate("gecode_constraint_dom_201", gecode_constraint_dom_201, 4);
YAP_UserCPredicate("gecode_constraint_dom_196", gecode_constraint_dom_196, 4);
YAP_UserCPredicate("gecode_constraint_dom_204", gecode_constraint_dom_204, 4);
YAP_UserCPredicate("gecode_constraint_dom_193", gecode_constraint_dom_193, 4);
YAP_UserCPredicate("gecode_constraint_dom_192", gecode_constraint_dom_192, 4);
YAP_UserCPredicate("gecode_constraint_dom_184", gecode_constraint_dom_184, 4);
YAP_UserCPredicate("gecode_constraint_dom_183", gecode_constraint_dom_183, 4);
YAP_UserCPredicate("gecode_constraint_dom_207", gecode_constraint_dom_207, 4);
YAP_UserCPredicate("gecode_constraint_dom_205", gecode_constraint_dom_205, 4);
YAP_UserCPredicate("gecode_constraint_abs_51", gecode_constraint_abs_51, 3);
YAP_UserCPredicate("gecode_constraint_abs_50", gecode_constraint_abs_50, 3);
YAP_UserCPredicate("gecode_constraint_channel_68", gecode_constraint_channel_68, 5);
YAP_UserCPredicate("gecode_constraint_channel_63", gecode_constraint_channel_63, 5);
YAP_UserCPredicate("gecode_constraint_assign_8", gecode_constraint_assign_8, 5);
YAP_UserCPredicate("gecode_constraint_assign_5", gecode_constraint_assign_5, 5);
YAP_UserCPredicate("gecode_constraint_assign_11", gecode_constraint_assign_11, 5);
YAP_UserCPredicate("gecode_constraint_assign_14", gecode_constraint_assign_14, 5);
YAP_UserCPredicate("gecode_constraint_rel_389", gecode_constraint_rel_389, 3);
YAP_UserCPredicate("gecode_constraint_rel_379", gecode_constraint_rel_379, 3);
YAP_UserCPredicate("gecode_constraint_path_346", gecode_constraint_path_346, 4);
YAP_UserCPredicate("gecode_constraint_branch_45", gecode_constraint_branch_45, 4);
YAP_UserCPredicate("gecode_constraint_branch_29", gecode_constraint_branch_29, 4);
YAP_UserCPredicate("gecode_constraint_branch_23", gecode_constraint_branch_23, 4);
YAP_UserCPredicate("gecode_constraint_branch_22", gecode_constraint_branch_22, 4);
YAP_UserCPredicate("gecode_constraint_branch_35", gecode_constraint_branch_35, 4);
YAP_UserCPredicate("gecode_constraint_branch_47", gecode_constraint_branch_47, 4);
YAP_UserCPredicate("gecode_constraint_branch_41", gecode_constraint_branch_41, 4);
YAP_UserCPredicate("gecode_constraint_branch_49", gecode_constraint_branch_49, 4);
YAP_UserCPredicate("gecode_constraint_mult_316", gecode_constraint_mult_316, 5);
YAP_UserCPredicate("gecode_constraint_circuit_81", gecode_constraint_circuit_81, 6);
YAP_UserCPredicate("gecode_constraint_circuit_78", gecode_constraint_circuit_78, 6);
YAP_UserCPredicate("gecode_constraint_circuit_75", gecode_constraint_circuit_75, 6);
YAP_UserCPredicate("gecode_constraint_clause_88", gecode_constraint_clause_88, 5);
YAP_UserCPredicate("gecode_constraint_clause_86", gecode_constraint_clause_86, 5);
YAP_UserCPredicate("gecode_constraint_precede_358", gecode_constraint_precede_358, 4);
YAP_UserCPredicate("gecode_constraint_precede_355", gecode_constraint_precede_355, 4);
YAP_UserCPredicate("gecode_constraint_precede_354", gecode_constraint_precede_354, 4);
YAP_UserCPredicate("gecode_constraint_channel_69", gecode_constraint_channel_69, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_126", gecode_constraint_cumulative_126, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_129", gecode_constraint_cumulative_129, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_122", gecode_constraint_cumulative_122, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_125", gecode_constraint_cumulative_125, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_119", gecode_constraint_cumulative_119, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_138", gecode_constraint_cumulative_138, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_141", gecode_constraint_cumulative_141, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_134", gecode_constraint_cumulative_134, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_137", gecode_constraint_cumulative_137, 7);
YAP_UserCPredicate("gecode_constraint_cumulative_131", gecode_constraint_cumulative_131, 7);
YAP_UserCPredicate("gecode_constraint_distinct_161", gecode_constraint_distinct_161, 3);
YAP_UserCPredicate("gecode_constraint_distinct_158", gecode_constraint_distinct_158, 3);
YAP_UserCPredicate("gecode_constraint_member_303", gecode_constraint_member_303, 5);
YAP_UserCPredicate("gecode_constraint_member_299", gecode_constraint_member_299, 5);
YAP_UserCPredicate("gecode_constraint_mod_312", gecode_constraint_mod_312, 4);
YAP_UserCPredicate("gecode_constraint_sqr_434", gecode_constraint_sqr_434, 3);
YAP_UserCPredicate("gecode_constraint_sqr_433", gecode_constraint_sqr_433, 3);
YAP_UserCPredicate("gecode_constraint_sequence_426", gecode_constraint_sequence_426, 7);
YAP_UserCPredicate("gecode_constraint_sequence_424", gecode_constraint_sequence_424, 7);
YAP_UserCPredicate("gecode_constraint_path_344", gecode_constraint_path_344, 7);
YAP_UserCPredicate("gecode_constraint_path_341", gecode_constraint_path_341, 7);
YAP_UserCPredicate("gecode_constraint_path_338", gecode_constraint_path_338, 7);
YAP_UserCPredicate("gecode_constraint_divmod_166", gecode_constraint_divmod_166, 6);
YAP_UserCPredicate("gecode_constraint_sorted_431", gecode_constraint_sorted_431, 3);
YAP_UserCPredicate("gecode_constraint_circuit_84", gecode_constraint_circuit_84, 3);
YAP_UserCPredicate("gecode_constraint_circuit_83", gecode_constraint_circuit_83, 3);
YAP_UserCPredicate("gecode_constraint_channel_71", gecode_constraint_channel_71, 3);
YAP_UserCPredicate("gecode_constraint_channel_61", gecode_constraint_channel_61, 3);
YAP_UserCPredicate("gecode_constraint_channel_64", gecode_constraint_channel_64, 3);
YAP_UserCPredicate("gecode_constraint_channel_59", gecode_constraint_channel_59, 3);
YAP_UserCPredicate("gecode_constraint_channel_67", gecode_constraint_channel_67, 3);
YAP_UserCPredicate("gecode_constraint_channel_65", gecode_constraint_channel_65, 3);
YAP_UserCPredicate("gecode_constraint_channel_72", gecode_constraint_channel_72, 3);
YAP_UserCPredicate("gecode_constraint_channel_70", gecode_constraint_channel_70, 3);
YAP_UserCPredicate("gecode_constraint_count_92", gecode_constraint_count_92, 5);
YAP_UserCPredicate("gecode_constraint_count_94", gecode_constraint_count_94, 5);
YAP_UserCPredicate("gecode_constraint_count_110", gecode_constraint_count_110, 5);
YAP_UserCPredicate("gecode_constraint_count_112", gecode_constraint_count_112, 5);
YAP_UserCPredicate("gecode_constraint_count_102", gecode_constraint_count_102, 5);
YAP_UserCPredicate("gecode_constraint_count_104", gecode_constraint_count_104, 5);
YAP_UserCPredicate("gecode_constraint_count_101", gecode_constraint_count_101, 5);
YAP_UserCPredicate("gecode_constraint_count_97", gecode_constraint_count_97, 5);
YAP_UserCPredicate("gecode_constraint_count_107", gecode_constraint_count_107, 5);
YAP_UserCPredicate("gecode_constraint_count_114", gecode_constraint_count_114, 5);
YAP_UserCPredicate("gecode_constraint_count_116", gecode_constraint_count_116, 5);
YAP_UserCPredicate("gecode_constraint_cumulatives_156", gecode_constraint_cumulatives_156, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_154", gecode_constraint_cumulatives_154, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_152", gecode_constraint_cumulatives_152, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_150", gecode_constraint_cumulatives_150, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_148", gecode_constraint_cumulatives_148, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_146", gecode_constraint_cumulatives_146, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_144", gecode_constraint_cumulatives_144, 8);
YAP_UserCPredicate("gecode_constraint_cumulatives_142", gecode_constraint_cumulatives_142, 8);
YAP_UserCPredicate("gecode_constraint_binpacking_55", gecode_constraint_binpacking_55, 5);
YAP_UserCPredicate("gecode_constraint_linear_283", gecode_constraint_linear_283, 6);
YAP_UserCPredicate("gecode_constraint_linear_287", gecode_constraint_linear_287, 6);
YAP_UserCPredicate("gecode_constraint_linear_251", gecode_constraint_linear_251, 6);
YAP_UserCPredicate("gecode_constraint_linear_255", gecode_constraint_linear_255, 6);
YAP_UserCPredicate("gecode_constraint_linear_259", gecode_constraint_linear_259, 6);
YAP_UserCPredicate("gecode_constraint_linear_257", gecode_constraint_linear_257, 6);
YAP_UserCPredicate("gecode_constraint_linear_274", gecode_constraint_linear_274, 6);
YAP_UserCPredicate("gecode_constraint_linear_273", gecode_constraint_linear_273, 6);
YAP_UserCPredicate("gecode_constraint_linear_278", gecode_constraint_linear_278, 6);
YAP_UserCPredicate("gecode_constraint_linear_277", gecode_constraint_linear_277, 6);
YAP_UserCPredicate("gecode_constraint_linear_266", gecode_constraint_linear_266, 6);
YAP_UserCPredicate("gecode_constraint_linear_265", gecode_constraint_linear_265, 6);
YAP_UserCPredicate("gecode_constraint_linear_270", gecode_constraint_linear_270, 6);
YAP_UserCPredicate("gecode_constraint_linear_269", gecode_constraint_linear_269, 6);
YAP_UserCPredicate("gecode_constraint_nooverlap_323", gecode_constraint_nooverlap_323, 7);
YAP_UserCPredicate("gecode_constraint_nooverlap_318", gecode_constraint_nooverlap_318, 7);
YAP_UserCPredicate("gecode_constraint_div_164", gecode_constraint_div_164, 5);
YAP_UserCPredicate("gecode_constraint_sqr_435", gecode_constraint_sqr_435, 4);
YAP_UserCPredicate("gecode_constraint_path_345", gecode_constraint_path_345, 8);
YAP_UserCPredicate("gecode_constraint_path_342", gecode_constraint_path_342, 8);
YAP_UserCPredicate("gecode_constraint_path_339", gecode_constraint_path_339, 8);
YAP_UserCPredicate("gecode_constraint_unary_447", gecode_constraint_unary_447, 5);
YAP_UserCPredicate("gecode_constraint_unary_450", gecode_constraint_unary_450, 5);
YAP_UserCPredicate("gecode_constraint_unary_443", gecode_constraint_unary_443, 5);
YAP_UserCPredicate("gecode_constraint_unary_446", gecode_constraint_unary_446, 5);
YAP_UserCPredicate("gecode_constraint_unary_440", gecode_constraint_unary_440, 5);
YAP_UserCPredicate("gecode_constraint_sorted_429", gecode_constraint_sorted_429, 4);
YAP_UserCPredicate("gecode_constraint_sorted_432", gecode_constraint_sorted_432, 4);
YAP_UserCPredicate("gecode_constraint_element_223", gecode_constraint_element_223, 8);
YAP_UserCPredicate("gecode_constraint_element_217", gecode_constraint_element_217, 8);
YAP_UserCPredicate("gecode_constraint_element_235", gecode_constraint_element_235, 8);
YAP_UserCPredicate("gecode_constraint_element_233", gecode_constraint_element_233, 8);
YAP_UserCPredicate("gecode_constraint_assign_16", gecode_constraint_assign_16, 4);
YAP_UserCPredicate("gecode_constraint_assign_7", gecode_constraint_assign_7, 4);
YAP_UserCPredicate("gecode_constraint_assign_4", gecode_constraint_assign_4, 4);
YAP_UserCPredicate("gecode_constraint_assign_2", gecode_constraint_assign_2, 4);
YAP_UserCPredicate("gecode_constraint_assign_10", gecode_constraint_assign_10, 4);
YAP_UserCPredicate("gecode_constraint_assign_18", gecode_constraint_assign_18, 4);
YAP_UserCPredicate("gecode_constraint_assign_13", gecode_constraint_assign_13, 4);
YAP_UserCPredicate("gecode_constraint_assign_20", gecode_constraint_assign_20, 4);
YAP_UserCPredicate("gecode_constraint_element_221", gecode_constraint_element_221, 5);
YAP_UserCPredicate("gecode_constraint_element_225", gecode_constraint_element_225, 5);
YAP_UserCPredicate("gecode_constraint_element_215", gecode_constraint_element_215, 5);
YAP_UserCPredicate("gecode_constraint_element_213", gecode_constraint_element_213, 5);
YAP_UserCPredicate("gecode_constraint_element_244", gecode_constraint_element_244, 5);
YAP_UserCPredicate("gecode_constraint_element_242", gecode_constraint_element_242, 5);
YAP_UserCPredicate("gecode_constraint_element_240", gecode_constraint_element_240, 5);
YAP_UserCPredicate("gecode_constraint_element_238", gecode_constraint_element_238, 5);
YAP_UserCPredicate("gecode_constraint_element_231", gecode_constraint_element_231, 5);
YAP_UserCPredicate("gecode_constraint_element_237", gecode_constraint_element_237, 5);
YAP_UserCPredicate("gecode_constraint_element_229", gecode_constraint_element_229, 5);
YAP_UserCPredicate("gecode_constraint_sequence_428", gecode_constraint_sequence_428, 3);
YAP_UserCPredicate("gecode_constraint_branch_30", gecode_constraint_branch_30, 5);
YAP_UserCPredicate("gecode_constraint_branch_26", gecode_constraint_branch_26, 5);
YAP_UserCPredicate("gecode_constraint_branch_24", gecode_constraint_branch_24, 5);
YAP_UserCPredicate("gecode_constraint_branch_32", gecode_constraint_branch_32, 5);
YAP_UserCPredicate("gecode_constraint_branch_36", gecode_constraint_branch_36, 5);
YAP_UserCPredicate("gecode_constraint_branch_42", gecode_constraint_branch_42, 5);
YAP_UserCPredicate("gecode_constraint_branch_38", gecode_constraint_branch_38, 5);
YAP_UserCPredicate("gecode_constraint_circuit_79", gecode_constraint_circuit_79, 7);
YAP_UserCPredicate("gecode_constraint_pow_351", gecode_constraint_pow_351, 4);
YAP_UserCPredicate("gecode_constraint_pow_350", gecode_constraint_pow_350, 4);
YAP_UserCPredicate("gecode_constraint_precede_357", gecode_constraint_precede_357, 3);
YAP_UserCPredicate("gecode_constraint_precede_353", gecode_constraint_precede_353, 3);
YAP_UserCPredicate("gecode_constraint_cumulative_128", gecode_constraint_cumulative_128, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_124", gecode_constraint_cumulative_124, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_118", gecode_constraint_cumulative_118, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_121", gecode_constraint_cumulative_121, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_140", gecode_constraint_cumulative_140, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_136", gecode_constraint_cumulative_136, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_130", gecode_constraint_cumulative_130, 6);
YAP_UserCPredicate("gecode_constraint_cumulative_133", gecode_constraint_cumulative_133, 6);
YAP_UserCPredicate("gecode_constraint_distinct_159", gecode_constraint_distinct_159, 4);
YAP_UserCPredicate("gecode_constraint_min_304", gecode_constraint_min_304, 3);
YAP_UserCPredicate("gecode_constraint_min_305", gecode_constraint_min_305, 3);
YAP_UserCPredicate("gecode_constraint_min_310", gecode_constraint_min_310, 3);
YAP_UserCPredicate("gecode_constraint_sqrt_438", gecode_constraint_sqrt_438, 4);
YAP_UserCPredicate("gecode_constraint_sequence_425", gecode_constraint_sequence_425, 6);
YAP_UserCPredicate("gecode_constraint_sequence_423", gecode_constraint_sequence_423, 6);
YAP_UserCPredicate("gecode_constraint_unshare_454", gecode_constraint_unshare_454, 3);
YAP_UserCPredicate("gecode_constraint_unshare_452", gecode_constraint_unshare_452, 3);
YAP_UserCPredicate("gecode_constraint_path_349", gecode_constraint_path_349, 6);
YAP_UserCPredicate("gecode_constraint_path_340", gecode_constraint_path_340, 6);
YAP_UserCPredicate("gecode_constraint_divmod_165", gecode_constraint_divmod_165, 5);
YAP_UserCPredicate("gecode_constraint_branch_31", gecode_constraint_branch_31, 6);
YAP_UserCPredicate("gecode_constraint_branch_27", gecode_constraint_branch_27, 6);
YAP_UserCPredicate("gecode_constraint_branch_25", gecode_constraint_branch_25, 6);
YAP_UserCPredicate("gecode_constraint_branch_33", gecode_constraint_branch_33, 6);
YAP_UserCPredicate("gecode_constraint_branch_37", gecode_constraint_branch_37, 6);
YAP_UserCPredicate("gecode_constraint_branch_43", gecode_constraint_branch_43, 6);
YAP_UserCPredicate("gecode_constraint_branch_39", gecode_constraint_branch_39, 6);
YAP_UserCPredicate("gecode_constraint_nooverlap_322", gecode_constraint_nooverlap_322, 9);
YAP_UserCPredicate("gecode_constraint_cumulative_120", gecode_constraint_cumulative_120, 5);
YAP_UserCPredicate("gecode_constraint_cumulative_132", gecode_constraint_cumulative_132, 5);
YAP_UserCPredicate("gecode_constraint_member_300", gecode_constraint_member_300, 3);
YAP_UserCPredicate("gecode_constraint_member_296", gecode_constraint_member_296, 3);
YAP_UserCPredicate("gecode_constraint_count_111", gecode_constraint_count_111, 6);
YAP_UserCPredicate("gecode_constraint_count_113", gecode_constraint_count_113, 6);
YAP_UserCPredicate("gecode_constraint_count_115", gecode_constraint_count_115, 6);
YAP_UserCPredicate("gecode_constraint_count_117", gecode_constraint_count_117, 6);
YAP_UserCPredicate("gecode_constraint_count_103", gecode_constraint_count_103, 6);
YAP_UserCPredicate("gecode_constraint_count_105", gecode_constraint_count_105, 6);
YAP_UserCPredicate("gecode_constraint_count_93", gecode_constraint_count_93, 6);
YAP_UserCPredicate("gecode_constraint_count_95", gecode_constraint_count_95, 6);
YAP_UserCPredicate("gecode_constraint_pow_352", gecode_constraint_pow_352, 5);
YAP_UserCPredicate("gecode_constraint_notMin_326", gecode_constraint_notMin_326, 3);
YAP_UserCPredicate("gecode_constraint_cumulative_127", gecode_constraint_cumulative_127, 8);
YAP_UserCPredicate("gecode_constraint_cumulative_123", gecode_constraint_cumulative_123, 8);
YAP_UserCPredicate("gecode_constraint_cumulative_139", gecode_constraint_cumulative_139, 8);
YAP_UserCPredicate("gecode_constraint_cumulative_135", gecode_constraint_cumulative_135, 8);
YAP_UserCPredicate("gecode_constraint_branch_46", gecode_constraint_branch_46, 3);
YAP_UserCPredicate("gecode_constraint_branch_21", gecode_constraint_branch_21, 3);
YAP_UserCPredicate("gecode_constraint_branch_44", gecode_constraint_branch_44, 3);
YAP_UserCPredicate("gecode_constraint_branch_48", gecode_constraint_branch_48, 3);
YAP_UserCPredicate("gecode_constraint_dom_188", gecode_constraint_dom_188, 3);
YAP_UserCPredicate("gecode_constraint_dom_190", gecode_constraint_dom_190, 3);
YAP_UserCPredicate("gecode_constraint_dom_171", gecode_constraint_dom_171, 3);
YAP_UserCPredicate("gecode_constraint_dom_173", gecode_constraint_dom_173, 3);
YAP_UserCPredicate("gecode_constraint_dom_169", gecode_constraint_dom_169, 3);
YAP_UserCPredicate("gecode_constraint_dom_167", gecode_constraint_dom_167, 3);
YAP_UserCPredicate("gecode_constraint_dom_178", gecode_constraint_dom_178, 3);
YAP_UserCPredicate("gecode_constraint_dom_176", gecode_constraint_dom_176, 3);
YAP_UserCPredicate("gecode_constraint_dom_174", gecode_constraint_dom_174, 3);
YAP_UserCPredicate("gecode_constraint_dom_195", gecode_constraint_dom_195, 3);
YAP_UserCPredicate("gecode_constraint_dom_203", gecode_constraint_dom_203, 3);
YAP_UserCPredicate("gecode_constraint_dom_191", gecode_constraint_dom_191, 3);
YAP_UserCPredicate("gecode_constraint_dom_182", gecode_constraint_dom_182, 3);
YAP_UserCPredicate("gecode_constraint_dom_211", gecode_constraint_dom_211, 3);
YAP_UserCPredicate("gecode_constraint_linear_263", gecode_constraint_linear_263, 5);
YAP_UserCPredicate("gecode_constraint_linear_261", gecode_constraint_linear_261, 5);
YAP_UserCPredicate("gecode_constraint_linear_250", gecode_constraint_linear_250, 5);
YAP_UserCPredicate("gecode_constraint_linear_249", gecode_constraint_linear_249, 5);
YAP_UserCPredicate("gecode_constraint_linear_254", gecode_constraint_linear_254, 5);
YAP_UserCPredicate("gecode_constraint_linear_253", gecode_constraint_linear_253, 5);
YAP_UserCPredicate("gecode_constraint_linear_258", gecode_constraint_linear_258, 5);
YAP_UserCPredicate("gecode_constraint_linear_256", gecode_constraint_linear_256, 5);
YAP_UserCPredicate("gecode_constraint_linear_282", gecode_constraint_linear_282, 5);
YAP_UserCPredicate("gecode_constraint_linear_281", gecode_constraint_linear_281, 5);
YAP_UserCPredicate("gecode_constraint_linear_286", gecode_constraint_linear_286, 5);
YAP_UserCPredicate("gecode_constraint_linear_285", gecode_constraint_linear_285, 5);
YAP_UserCPredicate("gecode_constraint_linear_272", gecode_constraint_linear_272, 5);
YAP_UserCPredicate("gecode_constraint_linear_276", gecode_constraint_linear_276, 5);
YAP_UserCPredicate("gecode_constraint_linear_264", gecode_constraint_linear_264, 5);
YAP_UserCPredicate("gecode_constraint_linear_268", gecode_constraint_linear_268, 5);
YAP_UserCPredicate("gecode_constraint_nooverlap_317", gecode_constraint_nooverlap_317, 6);
YAP_UserCPredicate("gecode_constraint_nooverlap_320", gecode_constraint_nooverlap_320, 6);
YAP_UserCPredicate("gecode_constraint_element_245", gecode_constraint_element_245, 6);
YAP_UserCPredicate("gecode_constraint_element_243", gecode_constraint_element_243, 6);
YAP_UserCPredicate("gecode_constraint_element_241", gecode_constraint_element_241, 6);
YAP_UserCPredicate("gecode_constraint_element_239", gecode_constraint_element_239, 6);
YAP_UserCPredicate("gecode_constraint_rel_395", gecode_constraint_rel_395, 4);
YAP_UserCPredicate("gecode_constraint_rel_397", gecode_constraint_rel_397, 4);
YAP_UserCPredicate("gecode_constraint_rel_413", gecode_constraint_rel_413, 4);
YAP_UserCPredicate("gecode_constraint_rel_411", gecode_constraint_rel_411, 4);
YAP_UserCPredicate("gecode_constraint_rel_383", gecode_constraint_rel_383, 4);
YAP_UserCPredicate("gecode_constraint_rel_384", gecode_constraint_rel_384, 4);
YAP_UserCPredicate("gecode_constraint_rel_381", gecode_constraint_rel_381, 4);
YAP_UserCPredicate("gecode_constraint_rel_377", gecode_constraint_rel_377, 4);
YAP_UserCPredicate("gecode_constraint_rel_375", gecode_constraint_rel_375, 4);
YAP_UserCPredicate("gecode_constraint_rel_380", gecode_constraint_rel_380, 4);
YAP_UserCPredicate("gecode_constraint_rel_371", gecode_constraint_rel_371, 4);
YAP_UserCPredicate("gecode_constraint_rel_367", gecode_constraint_rel_367, 4);
YAP_UserCPredicate("gecode_constraint_rel_391", gecode_constraint_rel_391, 4);
YAP_UserCPredicate("gecode_constraint_rel_393", gecode_constraint_rel_393, 4);
YAP_UserCPredicate("gecode_constraint_rel_387", gecode_constraint_rel_387, 4);
YAP_UserCPredicate("gecode_constraint_rel_390", gecode_constraint_rel_390, 4);
YAP_UserCPredicate("gecode_constraint_rel_399", gecode_constraint_rel_399, 4);
YAP_UserCPredicate("gecode_constraint_rel_403", gecode_constraint_rel_403, 4);
YAP_UserCPredicate("gecode_constraint_rel_407", gecode_constraint_rel_407, 4);
YAP_UserCPredicate("gecode_constraint_rel_408", gecode_constraint_rel_408, 4);
YAP_UserCPredicate("gecode_constraint_rel_414", gecode_constraint_rel_414, 4);
YAP_UserCPredicate("gecode_constraint_rel_419", gecode_constraint_rel_419, 4);
YAP_UserCPredicate("gecode_constraint_rel_421", gecode_constraint_rel_421, 4);
YAP_UserCPredicate("gecode_constraint_rel_361", gecode_constraint_rel_361, 4);
YAP_UserCPredicate("gecode_constraint_rel_359", gecode_constraint_rel_359, 4);
YAP_UserCPredicate("gecode_constraint_min_309", gecode_constraint_min_309, 5);
YAP_UserCPredicate("gecode_constraint_count_108", gecode_constraint_count_108, 3);
YAP_UserCPredicate("gecode_constraint_count_98", gecode_constraint_count_98, 3);
YAP_UserCPredicate("gecode_constraint_ite_247", gecode_constraint_ite_247, 6);

View File

@ -45,12 +45,12 @@ SOBJS=gecode_yap.@SO@
GECODE_VERSION = @GECODE_VERSION@
DISJUNCTOR = -DDISJUNCTOR
GECODE_LIBS = @GECODE_EXTRALIBS@
GECODE_MAJOR = @GECODE_MAJOR@
all: $(SOBJS) gecode.yap
gecode_yap.o: \
$(srcdir)/gecode_yap.cc \
$(srcdir)/gecode-common.icc \
$(srcdir)/gecode$(GECODE_MAJOR)_yap.cc \
$(srcdir)/gecode$(GECODE_MAJOR)-common.icc \
$(srcdir)/$(GECODE_VERSION)/gecode_yap_cc_impl_auto_generated.icc \
$(srcdir)/$(GECODE_VERSION)/gecode_yap_cc_init_auto_generated.icc \
$(srcdir)/$(GECODE_VERSION)/gecode_yap_cc_forward_auto_generated.icc \
@ -61,7 +61,7 @@ gecode_yap.o: \
@DO_SECOND_LD@gecode_yap.@SO@: gecode_yap.o
@DO_SECOND_LD@ @SHLIB_CXX_LD@ -o gecode_yap.@SO@ gecode_yap.o $(LDFLAGS) $(GECODE_LIBS) @EXTRA_LIBS_FOR_DLLS@
gecode.yap: $(srcdir)/gecode_yap_hand_written.yap $(srcdir)/$(GECODE_VERSION)/gecode_yap_auto_generated.yap
gecode.yap: $(srcdir)/gecode$(GECODE_MAJOR)_yap_hand_written.yap $(srcdir)/$(GECODE_VERSION)/gecode_yap_auto_generated.yap
cat $^ > $@
.PHONY: all clean install

View File

@ -195,6 +195,9 @@ class PredGenerator(DeclsLoader):
"VarBranchOptions",
"ValBranchOptions",
"TieBreakVarBranch<IntVarBranch>",
"TieBreak<IntVarBranch>",
"TieBreak<FloatVarBranch>",
"TieBreak<SetVarBranch>",
"TieBreakVarBranchOptions",
"TieBreakVarBranch<SetVarBranch>")
@ -616,16 +619,21 @@ class CCDescriptor(object):
print "{"
i = 1
args = []
has_space = False
for t in self.argtypes:
v = "X%d" % i
a = "YAP_ARG%d" % i
if t=="Space":
v = "*space"
print " GenericSpace* space = gecode_Space_from_term(%s);" % a
has_space = True
else:
extra = ""
if t in ("IntVar","BoolVar","SetVar","IntVarArgs","BoolVarArgs","SetVarArgs"):
if t in ("IntVar","BoolVar","SetVar","FloatVar","IntVarArgs","BoolVarArgs","SetVarArgs","FloatVarArgs"):
extra = "space,"
if has_space == False:
print " GenericSpace* space = gecode_Space_from_term(%s);" % a
has_space = True
print " %s %s = gecode_%s_from_term(%s%s);" % (t,v,t,extra,a)
args.append(v)
i += 1

View File

@ -9,6 +9,8 @@ all: $(PROTOTYPES) $(ENUMS)
$(PROTOTYPES): % : xml/namespaceGecode.xml extract-prototypes.xsl
cat notice.hh > $@ || { rm -f $@; exit 1; }
xsltproc extract-prototypes.xsl $< \
| grep EXPORT \
| grep -v Symmetry \
| sed 's/Gecode:://g' \
| sed 's/< /</g' \
| sed 's/ >/>/g' \
@ -16,6 +18,7 @@ $(PROTOTYPES): % : xml/namespaceGecode.xml extract-prototypes.xsl
| sed 's/, /,/g' \
| sed 's/forceinline //g' \
| sed 's/GECODE_INT_EXPORT //g' \
| sed 's/GECODE_FLOAT_EXPORT //g' \
| sed 's/GECODE_SET_EXPORT //g' \
| grep -v '*' | sort >> $@ || { rm -f $@; exit 1; }

View File

@ -0,0 +1,397 @@
// -*- c++ -*-
//=============================================================================
// Copyright (C) 2011 by Denys Duchier
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
#ifndef GECODE_COMMON
#define GECODE_COMMON
#include "gecode/driver.hh"
#include "gecode/int.hh"
#include "gecode/set.hh"
#include "gecode/search.hh"
#include <vector>
namespace generic_gecode
{
using namespace std;
using namespace Gecode;
// description of the optimization criterion
struct Optimizing
{
enum What { OPT_NONE, OPT_INT, OPT_RATIO };
enum How { OPT_MIN, OPT_MAX };
int num;
int den;
What what;
How how;
Optimizing(): num(-1), den(-1), what(OPT_NONE), how(OPT_MAX) {}
Optimizing(Optimizing& o)
: num(o.num), den(o.den), what(o.what), how(o.how) {}
void check_ok() const
{ if (what!=OPT_NONE)
throw Exception("gecode-python","too many optimization criteria"); }
void maximize(int i)
{ check_ok(); what = OPT_INT; how = OPT_MAX; num = i; };
void maximize(int i,int j)
{ check_ok(); what = OPT_RATIO; how = OPT_MAX; num = i; den = j; };
void minimize(int i)
{ check_ok(); what = OPT_INT; how = OPT_MIN; num = i; };
void minimize(int i,int j)
{ check_ok(); what = OPT_RATIO; how = OPT_MIN; num = i; den = j; };
};
struct GenericSpace;
struct GenericEngine
{
virtual GenericSpace* next(void)=0;
virtual ~GenericEngine() {};
};
struct GenericDFS: GenericEngine
{
DFS<GenericSpace> engine;
GenericDFS(GenericSpace* s,Search::Options& opt) : engine(s,opt) {}
virtual GenericSpace* next(void) { return engine.next(); }
};
struct GenericBAB: GenericEngine
{
BAB<GenericSpace> engine;
GenericBAB(GenericSpace* s,Search::Options& opt) : engine(s,opt) {}
virtual GenericSpace* next(void) { return engine.next(); }
};
#ifdef OLD
struct GenericRestart: GenericEngine
{
Restart<GenericSpace> engine;
GenericRestart(GenericSpace* s,Search::Options& opt): engine(s,opt) {}
virtual GenericSpace* next(void) { return engine.next(); }
};
#endif
struct LoadingDock
{
vector<IntVar> ivars;
vector<BoolVar> bvars;
vector<FloatVar> fvars;
vector<SetVar> svars;
vector<int> ikeep;
vector<int> bkeep;
vector<int> fkeep;
vector<int> skeep;
bool keeping_some() const
{
return (ikeep.size() != 0)
|| (bkeep.size() != 0)
|| (fkeep.size() != 0)
|| (skeep.size() != 0);
}
IntVar get_ivar(int i) const { return ivars[i]; }
BoolVar get_bvar(int i) const { return bvars[i]; }
FloatVar get_fvar(int i) const { return fvars[i]; }
SetVar get_svar(int i) const { return svars[i]; }
int enter_ivar(const IntVar& v)
{ ivars.push_back(v); return static_cast<int>(ivars.size()-1); }
int enter_bvar(const BoolVar& v)
{ bvars.push_back(v); return static_cast<int>(bvars.size()-1); }
int enter_fvar(const FloatVar& v)
{ fvars.push_back(v); return static_cast<int>(fvars.size()-1); }
int enter_svar(const SetVar& v)
{ svars.push_back(v); return static_cast<int>(svars.size()-1); }
int keep_ivar(int i) { ikeep.push_back(i); return static_cast<int>(ikeep.size()-1); }
int keep_bvar(int i) { bkeep.push_back(i); return static_cast<int>(bkeep.size()-1); }
int keep_fvar(int i) { fkeep.push_back(i); return static_cast<int>(fkeep.size()-1); }
int keep_svar(int i) { skeep.push_back(i); return static_cast<int>(skeep.size()-1); }
void freeze(Space& home,
IntVarArray& iarr, BoolVarArray& barr, SetVarArray& sarr, FloatVarArray& farr,
int& num, int& den)
{
if (keeping_some())
{
// make sure that optimization vars (if any) are kept
if (num != -1)
{
const int _num(num);
const int _den(den);
int n = static_cast<int>(ikeep.size());
bool num_found(false);
bool den_found(false);
for (;n--;)
{
const int idx(ikeep[n]);
if (idx==_num)
{ num_found=true; if (den_found) break; }
if (idx==_den)
{ den_found=true; if (num_found) break; }
}
if (!num_found)
{ ikeep.push_back(_num);
num=static_cast<int>(ikeep.size()-1); }
if (_den != -1 && !den_found)
{ ikeep.push_back(_den);
den=static_cast<int>(ikeep.size()-1); }
}
{ int n = static_cast<int>(ikeep.size());
iarr = IntVarArray(home, n);
for (;n--;) iarr[n]=ivars[ikeep[n]]; }
{ int n = static_cast<int>(bkeep.size());
barr = BoolVarArray(home, n);
for (;n--;) barr[n]=bvars[bkeep[n]]; }
{ int n = static_cast<int>(skeep.size());
sarr = SetVarArray(home, n);
for (;n--;) sarr[n]=svars[skeep[n]]; }
{ int n = static_cast<int>(fkeep.size());
farr = FloatVarArray(home, n);
for (;n--;) farr[n]=fvars[skeep[n]]; }
}
else
{
{ int n = static_cast<int>(ivars.size());
iarr = IntVarArray(home, n);
for (;n--;) iarr[n]=ivars[n]; }
{ int n = static_cast<int>(bvars.size());
barr = BoolVarArray(home, n);
for (;n--;) barr[n]=bvars[n]; }
{ int n = static_cast<int>(svars.size());
sarr = SetVarArray(home, n);
for (;n--;) sarr[n]=svars[n]; }
{ int n = static_cast<int>(fvars.size());
farr = FloatVarArray(home, n);
for (;n--;) farr[n]=fvars[n]; }
}
}
};
struct GenericSpace: Space
{
Optimizing optim;
IntVarArray ivars;
BoolVarArray bvars;
FloatVarArray fvars;
SetVarArray svars;
LoadingDock* dock;
bool keeping_some; // iff only SOME of the vars are kept
Space* space() { return this; }
GenericSpace(bool share, GenericSpace& s)
: Space(share, s), optim(s.optim), dock(NULL), keeping_some(s.keeping_some)
{
ivars.update(*this, share, s.ivars);
bvars.update(*this, share, s.bvars);
svars.update(*this, share, s.svars);
fvars.update(*this, share, s.fvars);
}
Space* copy(bool share)
{ freeze(); return new GenericSpace(share, *this); }
GenericSpace() : dock(new LoadingDock()), keeping_some(false) {}
~GenericSpace() { delete dock; }
// throw some C++ exception on behalf of glue code
void kaboom(const char* s)
{ throw Exception("gecode-python", s); }
int ikaboom(const char* s)
{ kaboom(s); return 0; }
// freeze the space before handing it off to a search engine
void freeze()
{
if (dock)
{
keeping_some = dock->keeping_some();
dock->freeze(*this, ivars, bvars, svars, fvars, optim.num, optim.den);
delete dock;
dock = NULL;
}
}
IntVar get_ivar(int i) const { return (dock)?dock->get_ivar(i):ivars[i]; }
BoolVar get_bvar(int i) const { return (dock)?dock->get_bvar(i):bvars[i]; }
SetVar get_svar(int i) const { return (dock)?dock->get_svar(i):svars[i]; }
FloatVar get_fvar(int i) const { return (dock)?dock->get_fvar(i):fvars[i]; }
int keep_ivar(int i)
{
if (dock) return dock->keep_ivar(i);
else return ikaboom("too late to keep");
}
int keep_bvar(int i)
{
if (dock) return dock->keep_bvar(i);
else return ikaboom("too late to keep");
}
int keep_svar(int i)
{
if (dock) return dock->keep_svar(i);
else return ikaboom("too late to keep");
}
int keep_fvar(int i)
{
if (dock) return dock->keep_fvar(i);
else return ikaboom("too late to keep");
}
bool frozen() const { return dock==NULL; }
bool has_keepers() const { return keeping_some; }
// when frozen and has_keepers: which is just has_keepers actually
bool use_keep_index() const { return has_keepers(); }
GenericEngine* new_engine(bool restart, Search::Options& opt)
{
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));
}
int _new_ivar(IntVar& v)
{
if (dock) return dock->enter_ivar(v);
else return ikaboom("too late to create vars");
}
int new_ivar(int lo, int hi)
{
IntVar v(*this, lo, hi);
return _new_ivar(v);
}
int new_ivar(IntSet& s)
{
IntVar v(*this, s);
return _new_ivar(v);
}
int _new_fvar(FloatVar& v)
{
if (dock) return dock->enter_fvar(v);
else return ikaboom("too late to create vars");
}
int new_fvar(double lo, double hi)
{
FloatVar v(*this, lo, hi);
return _new_fvar(v);
}
int _new_bvar(BoolVar& v)
{
if (dock) return dock->enter_bvar(v);
else return ikaboom("too late to create vars");
}
int new_bvar()
{
BoolVar v(*this, 0, 1);
return _new_bvar(v);
}
int _new_svar(SetVar& v)
{
if (dock) return dock->enter_svar(v);
else return ikaboom("too late to create vars");
}
int new_svar(int glbMin, int glbMax, int lubMin, int lubMax,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glbMin, glbMax, lubMin, lubMax, cardMin, cardMax);
return _new_svar(v);
}
int new_svar(IntSet glb, int lubMin, int lubMax,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glb, lubMin, lubMax, cardMin, cardMax);
return _new_svar(v);
}
int new_svar(int glbMin, int glbMax, IntSet lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glbMin, glbMax, lub, cardMin, cardMax);
return _new_svar(v);
}
int new_svar(IntSet glb, IntSet lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glb, lub, cardMin, cardMax);
return _new_svar(v);
}
void minimize(int i) { optim.minimize(i); }
void minimize(int i, int j) { optim.minimize(i,j); }
void maximize(int i) { optim.maximize(i); }
void maximize(int i, int j) { optim.maximize(i,j); }
virtual void constrain(const Space& s)
{
const GenericSpace& sol = static_cast<const GenericSpace&>(s);
switch (optim.what)
{
case Optimizing::OPT_NONE:
break;
case Optimizing::OPT_INT:
rel(*this, ivars[optim.num],
((optim.how==Optimizing::OPT_MIN) ? IRT_LE : IRT_GR),
sol.ivars[optim.num].val());
break;
case Optimizing::OPT_RATIO:
{
IntArgs c(2, sol.ivars[optim.den].val(),
- sol.ivars[optim.num].val());
IntVarArgs v(2);
v[0] = ivars[optim.num];
v[1] = ivars[optim.den];
linear(*this, c, v,
((optim.how==Optimizing::OPT_MIN) ? IRT_LE : IRT_GR), 0);
break;
}
}
}
};
}
#ifdef DISJUNCTOR
#include "disjunctor.icc"
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

80
library/gecode/photo.yap Normal file
View File

@ -0,0 +1,80 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- use_module(library(gecode)).
:- use_module(library(maplist)).
% 5 people want to have a photograph together, but they have preferences.
photo(Ex, Solution,Amount) :-
db(Ex, People, Preferences),
Space := space,
length(People, Len),
Len0 is Len-1,
People := intvars(Space,Len,0,Len0),
Space += distinct(People),
% Bools are the satisfied constraints
maplist(preferences(Space, Len), Preferences, Bools),
length(Preferences, PLen),
Sum := intvar(Space,0,PLen),
Space += linear(Bools,'IRT_EQ',Sum),
% add all satisfied constraints
Space += maximize(Sum),
Space += branch(People,'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
SolSpace := search(Space),
Solution := val(SolSpace,People),
Amount := val(SolSpace,Sum).
%reification, use with care
preferences(Space, Len, X-Y, B) :-
NLen is -Len,
I0 := intvar(Space, NLen, Len),
I := intvar(Space, 0, Len),
B := boolvar(Space),
Space += reify(B, 'RM_EQV', R),
Space += linear([1,-1],[X,Y],'IRT_EQ', I0),
Space += abs(I0, I),
Space += rel(I, 'IRT_EQ', 1, R).
db(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
Carl-Deb,
Deb-Alice,
Evan-Alice,
Bob-Evan,
Carl-Evan,
Deb-Evan,
Evan-Bob]).
db(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan],
[Betty-Donald,
Betty-Gary,
Betty-Peter,
Chris-Gary,
Chris-Susan,
Donald-Fred,
Donald-Gary,
Fred-Betty,
Fred-Gary,
Gary-Mary,
Gary-Betty,
Mary-Betty,
Mary-Susan,
Paul-Donald,
Paul-Peter,
Peter-Susan,
Peter-Paul]).

67
library/gecode/queens.yap Normal file
View File

@ -0,0 +1,67 @@
%% -*- prolog -*-
%%=============================================================================
%% Copyright (C) 2011 by Denys Duchier
%%
%% This program is free software: you can redistribute it and/or modify it
%% under the terms of the GNU Lesser General Public License as published by the
%% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%=============================================================================
:- use_module(library(gecode)).
:- use_module(library(maplist)).
% use alldiff constraints
queens(N, Solution) :-
Space := space,
length(Queens, N),
Queens := intvars(Space,N,1,N),
Space += distinct(Queens),
foldl(inc, Queens, Inc, 0, _),
foldl(dec, Queens, Dec, 0, _),
Space += distinct(Inc,Queens),
Space += distinct(Dec,Queens),
Space += branch(Queens, 'INT_VAR_SIZE_MIN', 'INT_VAL_MIN'),
SolSpace := search(Space),
Solution := val(SolSpace,Queens).
inc(_, I0, I0, I) :-
I is I0+1.
dec(_, I0, I0, I) :-
I is I0-1.
%
% Using gecode linear constraints for diagonals.
%
lqueens(N, Solution) :-
Space := space,
length(Queens, N),
Queens := intvars(Space,N,1,N),
Space += distinct(Queens),
lconstrain( Queens, Space, 0),
Space += branch(Queens, 'INT_VAR_SIZE_MIN', 'INT_VAL_MIN'),
SolSpace := search(Space),
Solution := val(SolSpace,Queens).
lconstrain([], _, _).
lconstrain( [Q|Queens], Space, I0) :-
I is I0+1,
foldl(constrain(Q, I0, Space), Queens, I, _),
lconstrain( Queens, Space, I).
constrain(Q, I, Space, R, J, J1) :-
% Q+I != R+J, Q-I != R-J <=> Q-R != J-I, Q-R != I-J,
J1 is J+1,
Sum is I-J,
Diff is J-I,
Space += linear([1,-1], [Q,R], 'IRT_NQ', Diff),
Space += linear([1,-1], [Q,R], 'IRT_NQ', Sum).

View File

@ -84,7 +84,10 @@ typedef enum {
matrix_set_all_that_disagree/5,
matrix_expand/3,
matrix_select/4,
matrix_column/3
matrix_column/3,
matrix_get/2,
matrix_set/2,
op(100, fy, '[]')
]).
:- load_foreign_files([matrix], [], init_matrix).

View File

@ -220,6 +220,30 @@ scan_dims(int ndims, YAP_Term tl, int dims[MAX_DIMS])
return TRUE;
}
static int
scan_dims_args(int ndims, YAP_Term tl, int dims[MAX_DIMS])
{
int i;
for (i = 0; i < ndims; i++) {
YAP_Term th;
int d;
th = YAP_ArgOfTerm(2+i, tl);
if (!YAP_IsIntTerm(th)) {
/* ERROR */
return FALSE;
}
d = YAP_IntOfTerm(th);
if (d < 0) {
/* ERROR */
return FALSE;
}
dims[i] = d;
}
return TRUE;
}
static int
cp_int_matrix(YAP_Term tl,YAP_Term matrix)
{
@ -607,6 +631,44 @@ matrix_set(void)
return TRUE;
}
static int
matrix_set2(void)
{
int dims[MAX_DIMS], *mat;
YAP_Term tf, t = YAP_ARG1;
mat = (int *)YAP_BlobOfTerm(YAP_ArgOfTerm(1,t));
if (!mat) {
/* Error */
return FALSE;
}
if (!scan_dims_args(mat[MAT_NDIMS], t, dims)) {
/* Error */
return FALSE;
}
tf = YAP_ARG2;
if (mat[MAT_TYPE] == INT_MATRIX) {
if (YAP_IsIntTerm(tf)) {
matrix_long_set(mat, dims, YAP_IntOfTerm(tf));
} else if (YAP_IsFloatTerm(tf)) {
matrix_long_set(mat, dims, YAP_FloatOfTerm(tf));
} else {
/* Error */
return FALSE;
}
} else {
if (YAP_IsIntTerm(tf)) {
matrix_float_set(mat, dims, YAP_IntOfTerm(tf));
} else if (YAP_IsFloatTerm(tf)) {
matrix_float_set(mat, dims, YAP_FloatOfTerm(tf));
} else {
/* Error */
return FALSE;
}
}
return TRUE;
}
static int
matrix_set_all(void)
{
@ -698,6 +760,25 @@ do_matrix_access(void)
return YAP_Unify(tf, YAP_ARG3);
}
static int
do_matrix_access2(void)
{
int dims[MAX_DIMS], *mat;
YAP_Term tf, t = YAP_ARG1;
mat = (int *)YAP_BlobOfTerm(YAP_ArgOfTerm(1, t));
if (!mat) {
/* Error */
return FALSE;
}
if (!scan_dims_args(mat[MAT_NDIMS], t, dims)) {
/* Error */
return FALSE;
}
tf = matrix_access(mat, dims);
return YAP_Unify(tf, YAP_ARG2);
}
static int
do_matrix_inc(void)
{
@ -2989,9 +3070,11 @@ init_matrix(void)
YAP_UserCPredicate("new_floats_matrix", new_floats_matrix, 4);
YAP_UserCPredicate("new_floats_matrix_set", new_floats_matrix_set, 4);
YAP_UserCPredicate("matrix_set", matrix_set, 3);
YAP_UserCPredicate("matrix_set", matrix_set2, 2);
YAP_UserCPredicate("matrix_set_all", matrix_set_all, 2);
YAP_UserCPredicate("matrix_add", matrix_add, 3);
YAP_UserCPredicate("matrix_get", do_matrix_access, 3);
YAP_UserCPredicate("matrix_get", do_matrix_access2, 2);
YAP_UserCPredicate("matrix_inc", do_matrix_inc, 2);
YAP_UserCPredicate("matrix_dec", do_matrix_dec, 2);
YAP_UserCPredicate("matrix_inc", do_matrix_inc2, 3);

View File

@ -851,7 +851,7 @@ opinfo("p_nonvar_x",[body,ifthenelse]).
opinfo("p_nonvar_y",[body,ifthenelse]).
opinfo("save_b_x",[body,new("x")]).
opinfo("save_b_y",[body,new("y")]).
opinfo("ensure_space",[body]).
opinfo("ensure_space",[]).
opinfo("write_x_loc",[body]).
opinfo("write_x_var",[body,new("x")]).
opinfo("write_y_var",[body,new("y")]).

View File

@ -77,6 +77,7 @@ CLPBN_LEARNING_PROGRAMS= \
$(CLPBN_LEARNING_SRCDIR)/bnt_parms.yap \
$(CLPBN_LEARNING_SRCDIR)/em.yap \
$(CLPBN_LEARNING_SRCDIR)/learn_utils.yap \
$(CLPBN_LEARNING_SRCDIR)/learn_mln_wgts.yap \
$(CLPBN_LEARNING_SRCDIR)/mle.yap
CLPBN_EXAMPLES= \

View File

@ -116,7 +116,7 @@ graph_representation([V|Vs], Graph, I0, Keys, TGraph) :-
length(Vals,Sz),
project_evidence_out([V|Parents],[V|Parents],Table,[Sz|Szs],Variables,NewTable),
% all variables are parents
propagate2parents(Variables, NewTable, Variables, Graph, Keys),
maplist( propagate2parent(NewTable, Variables, Graph, Keys), Variables),
graph_representation(Vs, Graph, I0, Keys, TGraph).
graph_representation([V|Vs], Graph, I0, Keys, [I-IParents|TGraph]) :-
I is I0+1,
@ -129,7 +129,7 @@ graph_representation([V|Vs], Graph, I0, Keys, [I-IParents|TGraph]) :-
sort_according_to_indices(NewParents,Keys,SortedNVs,SortedIndices),
reorder_CPT(Variables,NewTable,[V|SortedNVs],NewTable2,_),
add2graph(V, Vals, NewTable2, SortedIndices, Graph, Keys),
propagate2parents(NewParents, NewTable, Variables, Graph,Keys),
maplist( propagate2parent(NewTable, Variables, Graph,Keys), NewParents),
maplist(parent_index(Keys), NewParents, IVariables0),
sort(IVariables0, IParents),
arg(I, Graph, var(_,_,_,_,_,_,_,NewTable2,SortedIndices)),
@ -158,13 +158,11 @@ project_evidence_out([V|Parents],Deps,Table,Szs,NewDeps,NewTable) :-
project_evidence_out([_Par|Parents],Deps,Table,Szs,NewDeps,NewTable) :-
project_evidence_out(Parents,Deps,Table,Szs,NewDeps,NewTable).
propagate2parents([], _, _, _, _).
propagate2parents([V|NewParents], Table, Variables, Graph, Keys) :-
propagate2parent(Table, Variables, Graph, Keys, V) :-
delete(Variables,V,NVs),
sort_according_to_indices(NVs,Keys,SortedNVs,SortedIndices),
reorder_CPT(Variables,Table,[V|SortedNVs],NewTable,_),
add2graph(V, _, NewTable, SortedIndices, Graph, Keys),
propagate2parents(NewParents,Table, Variables, Graph, Keys).
add2graph(V, _, NewTable, SortedIndices, Graph, Keys).
add2graph(V, Vals, Table, IParents, Graph, Keys) :-
rb_lookup(V, Index, Keys),
@ -298,14 +296,12 @@ init_chains(I,VarOrder,Len,Graph,[Chain|Chains]) :-
init_chain(VarOrder,Len,Graph,Chain) :-
functor(Chain,sample,Len),
gen_sample(VarOrder,Graph,Chain).
maplist( gen_sample(Graph,Chain), VarOrder).
gen_sample([],_,_) :- !.
gen_sample([I|Vs],Graph,Chain) :-
arg(I,Graph,var(_,I,_,_,Sz,_,_,_,_)),
gen_sample(Graph, Chain, I) :-
arg(I, Graph, var(_,I,_,_,Sz,_,_,_,_)),
Pos is integer(random*Sz),
arg(I,Chain,Pos),
gen_sample(Vs,Graph,Chain).
arg(I, Chain, Pos).
init_estimates(0,_,_,[]) :- !.

View File

@ -9,22 +9,32 @@
%
%
:- module(learn_mlns_generative,
[learn_mln_generative/0,
portray_mln/0]).
:- use_module(library(lists)).
:- use_module(library(tries)).
:- use_module(library(maplist)).
:- use_module(library(nb)).
:- use_module(library(mlns)).
:- use_module(library(matrix)).
:- use_module(library(pfl)).
:- reexport(library(mlns)).
:- reexport(library(pfl)).
:- use_module(library(lbfgs)).
:- dynamic diff/4, i/2.
:- yap_flag(tabling_mode,local).
:- dynamic diff/4, lit/1, i/2.
prior_means(_, 0.0).
prior_dev(_, 100.0).
prior_dev(_, 1.0).
learn_mln_generative :-
compile,
@ -33,43 +43,70 @@ learn_mln_generative :-
set_weights :-
retract( mln:mln_w(Id, _) ),
optimizer_get_x( Id, W),
% writeln(weight:W),
%writeln(weight:W),
assert( mln:mln_w(Id, W) ),
fail.
set_weights.
add_lprior(Id-WI, Lik0, Lik) :-
prior_means(Id, PM),
prior_dev(Id, PV),
Lik is Lik0 + ((WI-PM)*(WI-PM))/(2*PV*PV).
adjust_lprior(Lik0, Lik) :-
Lik0 = Lik, !.
adjust_lprior(Lik0, Lik) :-
findall(I-WI, mln_w(I,WI), WIs),
foldl(add_lprior, WIs, Lik0, Lik).
add_lprior(Id-WI, Lik0, Lik) :-
prior_means(Id, PM),
prior_dev(Id, PV),
Lik is Lik0 + ((WI-PM)*(WI-PM))/(2*PV*PV).
likelihood(Lik) :-
S = s(0.0),
% nb_create_accumulator(0.0, Acc),
(
lmln:p(_Lit,P,_,_),
LogP is log(P),
% writeln(_Lit:P),
recorded(i, [Ref|N], _),
peval(Ref, LogP),
%writeln(N*P),
S = s(V),
V1 is V+LogP,
V1 is V+N*LogP,
nb_setarg(1, S, V1),
% nb_add_to_accumulator( Acc, LogP),
fail
;
% nb_accumulator_value(Acc, Lik)
S = s(Lik0),
writeln(lik:Lik0),
%writeln(lik:Lik0),
adjust_lprior(Lik0, Lik1),
Lik is -Lik1
).
derive :-
nb_getval(i2, Mat),
nb_getval(d2, MatD),
matrix_set_all(MatD, 0.0),
recorded(i, [Ref|NI], _),
trie_get_entry(Ref, e(_, Ds, Ps)),
member(n(Id,Occs,DN0,DN1), Ds),
matrix_get(Mat, [Id], N),
matrix_get(MatD, [Id], V),
peval(Ps, P0, P1),
X is Occs*(N-P0*(N+DN0)-P1*(N+DN1)),
%writeln(X is NI*(-P0*(DN0)-P1*(DN1))),
V1 is V-NI*X,
matrix_set(MatD, [Id], V1),
fail.
derive :-
nb_getval(d2, MatD),
mln(Ms),
N1 is Ms-1,
between(0, N1, Id),
matrix_get(MatD, [Id], Sum),
%writeln(d:Id:Sum),
adjust_prior(Sum, Id, NSum),
optimizer_set_g(Id, NSum ),
fail.
derive.
adjust_prior(Lik0, _, Lik) :-
Lik0 = Lik, !.
adjust_prior(Sum, Id, NSum) :-
@ -78,206 +115,258 @@ adjust_prior(Sum, Id, NSum) :-
prior_dev(Id, PV),
NSum is Sum+(Wi-PM)/(PV*PV).
derive :-
mln(Id, _, Els, _),
i(Id, N),
%writeln(Id:N),
% nb_create_accumulator(0.0, Acc),
S = s(0.0),
% nb_accumulator_value(Acc, Sum0),writeln(sum0:Sum0),
(
nth(_L, Els, VId),
p_l(Id, VId, P0, P1),
diff( VId, Id, DN0, DN1),
X is (N-P0*(N+DN0)-P1*(N+DN1)),
%writeln(X is (N-P0*(N+DN0)-P1*(N+DN1))),
% nb_add_to_accumulator(Acc, X),
S = s(V),
V1 is V-X,
nb_setarg(1, S, V1),
fail
;
% nb_accumulator_value(Acc, Sum),
S = s(Sum),
writeln(d:Id:Sum),
adjust_prior(Sum, Id, NSum),
optimizer_set_g(Id, NSum ),
fail
).
derive.
:- dynamic old_fx/1.
old_fx(+inf).
% This is the call back function which is invoked to report the progress
% if the last argument is set to anywhting else than 0, the optimizer will
% if the last argument is set to anything else than 0, the optimizer will
% stop right now
progress(FX,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
user:progress(FX,X_Norm,G_Norm,Step,_N,Iteration,Ls, Out) :-
( Iteration mod 100 =:= 0 -> atomic_concat([tmp_,Iteration,'.pfl'], File), open( File, write, S), portray_mln(S), close(S) ; true ),
retract(old_fx(FX0)),
( Delta is FX-FX0, abs(Delta/FX) < 0.00001 -> Out = 1 ; Out = 0),
optimizer_get_x(0,X0),
format('~d. Iteration : w=~4f f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,X0,FX,X_Norm,G_Norm,Step,Ls]).
assert(old_fx(FX)),
format('/* ~d: w[0]=~10f f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f */~n',[Iteration,X0,FX,X_Norm,G_Norm,Step,Ls]).
% This is the call back function which evaluates F and the gradient of F
evaluate(FX,_N,_Step) :-
set_weights,
likelihood(FX),
derive.
% This is the call back function which evaluates F and the gradient of F
user:evaluate(FX,_N,_Step) :-
set_weights,
likelihood(FX),
derive.
init_vars(Ev, Pr) :-
mln(N),
N1 is N-1,
format('We start the search at weight=0~2n',[]),
optimizer_initialize(N, Ev, Pr),
between(0, N1, I),
optimizer_set_x(I,0.0),
fail.
mln(N),
N1 is N-1,
format('/* We start the search for ~d weights at weight[_]=0 */~2n',[N]),
optimizer_initialize(N, Ev, Pr),
between(0, N1, I),
optimizer_set_x(I,0.0),
fail.
init_vars(_, _).
output_stat(BestF, Status) :-
mln(N),
N1 is N-1,
( between(0,N1,I),
optimizer_get_x(I,BestX0),
format('w[~d] = ~f~n', [I, BestX0]),
fail
;
Lik is -BestF,
format('Final likelihood=~f~2nLBFGS Status=~w~n',[Lik,Status])
).
( portray_mln,
fail
;
Lik is -BestF,
format('/* Final likelihood=~f */~n/* LBFGS Status=~w */~n',[Lik,Status])
).
optimize :-
init_vars(evaluate, progress),
optimizer_run(BestF,Status),
output_stat(BestF, Status),
optimizer_finalize,
format('~2nOptimization done~n',[]).
init_vars(evaluate, progress),
optimizer_run(BestF,Status),
output_stat(BestF, Status),
optimizer_finalize,
format('~2nOptimization done~n',[]).
compile :-
init_compiler,
mln(ParFactor, _Type, _Els, _G),
factor(markov, ParFactor, Ks, _, _Phi, Constraints),
maplist(call, Constraints),
nth(_L, Ks, VId),
compile_pw(VId, P0, P1, G),
assert((p_l(ParFactor, VId, P0, P1) :- lmln:G)),
init_compiler,
compile_literals,
fail.
/*
compile :-
recorded(i, [Ref|N], _),
trie_get_entry(Ref, E),
writeln(N:E),
fail.
*/
compile.
init_compiler :-
retractall(i(_,_)),
retractall(i(_,_,_,_)),
mln(HowMany),
D is HowMany+1,
matrix_new(ints, [D], M),
matrix_new(floats, [D], MD),
nb_setval(i2,M),
nb_setval(d2,MD),
collect_literals,
init_trie,
retractall(p_l(_,_,_,_)),
retractall(lmln:p(_,_,_,_)),
fail.
init_compiler.
compile_pw(VId, P0, P1, p(VId, _, P0, P1)) :-
clause(lmln:p(VId, _, P0, P1), _), !.
compile_pw(VId, Head0, Head1, G) :-
G = p(VId, Head, Head0, Head1),
compile(VId,Head,Head0,Head1,Bd),
assert( ( lmln:G :- Bd) ).
init_trie :-
catch(nb_getval( mln_trie, Trie ), _, fail),
trie_close( Trie ),
eraseall( i ),
fail.
init_trie :-
trie_open( Trie ),
nb_setval( mln_trie , Trie ).
compile(VId, P, P0, P1, Bd) :-
findall(p(FId,W,P0,P1), find_prob(VId, FId, W, P0, P1), Fs),
(evidence(VId, 1) -> P = P1 ; P = P0),
collect_literals :-
mln(ParFactor, _Type, _Els, _G, _DConstraints),
factor(markov, ParFactor, Ks, _, _Phi, _Constraints),
maplist(add_lit, Ks),
fail.
collect_literals.
add_lit(K) :-
functor(K, N, A),
functor(K0, N, A),
( lit(K0) -> true ; assert(lit(K0)) ).
compile_literals :-
lit(K),
functor(K, N, A),
statistics(runtime,_),
format(user_error, '/** grounding ~a/~d.~45+**/~n',[N,A]),
% evidence(K, 1),
( ground_lit(K),
%writeln(k:K),
compile_pw(K)
;
statistics(runtime,[_,T]),
format(user_error, '/** took ~d msec.~45+**/~n',[T]),
fail
).
ground_lit(K) :-
functor(K, _, Ar),
ground_lit(0, Ar, K).
ground_lit(Ar, Ar, _K).
ground_lit(I0, Ar, K) :-
I is I0+1,
(mln):mln_domain(I, K, G, _A),
user:G,
ground_lit(I, Ar, K).
compile_pw(VId) :-
(evidence(VId, 1) -> P = 1 ; P = 0),
compile(VId, P).
compile(VId, Val) :-
findall(p(FId,W,P0,P1,I0,I1), find_prob(VId, Val, FId, W, P0, P1, I0, I1), Fs),
(
Fs == [] -> fail
;
Fs = [p(F,W,1,1)]
Fs = [p(FId,W,1,1,I0,I1)]
->
P0 = 0.5, P1 = 0.5, Bd = true
; Fs = [p(F,W,P0A,P1A)]
->
Bd = (mln_w(F, W), P0 is P0A/(P0A+P1A), P1 is 1-P0)
;
Fs = [p(FA,WA,P0A,P1A),p(FB,WB,P0B,P1B)]
->
Bd = (mln_w(FA, WA), mln_w(FB, WB), P0 is P0A*P0B/(P0A*P0B+P1A*P1B), P1 is 1-P0)
;
Bd = ( sumps(Fs, V0, 1.0, V1, 1.0), P0 is V1/(V0+V1), P1 is 1-P0)
fail
;
sort(Fs, FsS),
merge_lits(FsS, FsN, Ws),
nb_getval( mln_trie, Trie ),
store( Trie, e(Val, Ws, FsN) )
).
find_prob(VId, ParFactor, W, P0, P1) :-
defined_in_factor(VId, ParFactor, L),
factor(markov, ParFactor, Ks, _, _Phi, Constraints),
nth0(L, Ks, VId),
maplist(call,Constraints),
mln(ParFactor, _Type, LP, _Head),
foldl(true_literal, LP, Ks, 0, NTs),
NTs < 2, % >= 2 ignore, always true...
maplist(polarity(VId, Pol), LP),
(NTs == 0 ->
/* We have no true literal */
( Pol == (+) ->
% inc_n(ParFactor, L1, 1),
(evidence(VId, 1) -> /* we are */
assert(diff(VId,ParFactor,-1, 0))
store( T , E ) :-
trie_check_entry(T, E, R), !,
recorded(i, [R|I], Ref),
erase(Ref),
I1 is I+1,
recorda(i, [R|I1], _).
store( T , E ) :-
trie_put_entry(T, E, R), !,
recorda(i, [R|1], _).
merge_lits([], [], []).
merge_lits([N*p(F,W,A1,A2,I1,I2), p(F,W,A3,A4,I3,I4)|FsS], FsM, Is) :-
A1 == A3,
A2 == A4,
I1 == I3,
I2 == I4, !,
N1 is N+1,
merge_lits([N1*p(F,W,A3,A4,I3,I4)|FsS], FsM, Is).
merge_lits([p(F,W,A1,A2,I1,I2), p(F,W,A3,A4,I3,I4)|FsS], FsM, Is) :-
A1 == A3,
A2 == A4,
I1 == I3,
I2 == I4, !,
merge_lits([2*p(F,W,A3,A4,I3,I4)|FsS], FsM, Is).
merge_lits([p(F,W,A1,A2,I1,I2) | FsS], [p(F,1,W,A1,A2)|FsM], [n(F,1,I1,I2)|Is]) :-
merge_lits(FsS, FsM, Is).
merge_lits([N*p(F,W,A1,A2,I1,I2) | FsS], [p(F,N,W,A1,A2)|FsM], [n(F,N,I1,I2)|Is]) :-
merge_lits(FsS, FsM, Is).
find_prob(VId, E, ParFactor, W, P0, P1, I0, I1) :-
mln(ParFactor, _, _Type, _, Constraints),
% maplist(call,Constraints),
deletei(Constraints, VId, ConstraintsF, Pol),
maplist(expand_domain(VId-Pol), ConstraintsF),
% all other literals are false
( Pol == (+) ->
P0 = 0, P1 = W,
(E == 1 -> /* we are making this true */
inc(ParFactor),
I0 = -1, I1 = 0
;
assert(diff(VId, ParFactor, 0, 1))
),
P0 = 1, P1 = exp(W)
;
% inc_n(ParFactor, L1, 0),
(evidence(VId, 1) -> /* we are */
assert(diff(VId,ParFactor, 1, 0))
;
assert(diff(VId, ParFactor, 0, -1))
),
P0 = exp(W), P1 = 1
)
/* it is false */
I0 = 0, I1 = 1
)
;
/* L == 0: increment true literals once */
(L == 0 -> inc(ParFactor) ; true ),
/* We have a single true literal */
( %are we that literal ?
Pol == (+) ->
(evidence(VId, 1) -> /* we are */
% inc_n(ParFactor, L1, 1),
assert(diff(VId,ParFactor, -1, 0)),
P0 = 1, P1 = exp(W) ;
/* we are not */
assert(diff(VId,ParFactor, 0, 0)),
% inc_n(ParFactor, L1, 0),
% inc_n(ParFactor, L1, 1),
P0 = 1, P1 = 1
)
P0 = W, P1 = 0,
(E == 1 -> /* we are making this false */
I0 = 1, I1 = 0
;
% NEGATIVE polarity
(evidence(VId, 1) -> /* we are not */
assert(diff(VId,ParFactor, 0, 0)),
% inc_n(ParFactor, L1, 0),
% inc_n(ParFactor, L1, 1),
P0 = 1, P1 = 1 ;
/* we are */
assert(diff(VId,ParFactor, 0, -1)),
% inc_n(ParFactor, L1, 0),
P0 = exp(W), P1 = 1
/* it is true */
inc(ParFactor),
I0 = 0, I1 = -1
)
)
).
polarity(L, -, -L) :- !.
polarity(L, +, L) :- !.
polarity(_, _, _).
expand_domain(VIdPol, true - Lits) :- !,
maplist( false_literal(VIdPol), Lits).
true_literal(-L, L, N, N1) :- !,
( evidence(L, 1) -> N1 = N ; N1 is N+1 ).
true_literal(L, L, N, N1) :-
( evidence(L, 1) -> N1 is N+1 ; N1 = N ).
expand_domain(VIdPol, Dom-Lits) :-
call(user:Dom),
maplist( true_literal(VIdPol), Lits).
% we need to check if we have
% L ; L or L ; -L
% in this case skip or it is always true, so fail.
false_literal(L-(-), L).
false_literal(VId-_, L) :-
evidence(L, 1),
L \= VId.
% L is ground
true_literal(L-(+), L) :- !.
true_literal(VId-_, L) :-
L \= VId,
\+ evidence(L, 1).
deletei([true-Lits|More], K, [true-NLits|More], -) :-
force_delete(Lits, K, NLits).
deletei([true-Lits|More], K, [true-Lits|NMore], -) :- !,
force_delete(More, K, NMore).
deletei(More, K, NMore, +) :-
deletei(More, K, NMore).
deletei([Dom-Lits|More], K, [Dom-NLits|More]) :-
force_delete(Lits, K, NLits).
deletei([DomLits|More], K, [DomLits|NMore]) :-
deletei(More, K, NMore).
force_delete([Elem|List], Elem, List).
force_delete([Head|List], Elem, [Head|Residue]) :-
force_delete(List, Elem, Residue).
inc(Id) :-
retract(i(Id, N)), !,
N1 is N+1,
assert(i(Id, N1)).
inc(Id) :-
assert(i(Id, 1)).
nb_getval(i2, M),
matrix_inc(M, [Id]).
% V is f (0)
check(W, V, -V, exp(W), _R, Matters, Matters0) :- !, Matters = Matters0.
check(_W, V, V, R, R, Matters, Matters0) :- !, Matters = Matters0.
check(W, _V, -V, Rf, R0, Matters, Matters0) :- !,
(evidence(V, 1) -> Rf = R0, Matters=Matters0; Rf = exp(W), Matters = not).
check(W, _V, V, Rf, R0, Matters, Matters0) :-
(evidence(V, 1) -> Rf = exp(W), Matters = not ; Rf = R0, Matters=Matters0).
peval(Ref, P) :-
trie_get_entry(Ref, e(Side, _, Ps)),
foldl2(p_eval, Ps, 0.0, P0, 0.0, P1),
logsum(P0, P1, P01),
( Side == 0 -> P = P0-P01 ; P = P1-P01 ).
complement(W, exp(W), 1).
complement(W, 1, exp(W)).
peval(Ps, P0, P1) :-
%writeln(p:Ds:Ps),
foldl2(p_eval, Ps, 0.0, AP0, 0.0, AP1),
logsum(AP0, AP1, AP01),
P0 is exp( AP0 - AP01 ),
P1 is 1-P0.
p_eval(p(WId, N, W, P0, P1), AP0, A0, AP1, A1) :-
mln_w(WId, W),
A0 is AP0+N*P0,
A1 is AP1+N*P1.

View File

@ -2,21 +2,33 @@
[op(1150,fx,mln),
op(1150,fx,mln_domain),
mln_domain/1,
mln_literal/1,
mln/1,
mln/4,
mln_w/2]).
mln/5,
mln_w/2,
portray_mln/0,
portray_mln/1]).
:- use_module(library(pfl)).
:- use_module(library(maplist)).
:- use_module(library(lists)).
:- use_module(library(terms)).
:- dynamic mln/1, mln/2, mln_domain/4, mln/4, mln_w/2.
:- dynamic mln/1, mln/2, mln_domain/4, mln/5, mln_w/2, mln_domain/5, mln_type_def/1.
user:term_expansion(mln_domain(P),[]) :-
expand_domain(P).
user:term_expansion( mln(W: D), pfl:factor(markov,Id,FList,FV,Phi,Constraints)) :-
translate_to_factor(W, D, FList, Id, FV, Phi, Constraints).
translate_to_factor(W, D, FList, Id, FV, Phi, Constraints), !.
user:term_expansion( mln(W: D), _) :-
throw(error(domain_error(mln,W:D),error)).
user:term_expansion(end_of_file,_) :-
mln_domain(TypeG, NP, I0, A, Type),
add_mln_domain(TypeG, NP, I0, A, Type),
fail.
user:term_expansion(end_of_file,end_of_file).
expand_domain((P1,P2)) :- !,
expand_domain(P1),
@ -31,8 +43,26 @@ do_type(NP, Type, I0, I) :-
I is I0+1,
arg(I0, NP, A),
TypeG =.. [Type, A],
assert(mln_domain(TypeG, NP, I0, A, Type)),
assert(mln_domain(I0, NP, TypeG, A)).
add_mln_domain(TypeG, NP, I0, A, _) :-
mln_type_def(TypeG), !,
functor(NP, G, Ar),
functor(NNP, G, Ar),
arg(I0, NNP, A),
assert_static(user:(TypeG :- NNP)).
add_mln_domain(TypeG, _NP, _I0, _A, _) :-
predicate_property(user:TypeG, _), !.
add_mln_domain(TypeG, NP, I0, A, Type) :-
assert(mln_type_def(TypeG)), !,
functor(NP, G, Ar),
functor(NNP, G, Ar),
arg(I0, NNP, A),
table(user:Type/1),
assert_static(user:(TypeG :- NNP)).
translate_to_factor(W, D, Lits, Id, Vs, Phi, Domain) :-
W0 is exp(W),
(
@ -57,10 +87,22 @@ translate_to_factor(W, D, Lits, Id, Vs, Phi, Domain) :-
new_mln(Id),
maplist(new_skolem(Id), Lits),
term_variables(Lits, Vs),
create_domain(Lits, Domain),
create_domain(Lits, Domain0),
exclude(ground, Domain0, Domain),
make_clause(Id, Do, Vs, Domain, Lits, LP, Head),
assert(mln_w(Id, W)),
assert(mln(Id, Do, LP, Head)).
assert(mln_w(Id, W)),
find_pos(LP, NLP, Pos),
foldl2(merge_domain_lits, Domain, NDomain, [], _, NLP, [] ),
exclude(empty_goal, [true-Pos|NDomain], FDomain),
assert(mln(Id, Do, LP, Head, FDomain)).
empty_goal(_-[]).
find_pos([], [], []).
find_pos([-Lit|Lits], LP, [Lit|Pos]) :- !,
find_pos(Lits, LP, Pos).
find_pos([Lit|Lits], [Lit|LP], Pos) :-
find_pos(Lits, LP, Pos).
%
% naive translation of conj/disjunction into Prolog
@ -74,7 +116,7 @@ make_clause(Id, Do, Vs, Domain, _Lits, Fs, Head) :-
order_body(disj, Fs, Bd0) :-
order_body(Fs, Bd0).
order_body(conj, Fs, Bd0) :-
andder_body(Fs, Bd0),
ander_body(Fs, Bd0),
order_body([-G], (\+ G)).
@ -106,6 +148,23 @@ new_mln(Id) :-
Id1 is Id+1,
assert(mln(Id1)).
merge_domain_lits( Domain, Domain-Gs, Vs, [V|Vs], LP0, LPF) :-
arg(1, Domain, V),
delete_with_v(LP0, [V|Vs], LPF, Gs).
delete_with_v([], _Vs, [], []).
delete_with_v([G|LP0], Vs, LPF, NGs) :-
new_variables_in_term(Vs, G, NVs),
( NVs == [] ->
NGs = [G|Gs],
LPF = LP1
;
NGs = Gs,
LPF = [G|LP1]
),
delete_with_v(LP0, Vs, LP1, Gs).
%
% make it easier to manipulate
%
@ -128,8 +187,8 @@ disj_to_list2((C1+C2), L1, L10, L, L0) :-
disj_to_list2(C2, L1I, L10, LI, L0).
disj_to_list2((_C1,_C2), _L1, _L10, _L, _L0) :- !, fail.
disj_to_list2((_C1*_C2), _L1, _L10, _L, _L0) :- !, fail.
disj_to_list2((\+ C), [(-C)|L1], L1, [C|L], L) :- literal(C), !.
disj_to_list2((- C), [(-C)|L1], L1, [C|L], L) :- literal(C), !.
disj_to_list2((\+ C), [(-C)|L1], L1, [C|L], L) :- !.
disj_to_list2((- C), [(-C)|L1], L1, [C|L], L) :- !.
disj_to_list2(C, [C|L1], L1, [C|L], L).
conj_to_list((C1,C2), L1, L10, L, L0) :-
@ -151,8 +210,8 @@ conj_to_list2((C1*C2), L1, L10, L, L0) :-
!,
conj_to_list2(C1, L1, L1I, L, LI),
conj_to_list2(C2, L1I, L10, LI, L0).
conj_to_list2((\+ C), [(C)|L1], L1, [C|L], L) :- literal(C), !.
conj_to_list2((- C), [(C)|L1], L1, [C|L], L) :- literal(C), !.
conj_to_list2((\+ C), [(C)|L1], L1, [C|L], L) :- !.
conj_to_list2((- C), [(C)|L1], L1, [C|L], L) :- !.
conj_to_list2(C, [-C|L1], L1, [C|L], L).
remove_not(-G, G) :- !.
@ -257,7 +316,7 @@ clean_cnf(CNF, NCNF) :-
% count groundings
%
all_true(Id, V) :-
mln(Id, _F, _D, Head),
mln(Id, _F, _D, Head, _),
nb_create_accumulator(0, Acc),
(
call(user:Head),
@ -267,3 +326,29 @@ all_true(Id, V) :-
nb_accumulator_value(Acc, V)
).
portray_mln :-
portray_mln( user_error ).
portray_mln(Stream) :-
mln(Id, _, LP, _, _),
mln_w(Id, W),
format(Stream, 'mln ~4f : ( ', [W] ),
numbervars(LP, 1, _),
portray_lits(Stream, LP),
format(Stream, ' ).~n', [] ),
fail.
portray_mln(_Stream).
portray_lits(Stream, [L1]) :- !,
portray_lit( Stream, L1 ).
portray_lits(Stream, [L1|Ls]) :- !,
portray_lit( Stream, L1 ),
format(Stream, ' ; ', []),
portray_lits( Stream, Ls ).
portray_lit( Stream, -L ) :- !,
format( Stream, '\\+ ~q', [L] ).
portray_lit( Stream, L ) :-
format( Stream, '~q', [L] ).

View File

@ -167,16 +167,24 @@ process_arg(Sk, Id, _I) -->
},
[Sk].
%
% redefinition
%
new_skolem(Sk, D) :-
copy_term(Sk, Sk1),
skolem(Sk1, D1),
functor(Sk1, N, A),
functor(Sk , N, A),
!,
functor(Sk , N, A), !,
( D1 = D -> true ; throw(pfl(permission_error(redefining_domain(Sk),D:D1)))).
%
%
% create interface and skolem descriptor
%
new_skolem(Sk, D) :-
functor(Sk, N, A),
functor(NSk, N, A),
% [f,t] is special for evidence
( D = [f,t] -> assert((evidence(NSk, 1) :- user:NSk)) ; true ),
interface_predicate(NSk),
assert(skolem(NSk, D)).

View File

@ -91,9 +91,9 @@ optimizer_parameters :-
optimizer_get_parameter(orthantwise_start,Orthantwise_Start),
optimizer_get_parameter(orthantwise_end,Orthantwise_End),
format('==========================================================================================~n',[]),
format('/******************************************************************************************~n',[]),
print_param('Name','Value','Description','Type'),
format('==========================================================================================~n',[]),
format('******************************************************************************************~n',[]),
print_param(m,M,'The number of corrections to approximate the inverse hessian matrix.',int),
print_param(epsilon,Epsilon,'Epsilon for convergence test.',float),
print_param(past,Past,'Distance for delta-based convergence test.',int),
@ -109,7 +109,7 @@ optimizer_parameters :-
print_param(orthantwise_c,Orthantwise_C,'Coefficient for the L1 norm of variables',float),
print_param(orthantwise_start,Orthantwise_Start,'Start index for computing the L1 norm of the variables.',int),
print_param(orthantwise_end,Orthantwise_End,'End index for computing the L1 norm of the variables.',int),
format('==========================================================================================~n',[]),
format('******************************************************************************************/~n',[]),
format(' use optimizer_set_paramater(Name,Value) to change parameters~n',[]),
format(' use optimizer_get_parameter(Name,Value) to see current parameters~n',[]),
format(' use optimizer_parameters to print this overview~2n',[]).

View File

@ -30,7 +30,7 @@
#define OPTIMIZER_STATUS_CB_EVAL 3
#define OPTIMIZER_STATUS_CB_PROGRESS 4
void init_lbfgs_predicates( void ) ;
int optimizer_status=OPTIMIZER_STATUS_NONE; // the internal state
int n; // the size of the parameter vector
@ -50,7 +50,9 @@ static lbfgsfloatval_t evaluate(
)
{
YAP_Term call;
YAP_Term a1;
YAP_Bool result;
YAP_Int s1;
YAP_Term t[3];
@ -61,6 +63,8 @@ static lbfgsfloatval_t evaluate(
call = YAP_MkApplTerm(fcall3, 3, t);
g=g_tmp;
s1 = YAP_InitSlot(call);
optimizer_status=OPTIMIZER_STATUS_CB_EVAL;
result=YAP_CallProlog(call);
optimizer_status=OPTIMIZER_STATUS_RUNNING;
@ -71,11 +75,16 @@ static lbfgsfloatval_t evaluate(
return FALSE;
}
if (YAP_IsFloatTerm(YAP_ArgOfTerm(1,call))) {
return (lbfgsfloatval_t) YAP_FloatOfTerm(YAP_ArgOfTerm(1,call));
} else if (YAP_IsIntTerm(YAP_ArgOfTerm(1,call))) {
return (lbfgsfloatval_t) YAP_IntOfTerm(YAP_ArgOfTerm(1,call));
}
call = YAP_GetFromSlot( s1 );
a1 = YAP_ArgOfTerm(1,call);
if (YAP_IsFloatTerm(a1)) {
YAP_ShutdownGoal( TRUE );
return (lbfgsfloatval_t) YAP_FloatOfTerm(a1);
} else if (YAP_IsIntTerm(a1)) {
YAP_ShutdownGoal( TRUE );
return (lbfgsfloatval_t) YAP_IntOfTerm(a1);
}
YAP_ShutdownGoal( TRUE );
fprintf(stderr, "ERROR: The evaluate call back function did not return a number as first argument.\n");

View File

@ -219,7 +219,8 @@ true :- true.
get_value('$top_level_goal',GA), GA \= [], !,
set_value('$top_level_goal',[]),
'$run_atom_goal'(GA),
( '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ).
'$nb_getval'('$break',BreakLevel,fail),
( BreakLevel \= 0 -> true ; '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ).
'$enter_top_level' :-
'$run_toplevel_hooks',
prompt1(' ?- '),
@ -229,7 +230,8 @@ true :- true.
nb_setval('$debug_run',off),
nb_setval('$debug_jump',off),
'$command'(Command,Varnames,_Pos,top),
( '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ).
'$nb_getval'('$break',BreakLevel,fail),
( BreakLevel \= 0 -> true ; '$pred_exists'(halt(_), user) -> halt(0) ; '$halt'(0) ).
'$erase_sets' :-

View File

@ -159,11 +159,13 @@ no_style_check([H|T]) :- no_style_check(H), no_style_check(T).
'$handle_multiple'(F,A,NM),
fail.
'$check_term'(_, T,_,_,M) :-
once((
(
get_value('$syntaxcheckdiscontiguous',on)
->
true
;
get_value('$syntaxcheckmultiple',on)
)),
),
nb_getval('$consulting_file',File),
'$xtract_head'(T,M,NM,_,F,A),
\+ (

View File

@ -106,7 +106,7 @@ encode([I0, I1, I2|Rest]) --> !,
},
encode(Rest).
encode([I0, I1]) --> !,
[O0, O1, O2, 0'=],
[O0, O1, O2, 0'=], %'
{ A is (I0<<16)+(I1<<8),
O00 is (A>>18) /\ 0x3f,
O01 is (A>>12) /\ 0x3f,