⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minimumsum.cpp

📁 这个是数据打孔重传程序的源代码
💻 CPP
字号:
#include "parameter_sets.h"

const double MAX = 1.7E+308;

int MinSumF(struct BasicParaS * ctrl, double * c) {

	int iter, i, sum, flag;
	struct LinkNode * currentNode, * iterNode;
	int M = ctrl->numChk;
	int N = ctrl->numVar;
	double temp0, temp1;
	int * varbits = new int[N];
	double * c1 = new double[N];

	// Iterate to flood the message throughout the whole graph
	for (iter = 0; iter<ctrl->maxIter; iter++) {
#ifdef DEBUG
		printf("Iterate to decode .. %d\n", iter);
#endif		
		// Horizontal step, for each check node
		for (i=0; i<M; i++) {
			currentNode = *(ctrl->rowLink+i);
			// Update Rji message for each variable node
			while (currentNode != NULL) {
				// Calculate the Rji for the current variable node
				temp0 = 1; // calc sign
				temp1 = MAX; // calc abs
				iterNode = *(ctrl->rowLink+i); // iter from the first node in the same row
				while (iterNode != NULL) {
					if (iterNode != currentNode) {
						if (iterNode->qMsg[0] < 0)
							temp0 *= -1;
						if (fabs(iterNode->qMsg[0]) < temp1)
							temp1 = fabs(iterNode->qMsg[0]);
					}
					iterNode = iterNode->rowPtr; // move to the next node in the same row
				}
				currentNode->rMsg[0] = temp0*temp1; // update the r0 message
				currentNode->rMsg[1] = 0; // update the r1 message
				currentNode = currentNode->rowPtr; // move to the next node in the same row
			}
		}

		// Vertical step, for each variable node
		for (i=0; i<N; i++) {
			currentNode = *(ctrl->colLink+i);
			// Update Qij message for each check node
			while (currentNode != NULL) {
				// Calculate the Qij for the current check node
				temp0 = *(c+i);
				iterNode = *(ctrl->colLink+i); // iter from the first node in the same col
				while (iterNode != NULL) {
					if (iterNode != currentNode) {
						temp0 += iterNode->rMsg[0];
					}
					iterNode = iterNode->colPtr; // move to the next node in the same col
				}
				currentNode->qMsg[0] = temp0; // update the q0 message
				currentNode->qMsg[1] = 0;
				currentNode = currentNode->colPtr; // move to the next node in the same col
			}
		}

		// Calculte the Q for each variable node and Decision
		for (i=0; i<N; i++) {
			temp0 = *(c+i);
			iterNode = *(ctrl->colLink+i);
			while (iterNode != NULL) {
				temp0 += iterNode->rMsg[0];
				iterNode = iterNode->colPtr; // move to the next node in the same col
			}
			*(c1+i) = temp0;
			if (temp0 > 0) {
				*(varbits+i) = 0;
			} else {
				*(varbits+i) = 1;
			}
		}

		// Check whether the current output is currect
		flag = 0;
		for (i=0; i<M; i++) {
			sum = 0;
			iterNode = *(ctrl->rowLink+i);
			while (iterNode != NULL) {
				sum += *(varbits+iterNode->colIdx);
				sum %= 2;
				iterNode = iterNode->rowPtr;
			}
			if (sum != 0)
				flag++;
		}
		if (flag == 0)
		{
			ctrl->numIter += (iter+1); 
			break;
		}
	}

	for (i=0; i<N; i++)
	{
		*(c+i) = * (c1+i);
	}

//	for (i=0; i<ctrl->numInBits; i++) {
//		*(output+i) = *(varbits+i);
//	}

#ifdef DEBUG
		iter = 0;
		printf("The output of decoding are ..\n");
		for (i=0; i<N; i++) {
			printf(" %d", *(varbits+i));
			iter++;
			if (iter == 24) {
				iter = 0;
				printf("\n");
			}
		}
#endif


	delete [] varbits;

	if (flag == 0) 
		return 0;
	else
	{
		ctrl->numIter += ctrl->maxIter;
		return 1;
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -