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

📄 bsagent.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
//
//////////////////////////////////////////////////////////////////////

// BSAgent.cpp: implementation of the BSAgent class.
//
//////////////////////////////////////////////////////////////////////

#include "BSAgent.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
BSAgent::BSAgent() {
}

BSAgent::BSAgent(BaseStation *bs, MAS_DF *df) {
  this->df = df;
  this->bs = bs;

  optimizer  = new LocalOptimizer(this);
  evaluator  = new Evaluator(this);

	currScheme = new P_TU_V;
	nextScheme = new P_TU_V;

	// reset the counter and flags.
	this->reset();
}

BSAgent::~BSAgent() {
  delete evaluator;
  delete optimizer;

	delete currScheme;
	delete nextScheme;
}

//////////////////////////////////////////////////////////////////////
// Return the BS_ID of this base station agent
//////////////////////////////////////////////////////////////////////
int BSAgent::getID() const {
  return bs->getID();
}

//////////////////////////////////////////////////////////////////////
// reset oscNum and initiate the bubble
//////////////////////////////////////////////////////////////////////
void BSAgent::reset() {
	// reset the counter and flags.
	oscNum = 0;
	holding = false;
	schemeUpdated = false;
}

//////////////////////////////////////////////////////////////////////
// Run bubble oscillation
//////////////////////////////////////////////////////////////////////
void BSAgent::run() {
	if ( !holding ) { 
		// start the buuble oscillation 
		optimizer->oscBubble();
		// scheme need to be updated (currScheme and nextScheme)
		schemeUpdated = true;
		holding = true;		// after oscillation, it needs to be held on for one turn to avoid oscillate back.
	}
	else {
		holding = false;		// after hold on for one turn, it is allowed for further oscillation.
	}
}

// Commit the changes by exchange currScheme and nextScheme, and apply the currScheme to BS.
void BSAgent::commit() {
	// check if scheme need to be updated
	if ( schemeUpdated ) {
		// exchange currScheme and nextScheme. 
		// Note: we can't simply replace currScheme with nextScheme, it will lose currScheme 
		//			 object and cause memory leak, as they are vector pointers
		P_TU_V *tmp = currScheme;
		currScheme = nextScheme;
		nextScheme = tmp;

		// clear nextScheme
		nextScheme->clear();
	}

	// apply the currScheme to BS
	bs->applyCurrScheme();

	// clear the schemeUpdated flag
	schemeUpdated = false;
}

// Return the current scheme
P_TU_V &BSAgent::getCurrScheme() {
	return *currScheme;
}

// Return the possible Tu of this base station
P_TU_V &BSAgent::getPossibleTU() {
  return bs->possibleTU;
}

//////////////////////////////////////////////////////////////////////
// Return the ID of neighbour BS
//////////////////////////////////////////////////////////////////////
int BSAgent::getNeighbourID(int index) const {
  if ( bs->Neighbour[index] != NULL ) 
    return bs->Neighbour[index]->getID();
  else
    return 0;
}

⌨️ 快捷键说明

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