version 1.229, 2016/11/17 05:33:20 |
version 1.231, 2016/12/05 10:29:14 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.228 2016/08/08 07:18:10 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.230 2016/12/02 02:12:00 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
Line 64 static int nd_gentrace,nd_gensyz,nd_nora,nd_newelim,nd |
|
Line 64 static int nd_gentrace,nd_gensyz,nd_nora,nd_newelim,nd |
|
static int *nd_gbblock; |
static int *nd_gbblock; |
static NODE nd_nzlist,nd_check_splist; |
static NODE nd_nzlist,nd_check_splist; |
static int nd_splist; |
static int nd_splist; |
|
static int *nd_sugarweight; |
|
|
NumberField get_numberfield(); |
NumberField get_numberfield(); |
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
Line 173 INLINE int nd_length(ND p) |
|
Line 174 INLINE int nd_length(ND p) |
|
} |
} |
} |
} |
|
|
|
extern int dp_negative_weight; |
|
|
INLINE int ndl_reducible(UINT *d1,UINT *d2) |
INLINE int ndl_reducible(UINT *d1,UINT *d2) |
{ |
{ |
UINT u1,u2; |
UINT u1,u2; |
Line 180 INLINE int ndl_reducible(UINT *d1,UINT *d2) |
|
Line 183 INLINE int ndl_reducible(UINT *d1,UINT *d2) |
|
|
|
if ( nd_module && (MPOS(d1) != MPOS(d2)) ) return 0; |
if ( nd_module && (MPOS(d1) != MPOS(d2)) ) return 0; |
|
|
if ( TD(d1) < TD(d2) ) return 0; |
if ( !dp_negative_weight && TD(d1) < TD(d2) ) return 0; |
#if USE_UNROLL |
#if USE_UNROLL |
switch ( nd_bpe ) { |
switch ( nd_bpe ) { |
case 3: |
case 3: |
Line 459 int ndl_weight(UINT *d) |
|
Line 462 int ndl_weight(UINT *d) |
|
return t; |
return t; |
} |
} |
|
|
|
/* for sugarweight */ |
|
|
|
int ndl_weight2(UINT *d) |
|
{ |
|
int t,u; |
|
int i,j; |
|
|
|
for ( i = 0, t = 0; i < nd_nvar; i++ ) { |
|
u = GET_EXP(d,i); |
|
t += nd_sugarweight[i]*u; |
|
} |
|
if ( nd_module && current_module_weight_vector && MPOS(d) ) |
|
t += current_module_weight_vector[MPOS(d)]; |
|
return t; |
|
} |
|
|
void ndl_weight_mask(UINT *d) |
void ndl_weight_mask(UINT *d) |
{ |
{ |
UINT t,u; |
UINT t,u; |
Line 2532 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 2551 ND_pairs nd_newpairs( NODE g, int t ) |
|
ndl_lcm(DL(nd_psh[r->i1]),dl,r->lcm); |
ndl_lcm(DL(nd_psh[r->i1]),dl,r->lcm); |
s = SG(nd_psh[r->i1])-TD(DL(nd_psh[r->i1])); |
s = SG(nd_psh[r->i1])-TD(DL(nd_psh[r->i1])); |
SG(r) = MAX(s,ts) + TD(LCM(r)); |
SG(r) = MAX(s,ts) + TD(LCM(r)); |
|
/* experimental */ |
|
if ( nd_sugarweight ) |
|
r->sugar2 = ndl_weight2(r->lcm); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
return r0; |
return r0; |
} |
} |
|
|
|
/* ipair = [i1,i2],[i1,i2],... */ |
|
ND_pairs nd_ipairtospair(NODE ipair) |
|
{ |
|
int s1,s2; |
|
NODE tn,t; |
|
ND_pairs r,r0; |
|
|
|
for ( r0 = 0, t = ipair; t; t = NEXT(t) ) { |
|
NEXTND_pairs(r0,r); |
|
tn = BDY((LIST)BDY(t)); |
|
r->i1 = QTOS((Q)ARG0(tn)); |
|
r->i2 = QTOS((Q)ARG1(tn)); |
|
ndl_lcm(DL(nd_psh[r->i1]),DL(nd_psh[r->i2]),r->lcm); |
|
s1 = SG(nd_psh[r->i1])-TD(DL(nd_psh[r->i1])); |
|
s2 = SG(nd_psh[r->i2])-TD(DL(nd_psh[r->i2])); |
|
SG(r) = MAX(s1,s2) + TD(LCM(r)); |
|
/* experimental */ |
|
if ( nd_sugarweight ) |
|
r->sugar2 = ndl_weight2(r->lcm); |
|
} |
|
if ( r0 ) NEXT(r) = 0; |
|
return r0; |
|
} |
|
|
/* kokokara */ |
/* kokokara */ |
|
|
ND_pairs crit_B( ND_pairs d, int s ) |
ND_pairs crit_B( ND_pairs d, int s ) |
Line 2717 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 2763 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
NEXT(m) = 0; |
NEXT(m) = 0; |
return m; |
return m; |
} |
} |
s = SG(m); |
|
if ( !NoSugar ) { |
if ( !NoSugar ) { |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) |
if ( nd_sugarweight ) { |
if ( (SG(p) < s) |
s = m->sugar2; |
|| ((SG(p) == s) && (DL_COMPARE(LCM(p),LCM(m)) < 0)) ) { |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) |
ml = l; m = p; s = SG(m); |
if ( (p->sugar2 < s) |
} |
|| ((p->sugar2 == s) && (DL_COMPARE(LCM(p),LCM(m)) < 0)) ) { |
|
ml = l; m = p; s = m->sugar2; |
|
} |
|
} else { |
|
s = SG(m); |
|
for ( ml = 0, l = m; p; p = NEXT(l = p) ) |
|
if ( (SG(p) < s) |
|
|| ((SG(p) == s) && (DL_COMPARE(LCM(p),LCM(m)) < 0)) ) { |
|
ml = l; m = p; s = SG(m); |
|
} |
|
} |
} else { |
} else { |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) |
if ( DL_COMPARE(LCM(p),LCM(m)) < 0 ) { |
if ( DL_COMPARE(LCM(p),LCM(m)) < 0 ) { |
Line 2744 ND_pairs nd_minsugarp( ND_pairs d, ND_pairs *prest ) |
|
Line 2799 ND_pairs nd_minsugarp( ND_pairs d, ND_pairs *prest ) |
|
int msugar,i; |
int msugar,i; |
ND_pairs t,dm0,dm,dr0,dr; |
ND_pairs t,dm0,dm,dr0,dr; |
|
|
for ( msugar = SG(d), t = NEXT(d); t; t = NEXT(t) ) |
if ( nd_sugarweight ) { |
if ( SG(t) < msugar ) msugar = SG(t); |
for ( msugar = d->sugar2, t = NEXT(d); t; t = NEXT(t) ) |
dm0 = 0; dr0 = 0; |
if ( t->sugar2 < msugar ) msugar = t->sugar2; |
for ( i = 0, t = d; t; t = NEXT(t) ) |
dm0 = 0; dr0 = 0; |
if ( i < nd_f4_nsp && SG(t) == msugar ) { |
for ( i = 0, t = d; t; t = NEXT(t) ) |
if ( dm0 ) NEXT(dm) = t; |
if ( i < nd_f4_nsp && t->sugar2 == msugar ) { |
else dm0 = t; |
if ( dm0 ) NEXT(dm) = t; |
dm = t; |
else dm0 = t; |
i++; |
dm = t; |
} else { |
i++; |
if ( dr0 ) NEXT(dr) = t; |
} else { |
else dr0 = t; |
if ( dr0 ) NEXT(dr) = t; |
dr = t; |
else dr0 = t; |
} |
dr = t; |
|
} |
|
} else { |
|
for ( msugar = SG(d), t = NEXT(d); t; t = NEXT(t) ) |
|
if ( SG(t) < msugar ) msugar = SG(t); |
|
dm0 = 0; dr0 = 0; |
|
for ( i = 0, t = d; t; t = NEXT(t) ) |
|
if ( i < nd_f4_nsp && SG(t) == msugar ) { |
|
if ( dm0 ) NEXT(dm) = t; |
|
else dm0 = t; |
|
dm = t; |
|
i++; |
|
} else { |
|
if ( dr0 ) NEXT(dr) = t; |
|
else dr0 = t; |
|
dr = t; |
|
} |
|
} |
NEXT(dm) = 0; |
NEXT(dm) = 0; |
if ( dr0 ) NEXT(dr) = 0; |
if ( dr0 ) NEXT(dr) = 0; |
*prest = dr0; |
*prest = dr0; |
Line 6182 NODE nd_f4(int m,int **indp) |
|
Line 6254 NODE nd_f4(int m,int **indp) |
|
ND spol,red; |
ND spol,red; |
NDV nf,redv; |
NDV nf,redv; |
NM s0,s; |
NM s0,s; |
NODE rp0,srp0,nflist,nzlist; |
NODE rp0,srp0,nflist,nzlist,nzlist_t; |
int nsp,nred,col,rank,len,k,j,a,i1s,i2s; |
int nsp,nred,col,rank,len,k,j,a,i1s,i2s; |
UINT c; |
UINT c; |
UINT **spmat; |
UINT **spmat; |
Line 6200 NODE nd_f4(int m,int **indp) |
|
Line 6272 NODE nd_f4(int m,int **indp) |
|
#endif |
#endif |
g = 0; d = 0; |
g = 0; d = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
d = update_pairs(d,g,i,0); |
if ( !nd_nzlist ) d = update_pairs(d,g,i,0); |
g = update_base(g,i); |
g = update_base(g,i); |
} |
} |
nzlist = 0; |
nzlist = 0; |
while ( d ) { |
nzlist_t = nd_nzlist; |
|
while ( d || nzlist_t ) { |
get_eg(&eg0); |
get_eg(&eg0); |
l = nd_minsugarp(d,&d); |
|
sugar = SG(l); |
|
if ( MaxDeg > 0 && sugar > MaxDeg ) break; |
|
if ( nd_nzlist ) { |
if ( nd_nzlist ) { |
for ( tn = nd_nzlist; tn; tn = NEXT(tn) ) { |
node = BDY((LIST)BDY(nzlist_t)); |
node = BDY((LIST)BDY(tn)); |
sugar = ARG0(node); |
if ( QTOS((Q)ARG0(node)) == sugar ) break; |
tn = BDY((LIST)ARG1(node)); |
|
if ( !tn ) { |
|
nzlist_t = NEXT(nzlist_t); |
|
continue; |
} |
} |
if ( tn ) { |
/* tn = [[i1,i2],...] */ |
for ( t = l, ll0 = 0; t; t = NEXT(t) ) { |
l = nd_ipairtospair(tn); |
for ( tn = BDY((LIST)ARG1(node)); tn; tn = NEXT(tn) ) { |
} else { |
i1s = QTOS((Q)ARG0(BDY((LIST)BDY(tn)))); |
l = nd_minsugarp(d,&d); |
i2s = QTOS((Q)ARG1(BDY((LIST)BDY(tn)))); |
sugar = nd_sugarweight?l->sugar2:SG(l); |
if ( t->i1 == i1s && t->i2 == i2s ) break; |
if ( MaxDeg > 0 && sugar > MaxDeg ) break; |
} |
|
if ( tn ) { |
|
if ( !ll0 ) ll0 = t; |
|
else NEXT(ll) = t; |
|
ll = t; |
|
} |
|
} |
|
if ( ll0 ) NEXT(ll) = 0; |
|
l = ll0; |
|
} else l = 0; |
|
} |
} |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
stat = nd_sp_f4(m,0,l,bucket); |
stat = nd_sp_f4(m,0,l,bucket); |
if ( !stat ) { |
if ( !stat ) { |
for ( t = l; NEXT(t); t = NEXT(t) ); |
if ( !nd_nzlist ) { |
NEXT(t) = d; d = l; |
for ( t = l; NEXT(t); t = NEXT(t) ); |
d = nd_reconstruct(0,d); |
NEXT(t) = d; d = l; |
|
d = nd_reconstruct(0,d); |
|
} |
continue; |
continue; |
} |
} |
if ( bucket->m < 0 ) continue; |
if ( bucket->m < 0 ) continue; |
Line 6265 NODE nd_f4(int m,int **indp) |
|
Line 6330 NODE nd_f4(int m,int **indp) |
|
nf = ndtondv(m,nf1); |
nf = ndtondv(m,nf1); |
} |
} |
nh = ndv_newps(m,nf,0,1); |
nh = ndv_newps(m,nf,0,1); |
d = update_pairs(d,g,nh,0); |
if ( !nd_nzlist ) d = update_pairs(d,g,nh,0); |
g = update_base(g,nh); |
g = update_base(g,nh); |
} |
} |
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
Line 6279 NODE nd_f4(int m,int **indp) |
|
Line 6344 NODE nd_f4(int m,int **indp) |
|
STOQ(sugar,sugarq); node = mknode(2,sugarq,l0); MKLIST(l1,node); |
STOQ(sugar,sugarq); node = mknode(2,sugarq,l0); MKLIST(l1,node); |
MKNODE(node,l1,nzlist); nzlist = node; |
MKNODE(node,l1,nzlist); nzlist = node; |
} |
} |
|
if ( nd_nzlist ) nzlist_t = NEXT(nzlist_t); |
} |
} |
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
MKLIST(l0,reverse_node(nzlist)); |
MKLIST(l0,reverse_node(nzlist)); |
Line 8060 void conv_ilist(int demand,int trace,NODE g,int **indp |
|
Line 8126 void conv_ilist(int demand,int trace,NODE g,int **indp |
|
void parse_nd_option(NODE opt) |
void parse_nd_option(NODE opt) |
{ |
{ |
NODE t,p,u; |
NODE t,p,u; |
int i,s; |
int i,s,n; |
char *key; |
char *key; |
Obj value; |
Obj value; |
|
|
nd_gentrace = 0; nd_gensyz = 0; nd_nora = 0; nd_gbblock = 0; |
nd_gentrace = 0; nd_gensyz = 0; nd_nora = 0; nd_gbblock = 0; |
nd_newelim = 0; nd_intersect = 0; nd_nzlist = 0; |
nd_newelim = 0; nd_intersect = 0; nd_nzlist = 0; |
nd_splist = 0; nd_check_splist = 0; |
nd_splist = 0; nd_check_splist = 0; |
|
nd_sugarweight = 0; |
|
|
for ( t = opt; t; t = NEXT(t) ) { |
for ( t = opt; t; t = NEXT(t) ) { |
p = BDY((LIST)BDY(t)); |
p = BDY((LIST)BDY(t)); |
key = BDY((STRING)BDY(p)); |
key = BDY((STRING)BDY(p)); |
Line 8100 void parse_nd_option(NODE opt) |
|
Line 8168 void parse_nd_option(NODE opt) |
|
nd_splist = value?1:0; |
nd_splist = value?1:0; |
else if ( !strcmp(key,"check_splist") ) { |
else if ( !strcmp(key,"check_splist") ) { |
nd_check_splist = BDY((LIST)value); |
nd_check_splist = BDY((LIST)value); |
|
} else if ( !strcmp(key,"sugarweight") ) { |
|
nd_sugarweight = BDY((LIST)value); |
|
u = BDY((LIST)value); |
|
n = length(u); |
|
nd_sugarweight = MALLOC(n*sizeof(int)); |
|
for ( i = 0; i < n; i++, u = NEXT(u) ) |
|
nd_sugarweight[i] = QTOS((Q)BDY(u)); |
} |
} |
} |
} |
} |
} |