-
Notifications
You must be signed in to change notification settings - Fork 10
/
soft_maxdimz.c
57 lines (54 loc) · 1.48 KB
/
soft_maxdimz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include"utils.h"
#include"matrix_ops.h"
void find_maxz(double *vlist,int nvert, double *maxz,int *maxv)
{
double maxzval=-1e6;
double maxzind=-1;
for(int j=0;j<nvert;j++)
if(maxzval<vlist[3*j+2])
{
maxzval=vlist[3*j+2];
maxzind=j;
}
*maxz=maxzval;
*maxv=maxzind;
}
void find_minz(double *vlist,int nvert, double *minz,int *minv)
{
double minzval=1e6;
double minzind=-1;
for(int j=0;j<nvert;j++)
if(minzval>vlist[3*j+2])
{
minzval=vlist[3*j+2];
minzind=j;
}
*minz=minzval;
*minv=minzind;
}
void soft_maxdimz(int *tlist,double *vlist,int nfacn,int nvertn,double *D,int nvert,double zmax,double c,double *zm,double *dz)
{
/*
* Find whether z dimension of the polyhedron is larger than the zmax
* Calculate distance using the logistic function
* i
* OUTPUT:
* zm: distance
* dz: 1xnvert vector, only 2 entries are nonzero [if D is nvertnxnvert vector, otherwise dz is 1xnvertn vector]
*
*/
int minv,maxv;
double maxz,minz;
double *dzn=calloc(nvertn,sizeof(double));
find_maxz(vlist,nvertn,&maxz,&maxv);
find_minz(vlist,nvertn,&minz,&minv);
double zmv=(maxz-minz)-zmax;
*zm=1.0/(1.0+exp(-c*zmv));
dzn[maxv]=*zm*(1-*zm)*c;
dzn[minv]=-*zm*(1-*zm)*c;
if(D!=NULL)
matrix_prod(dzn,1,nvertn,D,nvert,dz);
else
memcpy(dz,dzn,sizeof(double)*nvertn);
free(dzn);
}