version 1.47, 2007/10/14 02:32:21 |
version 1.50, 2009/01/04 10:02:00 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/dp-supp.c,v 1.46 2007/09/19 05:42:59 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/dp-supp.c,v 1.49 2009/01/04 05:44:51 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 1683 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
Line 1683 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
struct order_pair *l; |
struct order_pair *l; |
NODE node,t,tn; |
NODE node,t,tn; |
MAT m; |
MAT m; |
pointer **b; |
VECT v; |
|
pointer **b,*bv; |
int **w; |
int **w; |
|
|
if ( vl && obj && OID(obj) == O_LIST ) { |
if ( vl && obj && OID(obj) == O_LIST ) { |
Line 1721 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
Line 1722 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
spec->nv = col; spec->ord.matrix.row = row; |
spec->nv = col; spec->ord.matrix.row = row; |
spec->ord.matrix.matrix = w; |
spec->ord.matrix.matrix = w; |
return 1; |
return 1; |
|
} else if ( OID(obj) == O_VECT ) { |
|
v = (VECT)obj; bv = BDY(v); |
|
if ( v->len < 2 ) error("create_order_spec : invalid argument"); |
|
create_order_spec(0,(Obj)bv[1],&spec); |
|
spec->id += 256; spec->obj = obj; |
|
spec->istop = bv[0]==0; |
|
*specp = spec; |
|
return 1; |
} else |
} else |
return 0; |
return 0; |
} |
} |
Line 2184 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2193 void homogenize_order(struct order_spec *old,int n,str |
|
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |
} |
} |
break; |
break; |
case 1: |
case 1: case 257: |
length = old->ord.block.length; |
length = old->ord.block.length; |
l = (struct order_pair *) |
l = (struct order_pair *) |
MALLOC_ATOMIC((length+1)*sizeof(struct order_pair)); |
MALLOC_ATOMIC((length+1)*sizeof(struct order_pair)); |
bcopy((char *)old->ord.block.order_pair,(char *)l,length*sizeof(struct order_pair)); |
bcopy((char *)old->ord.block.order_pair,(char *)l,length*sizeof(struct order_pair)); |
l[length].order = 2; l[length].length = 1; |
l[length].order = 2; l[length].length = 1; |
new->id = 1; new->nv = n+1; |
new->id = old->id; new->nv = n+1; |
new->ord.block.order_pair = l; |
new->ord.block.order_pair = l; |
new->ord.block.length = length+1; |
new->ord.block.length = length+1; |
|
new->istop = old->istop; |
break; |
break; |
case 2: |
case 2: case 258: |
nv = old->nv; row = old->ord.matrix.row; |
nv = old->nv; row = old->ord.matrix.row; |
oldm = old->ord.matrix.matrix; newm = almat(row+1,nv+1); |
oldm = old->ord.matrix.matrix; newm = almat(row+1,nv+1); |
for ( i = 0; i <= nv; i++ ) |
for ( i = 0; i <= nv; i++ ) |
Line 2204 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2214 void homogenize_order(struct order_spec *old,int n,str |
|
newm[i+1][j] = oldm[i][j]; |
newm[i+1][j] = oldm[i][j]; |
newm[i+1][j] = 0; |
newm[i+1][j] = 0; |
} |
} |
new->id = 2; new->nv = nv+1; |
new->id = old->id; new->nv = nv+1; |
new->ord.matrix.row = row+1; new->ord.matrix.matrix = newm; |
new->ord.matrix.row = row+1; new->ord.matrix.matrix = newm; |
|
new->istop = old->istop; |
break; |
break; |
case 3: |
case 3: case 259: |
onv = old->nv; |
onv = old->nv; |
nnv = onv+1; |
nnv = onv+1; |
olen = old->ord.composite.length; |
olen = old->ord.composite.length; |
Line 2241 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2252 void homogenize_order(struct order_spec *old,int n,str |
|
(struct sparse_weight *)MALLOC(sizeof(struct sparse_weight)); |
(struct sparse_weight *)MALLOC(sizeof(struct sparse_weight)); |
nwb[i].body.sparse_weight[0].pos = onv; |
nwb[i].body.sparse_weight[0].pos = onv; |
nwb[i].body.sparse_weight[0].value = 1; |
nwb[i].body.sparse_weight[0].value = 1; |
new->id = 3; |
new->id = old->id; |
new->nv = nnv; |
new->nv = nnv; |
new->ord.composite.length = nlen; |
new->ord.composite.length = nlen; |
new->ord.composite.w_or_b = nwb; |
new->ord.composite.w_or_b = nwb; |
|
new->istop = old->istop; |
print_composite_order_spec(new); |
print_composite_order_spec(new); |
break; |
break; |
|
case 256: /* simple module order */ |
|
switch ( old->ord.simple ) { |
|
case 0: |
|
new->id = 256; new->ord.simple = 0; break; |
|
case 1: |
|
l = (struct order_pair *) |
|
MALLOC_ATOMIC(2*sizeof(struct order_pair)); |
|
l[0].length = n; l[0].order = old->ord.simple; |
|
l[1].length = 1; l[1].order = 2; |
|
new->id = 257; |
|
new->ord.block.order_pair = l; |
|
new->ord.block.length = 2; new->nv = n+1; |
|
break; |
|
case 2: |
|
new->id = 256; new->ord.simple = 1; break; |
|
default: |
|
error("homogenize_order : invalid input"); |
|
} |
|
new->istop = old->istop; |
|
break; |
default: |
default: |
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |
} |
} |
Line 2726 int compare_facet_preorder(int n,int *u,int *v, |
|
Line 2758 int compare_facet_preorder(int n,int *u,int *v, |
|
else if ( t < 0 ) return 0; |
else if ( t < 0 ) return 0; |
} |
} |
return 1; |
return 1; |
|
} |
|
|
|
Q inner_product_with_small_vector(VECT w,int *v) |
|
{ |
|
int n,i; |
|
Q q,s,t,u; |
|
|
|
n = w->len; |
|
s = 0; |
|
for ( i = 0; i < n; i++ ) { |
|
STOQ(v[i],q); mulq((Q)w->body[i],q,&t); addq(t,s,&u); s = u; |
|
} |
|
return s; |
|
} |
|
|
|
Q compute_last_t(NODE g,NODE gh,Q t,VECT w1,VECT w2,NODE *homo,VECT *wp) |
|
{ |
|
int n,i; |
|
int *wt; |
|
Q last,d1,d2,dn,nm,s,t1; |
|
VECT wd,wt1,wt2,w; |
|
NODE tg,tgh; |
|
MP f; |
|
int *h; |
|
NODE r0,r; |
|
MP m0,m; |
|
DP d; |
|
|
|
n = w1->len; |
|
wt = W_ALLOC(n); |
|
last = ONE; |
|
/* t1 = 1-t */ |
|
for ( tg = g, tgh = gh; tg; tg = NEXT(tg), tgh = NEXT(tgh ) ) { |
|
f = BDY((DP)BDY(tg)); |
|
h = BDY((DP)BDY(tgh))->dl->d; |
|
for ( ; f; f = NEXT(f) ) { |
|
for ( i = 0; i < n; i++ ) wt[i] = h[i]-f->dl->d[i]; |
|
for ( i = 0; i < n && !wt[i]; i++ ); |
|
if ( i == n ) continue; |
|
d1 = inner_product_with_small_vector(w1,wt); |
|
d2 = inner_product_with_small_vector(w2,wt); |
|
nm = d1; subq(d1,d2,&dn); |
|
/* if d1=d2 then nothing happens */ |
|
if ( !dn ) continue; |
|
/* s satisfies ds = 0*/ |
|
divq(nm,dn,&s); |
|
|
|
if ( cmpq(s,t) > 0 && cmpq(s,last) < 0 ) |
|
last = s; |
|
else if ( !cmpq(s,t) ) { |
|
if ( cmpq(d2,0) < 0 ) { |
|
last = t; |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
if ( !last ) { |
|
dn = ONE; nm = 0; |
|
} else { |
|
NTOQ(NM(last),1,nm); |
|
if ( INT(last) ) dn = ONE; |
|
else { |
|
NTOQ(DN(last),1,dn); |
|
} |
|
} |
|
/* (1-n/d)*w1+n/d*w2 -> w=(d-n)*w1+n*w2 */ |
|
subq(dn,nm,&t1); mulvect(CO,(Obj)w1,(Obj)t1,(Obj *)&wt1); |
|
mulvect(CO,(Obj)w2,(Obj)nm,(Obj *)&wt2); addvect(CO,wt1,wt2,&w); |
|
|
|
r0 = 0; |
|
for ( tg = g, tgh = gh; tg; tg = NEXT(tg), tgh = NEXT(tgh ) ) { |
|
f = BDY((DP)BDY(tg)); |
|
h = BDY((DP)BDY(tgh))->dl->d; |
|
for ( m0 = 0; f; f = NEXT(f) ) { |
|
for ( i = 0; i < n; i++ ) wt[i] = h[i]-f->dl->d[i]; |
|
for ( i = 0; i < n && !wt[i]; i++ ); |
|
if ( !inner_product_with_small_vector(w,wt) ) { |
|
NEXTMP(m0,m); m->c = f->c; m->dl = f->dl; |
|
} |
|
} |
|
NEXT(m) = 0; |
|
MKDP(((DP)BDY(tg))->nv,m0,d); d->sugar = ((DP)BDY(tg))->sugar; |
|
NEXTNODE(r0,r); BDY(r) = (pointer)d; |
|
} |
|
NEXT(r) = 0; |
|
*homo = r0; |
|
*wp = w; |
|
return last; |
} |
} |
|
|
/* return 0 if last_w = infty */ |
/* return 0 if last_w = infty */ |