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

📄 cpp1.cpp

📁 博弈论自适应功率控制中的实现
💻 CPP
字号:
#include <iostream.h>
#include <fstream.h>
#include "DSSS_ad_hoc.h"
#include <stdlib.h>
#include <stdio.h>

void main(void)
{
	int num_ad_hoc;
	int k,m;
	int num_iterations;
	char file_name[200];
	int temp_id;

	Infdneg = -exp(2004.0);
	DSSS_ad_hoc *DSSS_ad_hoc_stack;
	//DSSS_ad_hoc DSSS_ad_hoc_stack[10];
	ifstream fin;
	ofstream fout;

	//Initialization
	sprintf(file_name,"DSSS_data.txt");
	num_ad_hoc = 10;
	fin.open(file_name);
	fin >> num_ad_hoc;
	fin >> num_iterations;
	fin >> channel_d0;
	fin >> channel_exponent;	
	
	DSSS_ad_hoc_stack = new DSSS_ad_hoc[num_ad_hoc];
	//read in gunk
	for(k=0;k<num_ad_hoc;k++)
	{		
		fin >> DSSS_ad_hoc_stack[k];
	};	
	fin.close();

	//let all the radios see each other
	for(k=0;k<num_ad_hoc;k++)
	{
		for(m=0; m<num_ad_hoc; m++)
		{
			if(k!=m) // not itself
			{
				DSSS_ad_hoc_stack[k].hook_radio(&DSSS_ad_hoc_stack[m]); //place in reception
			}
		}
	}

	//set nodes of interest, allocate space
	for(k=0;k<num_ad_hoc;k++)
	{
		temp_id = DSSS_ad_hoc_stack[k].get_node_of_interest_id();
		DSSS_ad_hoc_stack[k].set_node_of_interest(&DSSS_ad_hoc_stack[temp_id]);
		DSSS_ad_hoc_stack[k].allocate_space(num_iterations);
	}

	//main loop
	for(k =0; k < num_iterations; k++)
	{
		//update incident powers
		for(m=0; m<num_ad_hoc; m++)
		{
			DSSS_ad_hoc_stack[m].update_incident_power();
		}

		//update transmit powers
		for(m=0; m<num_ad_hoc; m++)
		{
			DSSS_ad_hoc_stack[m].update_decision();
		}

		//update transmit powers
		for(m=0; m<num_ad_hoc; m++)
		{
			DSSS_ad_hoc_stack[m].update_stats();
		}
	}

	//Post processing
	fout.open("sim_result.txt");
	for(k=0;k<num_ad_hoc;k++)
	{
		fout << DSSS_ad_hoc_stack[k];
	}

	fout.close();
};

⌨️ 快捷键说明

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