-
Notifications
You must be signed in to change notification settings - Fork 1
/
distance.c
60 lines (59 loc) · 1.67 KB
/
distance.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
57
58
59
60
#include "ext.h"
#include "zerorange.h"
real dotproduct(real a1[], real a2[], real b1[],real b2[]){
int i;
real temp=0;
for(i=0;i<Dimension;i++){
temp+=(a2[i]-a1[i])*(b2[i]-b1[i]);
}
return(temp);
}
real singleslicedistance(real x0[],real x1[]){
int k;
real temp=0;
for(k=0;k<Dimension;k++){
temp+=pow2((x1[k]-x0[k]));
}
return(sqrt(temp));
}
//calculate a distancetable as well as the permutestatus.
int distanceinitialize(real x[][MAXN][MAXDIMEN])
{
//initialie distance table
int i,j,k;
for(i=0;i<ParticleNumber;i++)
for(j=i+1;j<ParticleNumber;j++)
for(k=0;k<=N;k++)//remeber to keep the last node
distancetable[i][j][k]=singleslicedistance(x[i][k],x[j][k]);
//calculate the permute status, i.e., the sign of the path
int ii,jj,l,m;
real old,tempd,ratio=1;
for(i=0;i<N;i++){
old=0;
for(ii=0;ii<permute1;ii++){
for(jj=0;jj<permute2;jj++){
tempd=1;
//each term needs the single particle terms and pair terms
//single particle term species 1
for(l=0;l<identity[0];l++){
tempd*=trapdensitymatrix(x[l][i],x[permutetable[ii][l]][i+1],epsilon);
}
//single particle term species 2
for(l=identity[0];l<ParticleNumber;l++){
tempd*=trapdensitymatrix(x[l][i],x[permutetable[jj][l]][i+1],epsilon);
}
//pair terms
for(l=0;l<identity[0];l++){
for(m=identity[0];m<ParticleNumber;m++){
tempd*=zerorangepairlink4(
x[l][i],x[m][i],x[permutetable[ii][l]][i+1],x[permutetable[jj][m]][i+1]);
}
}
old+=tempd*sig1[ii]*sig2[jj];
}
}
ratio*=old;
}
permutestatus=ratio>=0?0:1;
return(1);
}