📄 btc_atm_unix.cpp
字号:
arrayvalue[l] = (int)fmod(value,2);
value = value/2;
}
value = 0;
for(l=RM_N-1-i; l >= 1; l--)
{
if (arrayvalue[l]==1)
value += (int) pow(2,RM_N-1-i-l);
}
}
else
{
int idtemp[RM_N];
for(int p=0; p < RM_N; p++)
idtemp[p] = -1;
fillid(id[branch[numbranch].getOriginalnode()],idtemp,s,1);
value = findstate(idtemp,RM_N-i-1);
}
for(m = 0; m < 2*pow(2,statecomplex[i]); m++)
{
int temp;
temp = branch[startbranchindex[i]+m].getDestination();
if(value == temp)
{
branch[numbranch].setDestinationnode(branch[startbranchindex[i]+m].getDestinationnode());
branch[numbranch].setBit(branch[startbranchindex[i]+m].getBit()*-1);
found = 'y';
break;
}
else
{
found = 'n';
}
} // loop m
if(found == 'n')
{
branch[numbranch].setDestinationnode(startnodeindex[i+1]+n);
if(j==0)
{
fillid(id[branch[numbranch].getOriginalnode()],id[branch[numbranch].getDestinationnode()],s,-1);
}
else
{
fillid(id[branch[numbranch].getOriginalnode()],id[branch[numbranch].getDestinationnode()],s,1);
}
branch[numbranch].setDestination(findstate(id[startnodeindex[i+1]+n],RM_N-i-1));
branch[numbranch].setBit(findbit(i,branch[numbranch].getOriginal(),id[startnodeindex[i+1]+n]));
node[startnodeindex[i+1]+n].setStage(branch[numbranch].getDestination());
n++;
}// if(found == 'n')
numbranch++;
} //loop j
nodenum++;
} // from else statement of k
}// loop k
}
else
{
int n=0;
for(k=0; k < pow(2,statecomplex[i]); k++)
{
branch[numbranch].setOriginaltime(i);
branch[numbranch].setOriginal(findstate(id[nodenum],RM_N-i));
branch[numbranch].setOriginalnode(nodenum);
if(k==0)
{
branch[numbranch].setDestinationnode(startnodeindex[i+1]+k);
fillid(id[branch[numbranch].getOriginalnode()],id[branch[numbranch].getDestinationnode()],s,-1);
branch[numbranch].setDestination(findstate(id[startnodeindex[i+1]+k],RM_N-i-1));
branch[numbranch].setBit(findbit(i,branch[numbranch].getOriginal(),id[startnodeindex[i+1]+k]));
node[startnodeindex[i+1]+k].setStage(branch[numbranch].getDestination());
n++;
}
else
{
int value,l,m, arrayvalue[RM_N];
char found;
value = branch[numbranch].getOriginal();
for(l=RM_N-i-1; l >= 0; l--)
{
arrayvalue[l] = (int)fmod(value,2);
value = value/2;
}
value = 0;
for(l=RM_N-1-i; l >= 1; l--)
{
if (arrayvalue[l]==1)
value += (int) pow(2,RM_N-1-i-l);
}
for(m = 0; m < pow(2,statecomplex[i]); m++)
{
int temp;
temp = branch[startbranchindex[i]+m].getDestination();
if(value == temp)
{
branch[numbranch].setDestination(temp);
branch[numbranch].setDestinationnode(branch[startbranchindex[i]+m].getDestinationnode());
branch[numbranch].setBit(branch[startbranchindex[i]+m].getBit()*-1);
found = 'y';
break;
}
else
{
found = 'n';
}
}
if(found == 'n')
{
branch[numbranch].setDestinationnode(startnodeindex[i+1]+n);
fillid(id[branch[numbranch].getOriginalnode()],id[branch[numbranch].getDestinationnode()],s,-1);
branch[numbranch].setDestination(findstate(id[startnodeindex[i+1]+n],RM_N-i-1));
branch[numbranch].setBit(findbit(i,branch[numbranch].getOriginal(),id[startnodeindex[i+1]+n]));
node[startnodeindex[i+1]+n].setStage(branch[numbranch].getDestination());
n++;
}
}
// }
numbranch++;
nodenum++;
}
}
}
lastbranch = numbranch;
lastnode = nodenum+1;
}
void newAddXYtoX(int *X,int *Y,int leng)
{
int i;
int temp[RM_N];
for(i=0; i < leng; i++)
temp[i] = X[i];
for(i = RM_N-leng; i < RM_N; i++)
{
X[i-(RM_N-leng)] = temp[i-(RM_N-leng)]^Y[i];
}
}
int findstate(int *index,int length)
{
int i,j;
int Temp[length];
int result=0;
if(index[0] == -2)
{
for(i=0; i < length; i++)
Temp[i] = 0;
}
else if (index[0] >= 0)
{
for(i=0; i < length; i++)
Temp[i] = Gx[index[0]][i];
}
for(i=0; i < RM_K; i++)
{
if(index[i+1] == -1)
break;
else if(index[i+1] >= 0)
{
newAddXYtoX(Temp,Gx[index[i+1]],length);
}
}
for(i=length-1; i >= 0; i--)
{
if (Temp[i]==1)
result += (int) pow(2,length-1-i);
}
return result;
}
void fillid(int *in,int *out,int s,int a)
{
int i,j;
int num=0;
for(i=0; i < RM_N; i++)
{
if(in[i] == -1)
break;
else
{
out[num] = in[i];
num++;
}
}
if(a == 1)
out[num] = s;
}
int findbit(int originaltime,int original,int *index)
{
int i,j;
int arraytemp[RM_N];
int temp;
int Temp[RM_N];
temp = original;
for(i=RM_N-originaltime-1; i >= 0; i--)
{
arraytemp[i] = (int)fmod(temp,2);
temp = temp/2;
}
if(index[1] == -1)
{
return arraytemp[0]*2-1;
}
else
{
if(index[0] == -2)
{
for(i=0; i < RM_N-originaltime+1; i++)
Temp[i] = 0;
}
else if(index[0] >= 0)
{
for(i=0; i < RM_N-originaltime+1; i++)
Temp[i] = Gx[index[0]][i];
}
for(i=0; i < RM_K; i++)
{
if(index[i+1] == -1 )
break;
else if(index[i+1] >= 0)
{
newAddXYtoX(Temp,Gx[index[i+1]],RM_N-originaltime);
}
}
return Temp[0]*2-1;
}
}
void Softout(double *Rx,double Lc, double *Le_in, double *soft_out,int tag)
{
int i,j,k;
double Lx_y[RM_N];
double Le_out[RM_N];
int head,tail;
int codebit,numbranch,numnode;
for(i=0; i < RM_K; i++)
Lx_y[Left[i]] = Lc*Rx[Left[i]] + Le_in[i];
for(i=0; i < RM_N-RM_K; i++)
Lx_y[Parity[i]] = Lc*Rx[Parity[i]];
if(tag == 1)
{
for(i=RM_N-1; i>= RM_N; i--)
Lx_y[Parity[i-RM_K]] = Rx[Parity[i-RM_K]];
}
// intialize the matric;
node[0].setForwardmatric(1.0);
node[lastnode-1].setBackwardmatric(1.0);
for(i=1; i<lastnode-1; i++)
{
node[i].setForwardmatric(0.0); // dummy value
node[i].setBackwardmatric(0.0);
}
double temp = 0;
double testLxy;
int testgetbit;
double testgetvalue;
for(i=0; i < lastbranch; i++)
{
head = branch[i].getOriginalnode();
tail = branch[i].getDestinationnode();
temp = node[head].getForwardmatric()* exp(0.5*Lx_y[branch[i].getOriginaltime()]*branch[i].getBit());
node[tail].setForwardmatric(temp+node[tail].getForwardmatric());
}
temp = 0;
for(i=lastbranch-1; i >= 0; i--)
{
tail = branch[i].getOriginalnode();
head = branch[i].getDestinationnode();
temp = node[head].getBackwardmatric()*exp(0.5*Lx_y[branch[i].getOriginaltime()]*branch[i].getBit());
node[tail].setBackwardmatric(temp+node[tail].getBackwardmatric());
}
double forplus,forminus;
int messgindex;
temp = 0;
numbranch =0;
numnode =0;
for(messgindex=0; messgindex < RM_N; messgindex++)
{
if(messgindex < RM_K)
i = Left[messgindex];
else
i = Parity[messgindex-RM_K];
forplus = forminus = 0;
numbranch = startbranchindex[i];
if(statecomplex[i] <= statecomplex[i+1])
{
for(k=0; k < pow(2,statecomplex[i]); k++)
{
for(j=0; j < 2; j++)
{
if( branch[numbranch].getBit()==1)
{
temp = node[branch[numbranch].getOriginalnode()].getForwardmatric()*
node[branch[numbranch].getDestinationnode()].getBackwardmatric();
forplus += temp;
}
else
{
temp = node[branch[numbranch].getOriginalnode()].getForwardmatric()*
node[branch[numbranch].getDestinationnode()].getBackwardmatric();
forminus += temp;
}
numbranch++;
}//loop j
} // loop k
Le_out[messgindex] = log(forplus/forminus);
}//if statecomplex
else
{
for(k=0; k < pow(2,statecomplex[i]); k++)
{
if( branch[numbranch].getBit()==1)
{
temp = node[branch[numbranch].getOriginalnode()].getForwardmatric()*
node[branch[numbranch].getDestinationnode()].getBackwardmatric();
forplus += temp;
}
else
{
temp = node[branch[numbranch].getOriginalnode()].getForwardmatric()*
node[branch[numbranch].getDestinationnode()].getBackwardmatric();
forminus += temp;
}
numbranch++;
}
Le_out[messgindex] = log(forplus/forminus);
}
}//loop i
for(i=0; i < RM_N; i++)
soft_out[i] = Le_out[i];
}
double callogone(double in1,double in2)
{
int i,j;
double temp1,temp2,temp3;
temp1 = exp(in1);
temp2 = exp(in2);
temp3 = (temp1+temp2)/((1+temp1)*(1+temp2));
return(temp3);
}
double callogzero(double in1,double in2)
{
int i,j;
double temp1,temp2,temp3;
temp1 = exp(in1);
temp2 = exp(in2);
temp3 = ((temp1*temp2)+1)/((1+temp1)*(1+temp2));
return(temp3);
}
double algebra(double in1,double in2)
{
double temp1,temp2,temp3;
temp1 = exp(in1);
temp2 = exp(in2);
temp3 = (temp1+temp2)/(1+(temp1*temp2));
return(log(temp3));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -