version 1.32, 2003/08/19 04:38:09 |
version 1.33, 2003/08/19 05:29:11 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.31 2003/08/13 03:13:22 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.32 2003/08/19 04:38:09 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 67 typedef struct oND_pairs { |
|
Line 67 typedef struct oND_pairs { |
|
unsigned int lcm[1]; |
unsigned int lcm[1]; |
} *ND_pairs; |
} *ND_pairs; |
|
|
int (*nm_compare_generic)(NM a,NM b); |
int (*nm_compare_function)(NM a,NM b); |
int (*nmv_compare_generic)(NMV a,NMV b); |
int (*nmv_compare_function)(NMV a,NMV b); |
|
int (*ndp_compare_function)(ND_pairs a,ND_pairs b); |
|
|
double nd_scale=2; |
double nd_scale=2; |
static unsigned int **nd_bound; |
static unsigned int **nd_bound; |
Line 84 ND_pairs _ndp_free_list; |
|
Line 85 ND_pairs _ndp_free_list; |
|
|
|
static NDV *nd_ps; |
static NDV *nd_ps; |
static NDV *nd_psq; |
static NDV *nd_psq; |
int *nd_psl; |
|
RHist *nd_psh; |
RHist *nd_psh; |
int nd_psn,nd_pslen; |
int nd_psn,nd_pslen; |
|
|
Line 108 extern int Top,Reverse; |
|
Line 108 extern int Top,Reverse; |
|
#define TD(a) ((a)->td) |
#define TD(a) ((a)->td) |
#define SG(a) ((a)->sugar) |
#define SG(a) ((a)->sugar) |
#define LEN(a) ((a)->len) |
#define LEN(a) ((a)->len) |
|
#define LCM(a) ((a)->lcm) |
|
|
#define NM_COMPARE(m1,m2)\ |
#define NM_COMPARE(m1,m2)\ |
nd_degcompat?(TD(m1)>TD(m2)?1\ |
(nd_degcompat?(TD(m1)>TD(m2)?1\ |
:(TD(m1)<TD(m2)?-1:ndl_compare(DL(m1),DL(m2))))\ |
:(TD(m1)<TD(m2)?-1:ndl_compare(DL(m1),DL(m2))))\ |
:(*nm_compare_generic)(m1,m2) |
:(*nm_compare_function)(m1,m2)) |
|
#define NMV_COMPARE(m1,m2)\ |
|
(nd_degcompat?(TD(m1)>TD(m2)?1\ |
|
:(TD(m1)<TD(m2)?-1:ndl_compare(DL(m1),DL(m2))))\ |
|
:(*nmv_compare_function)(m1,m2)) |
|
#define NDP_COMPARE(m1,m2)\ |
|
(nd_degcompat?(TD(m1)>TD(m2)?1\ |
|
:(TD(m1)<TD(m2)?-1:ndl_compare(LCM(m1),LCM(m2))))\ |
|
:(*ndp_compare_function)(m1,m2)) |
#define NM_ADV(m) (m = (NM)(((char *)m)+nm_adv)) |
#define NM_ADV(m) (m = (NM)(((char *)m)+nm_adv)) |
#define NEWRHist(r) \ |
#define NEWRHist(r) \ |
((r)=(RHist)MALLOC(sizeof(struct oRHist)+(nd_wpd-1)*sizeof(unsigned int))) |
((r)=(RHist)MALLOC(sizeof(struct oRHist)+(nd_wpd-1)*sizeof(unsigned int))) |
|
|
|
|
int ndv_compare(NDV *p1,NDV *p2) |
int ndv_compare(NDV *p1,NDV *p2) |
{ |
{ |
int td1,td2; |
return NMV_COMPARE(BDY(*p1),BDY(*p2)); |
|
|
if ( nd_degcompat ) { |
|
td1 = HTD(*p1); td2 = HTD(*p2); |
|
if ( td1 > td2 ) return 1; |
|
else if ( td1 < td2 ) return -1; |
|
else return ndl_compare(HDL(*p1),HDL(*p2)); |
|
} else |
|
return (*nmv_compare_generic)(BDY(*p1),BDY(*p2)); |
|
} |
} |
|
|
int ndv_compare_rev(NDV *p1,NDV *p2) |
int ndv_compare_rev(NDV *p1,NDV *p2) |
{ |
{ |
return -ndv_compare(p1,p2); |
return -NMV_COMPARE(BDY(*p1),BDY(*p2)); |
} |
} |
|
|
NODE nd_reduceall(int m,NODE f) |
NODE nd_reduceall(int m,NODE f) |
Line 1912 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 1913 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
{ |
{ |
ND_pairs m,ml,p,l; |
ND_pairs m,ml,p,l; |
unsigned int *lcm; |
unsigned int *lcm; |
int s,td,len,tlen,c; |
int s,td,len,tlen,c,c1; |
|
|
if ( !(p = NEXT(m = d)) ) { |
if ( !(p = NEXT(m = d)) ) { |
*prest = p; |
*prest = p; |
NEXT(m) = 0; |
NEXT(m) = 0; |
return m; |
return m; |
} |
} |
lcm = m->lcm; |
|
s = SG(m); |
s = SG(m); |
td = TD(m); |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) |
len = nd_psl[m->i1]+nd_psl[m->i2]; |
if ( (SG(p) < s) || ((SG(p) == s) && (NDP_COMPARE(p,m) < 0)) ) { |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) { |
ml = l; |
if (SG(p) < s) |
m = p; |
goto find; |
s = SG(m); |
else if ( SG(p) == s ) { |
|
if ( TD(p) < td ) |
|
goto find; |
|
else if ( TD(p) == td ) { |
|
c = ndl_compare(p->lcm,lcm); |
|
if ( c < 0 ) |
|
goto find; |
|
} |
|
} |
} |
continue; |
|
find: |
|
ml = l; |
|
m = p; |
|
lcm = m->lcm; |
|
s = SG(m); |
|
td = TD(m); |
|
len = tlen; |
|
} |
|
if ( !ml ) *prest = NEXT(m); |
if ( !ml ) *prest = NEXT(m); |
else { |
else { |
NEXT(ml) = NEXT(m); |
NEXT(ml) = NEXT(m); |
Line 1961 int nd_newps(int mod,ND a) |
|
Line 1944 int nd_newps(int mod,ND a) |
|
|
|
if ( nd_psn == nd_pslen ) { |
if ( nd_psn == nd_pslen ) { |
nd_pslen *= 2; |
nd_pslen *= 2; |
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
|
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV)); |
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
Line 1978 int nd_newps(int mod,ND a) |
|
Line 1960 int nd_newps(int mod,ND a) |
|
nd_ps[nd_psn] = b; |
nd_ps[nd_psn] = b; |
else |
else |
nd_psq[nd_psn] = b; |
nd_psq[nd_psn] = b; |
nd_psl[nd_psn] = len; |
|
nd_free(a); |
nd_free(a); |
return nd_psn++; |
return nd_psn++; |
} |
} |
Line 1991 int nd_newps_trace(int mod,ND nf,ND nfq) |
|
Line 1972 int nd_newps_trace(int mod,ND nf,ND nfq) |
|
|
|
if ( nd_psn == nd_pslen ) { |
if ( nd_psn == nd_pslen ) { |
nd_pslen *= 2; |
nd_pslen *= 2; |
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
|
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV)); |
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
Line 2008 int nd_newps_trace(int mod,ND nf,ND nfq) |
|
Line 1988 int nd_newps_trace(int mod,ND nf,ND nfq) |
|
nd_bound[nd_psn] = nd_compute_bound(nfq); |
nd_bound[nd_psn] = nd_compute_bound(nfq); |
NEWRHist(r); SG(r) = SG(nf); TD(r) = HTD(nf); ndl_copy(HDL(nf),DL(r)); |
NEWRHist(r); SG(r) = SG(nf); TD(r) = HTD(nf); ndl_copy(HDL(nf),DL(r)); |
nd_psh[nd_psn] = r; |
nd_psh[nd_psn] = r; |
|
|
len = LEN(nd_psq[nd_psn]); |
|
nd_psl[nd_psn] = len; |
|
|
|
nd_free(nf); nd_free(nfq); |
nd_free(nf); nd_free(nfq); |
return nd_psn++; |
return nd_psn++; |
} |
} |
Line 2027 void nd_setup(int mod,NODE f) |
|
Line 2003 void nd_setup(int mod,NODE f) |
|
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
|
|
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
|
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
Line 2082 void nd_setup_trace(int mod,NODE f) |
|
Line 2057 void nd_setup_trace(int mod,NODE f) |
|
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
|
|
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
|
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
Line 2184 void nd_gr_trace(LIST f,LIST v,int m,int homo,struct o |
|
Line 2158 void nd_gr_trace(LIST f,LIST v,int m,int homo,struct o |
|
initd(&ord1); |
initd(&ord1); |
nd_nvar++; |
nd_nvar++; |
} else { |
} else { |
switch ( ord->ord.simple ) { |
|
case 0: nd_isrlex = 1; nd_degcompat = 1; break; |
|
case 1: nd_isrlex = 0; nd_degcompat = 1; break; |
|
default: error("nd_gr : unsupported order"); |
|
} |
|
for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
ptod(CO,vv,(P)BDY(t),&c); |
ptod(CO,vv,(P)BDY(t),&c); |
if ( c ) { |
if ( c ) { |
Line 2197 void nd_gr_trace(LIST f,LIST v,int m,int homo,struct o |
|
Line 2166 void nd_gr_trace(LIST f,LIST v,int m,int homo,struct o |
|
} |
} |
if ( fd0 ) NEXT(fd) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
in0 = fd0; |
in0 = fd0; |
|
nd_init_ord(ord); |
} |
} |
do { |
do { |
nd_setup_trace(m,fd0); |
nd_setup_trace(m,fd0); |