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

📄 main.cpp

📁 Bubble Oscillation Algorithm. It is used to implement balancing load traffic, which is similar to wh
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////
//  Title:        Geographic Load Balancing for Cellular Networks 
//		          by emulating the behavior of air bubbles 
//
//  Description:  This project is for dynamically balancing the traffic load 
//                  over a cellular network with fully adaptive antennas by 
//		    emulating the behaviours of a bubble array. Since 
//                  we assume fully adaptive base station antenna in this  
//                  version, antenna agent and simulator are not needed. 
//
//  Copyright:    Copyright (c) 2003
//  Company:      Elec. Eng. Dept., Queen Mary, University of London
//  @author       Lin Du (lin.du@elec.qmul.ac.uk)
//  @version      1.0
//
//////////////////////////////////////////////////////////////////////

//  Main file
//
//////////////////////////////////////////////////////////////////////

#include "main.h"

//  Main function
//
//////////////////////////////////////////////////////////////////////

//#define _TEST_    // flag for testing/tuning

#ifdef _TEST_
const static double TEST_STEP_0 = 10.0;
const static double TEST_STEP_1 = 10.0;
const static double TEST_STEP_2 = 10.0;
const static double TEST_STEP_3 = 10.0;

// For testing and tuning
void testing(int argc, char *argv[]) {
	int i = 1;
	double W0_MIN = 0.0061;
	double W0_MAX = 0.0062;
	double W1_MIN = 0.0005;
	double W1_MAX = 0.0009;
	double W2_MIN = 0.02;
	double W2_MAX = 0.04;

  for(double W0 = W0_MIN; W0 < W0_MAX; W0 += (W0_MAX-W0_MIN)/TEST_STEP_0) 
  {
    df->parameter.W0 = W0;
//    for(double W1 = W1_MIN; W1 < W1_MAX; W1 += (W1_MAX-W1_MIN)/TEST_STEP_1) 
    {
//			df->parameter.W1 = W1;
//			for(double W2 = W2_MIN; W2 < W2_MAX; W2 += (W2_MAX-W2_MIN)/TEST_STEP_2) 
			{
//				df->parameter.W2 = W2;
				mainFunc(argc, argv);
			}
//  		cout << endl;
    }
//		cout << endl;
  }
}

#endif

// display the usage
void usage(char *cmdName) {
  cout << "Usage:" << endl;
  cout << cmdName << " BS_Scenario_File MS_Scenario_File1 [MS_Scenario_File2 ...] [-recover]" << endl;
}

// The main functional procedure
void mainFunc(int argc, char *argv[]) 
{
  double capacity1, block1, share1[MAX_SHARE_NUM];
  double capacity3, block3, share3[MAX_SHARE_NUM];
  int scen_0, scen_n;

  // create the testbed
  tb = new TestBed(argv[1], ams, df);    // create tb with BS scenario file name

  // Check for recover mode
  if(strcmp(argv[argc-1], "-recover")) 
  {
    scen_0 = 2;
    scen_n = argc - 1;
		// pass the unstable states when the simulation just starting 
		tb->advanceSimTime(6000, true);    // (100 min)
  } 
  else 
  {
    scen_0 = ams->recover("rec_bub.dat");
    scen_n = argc - 2;
  }

  for (int i = scen_0; i <= scen_n; i++) 
  {
    // run MAS each 60 seconds
    tb->advanceSimTime( SNAPSHOT_INTERVAL, true );

		// Read TU scenario file
    tb->ReadMSScenario( argv[i] );

    // Run simultion (with assignment)
    tb->simulate(true); 
    capacity1 = tb->getSystemCapacity();
    block1 = tb->getBlockedNum();
    int n;
		for( n=0; n<MAX_SHARE_NUM; n++) 
			share1[n] = tb->getSharedNum(n);

#ifndef _TEST_
    // Do not write plot files when testing, in order to speed it up.
	  char buf[256];
    // Output result
//    sprintf(buf, "%s_cir_bub.plt", argv[i]);
//    tb->writeGPResult(buf);
//    sprintf(buf, "cir%sbub.m", argv[i]);
//    tb->writeMatlabResult(buf);
#endif

    // Run MAS optimisation and count the time
		struct _timeb time_buf;
		ftime(&time_buf);	// get current time
		double time1 = (double)time_buf.time + ((double)time_buf.millitm)/1000.0;
    int osc_num = ams->startMAS(argv[i]);
		ftime(&time_buf); // get current time
		double time2 = (double)time_buf.time + ((double)time_buf.millitm)/1000.0;

    // Run simultion again (no assignment) (no need now, coz we already ran it in MAS)
//    tb->simulate(false);
#ifndef _TEST_
    // Output result
    sprintf(buf, "%s_osc_bub.plt", argv[i]);
    tb->writeGPResult(buf);
    sprintf(buf, "osc%sbub.m", argv[i]);
//    tb->writeMatlabResult(buf);
#endif
    capacity3= tb->getSystemCapacity();
    block3= tb->getBlockedNum();
		for( n=0; n<MAX_SHARE_NUM; n++) 
			share3[n] = tb->getSharedNum(n);

    // Display the progress
#ifdef _TEST_
    cout << block3 << " ";
    break;
#else
		cout << argv[i] << " cap:";
    cout <<"c="<<capacity1<<" "<<share1[0]<<" "<<share1[1]<<" "<<share1[2]<<" "; 
    cout <<"m="<<capacity3<<" "<<share3[0]<<" "<<share3[1]<<" "<<share3[2]<<" ";  
    cout <<"b_num:c=" << block1 << " m=" << block3<<" ";
    cout <<"b_rte:c=" << block1/(block1+capacity1) << " m=" << block3/(block3+capacity3) <<" ";
		// output the optimisation time and oscillation number
		cout <<"time(sec)=" << (time2 - time1) << " osc=" << osc_num << endl;

    // Save the recover info.
    if (i < scen_n)      
			ams->checkpoint(i+1, "rec_bub.dat");
#endif      
  }

  // release the testbed.
  // It is not very effecient to create testbed everytime when testing/tuning, 
  // but we do not use it often, so just leave it.
  delete tb;
}

// main function
int main(int argc, char *argv[]) {
  // check the command line input
  if( argc < 3 ) {
    usage(argv[0]);
    exit(1);
  } 

  // create MAS and DF
  ams = new MAS_AMS();
  df = new MAS_DF();

  // setup the parameters           
  df->parameter.W0 = 0; //0.002; // 0.00613; //1.7; //(U4) //0.00613;	//(U0)			 
//  df->parameter.W1 = 0.00058;				 
//  df->parameter.W2 = 0.035;
  df->parameter.W3 = 100;//0.5;//0.4; //0.7; //0.4;

#ifdef _TEST_
  // For testing and tuning
  testing(argc, argv);
#else
  mainFunc(argc, argv);
#endif

  delete df;
  delete ams;

  return 0;
}







⌨️ 快捷键说明

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