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

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

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

#include "LocalOptimizer.h"

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

LocalOptimizer::LocalOptimizer(BSAgent *agent) {
  this->agent = agent;
}

LocalOptimizer::~LocalOptimizer() {
}

//////////////////////////////////////////////////////////////////////
// Propose the best possible scheme for this BS and save it to currScheme, 
//      The goal for this is to try to balance the loads within 7 cells 
//			This is used for initiate the bubbles when oscNumber=0; and oscillation when oscNumber>0
//
// Note: This will be immediately committed if the load has not exceed the UR_TARGET
//////////////////////////////////////////////////////////////////////
void LocalOptimizer::oscBubble() {
	double load_target;
  int nbr_num;

  /////////////////////////////////
  // first calculate the load target we will try to reach 
	//	Note: Currently we use the average value of the prospective load of 7 cells
  /////////////////////////////////
  // either only check the local one
/*	load_target=0;
	for(nbr_num=0; nbr_num<6; nbr_num++) {
		// cumulate the total load in the whole local region. (sum of the load in six sectors)
		load_target += agent->bs->getNbrDemand(nbr_num);
	}

	//  the prospective load from local into.
	load_target *= (SHARE_DISTANCE*SHARE_DISTANCE)/(MAX_DISTANCE*MAX_DISTANCE);
*/
	// or use the average value of the prospective load of 7 cells
	load_target=0;
	nbr_num = 0;
  for(int i=0; i<6; i++) {
    int helperID = agent->getNeighbourID(i);
    if (helperID != NULL ) {    
      BaseStation *bs = agent->df->findBS( helperID );

      // Accumulate the load
      load_target += bs->getProspectiveLoad();
      nbr_num ++;
    }
  }
  load_target += agent->bs->getProspectiveLoad();
  // get the average value;
  load_target /= (nbr_num + 1.0);


  // Check if load_target exceed the UR_TARGET(can reserve some capacity if UR_TARGET<1)
  if (load_target > agent->bs->getCapacity() * UR_TARGET) 
    load_target = agent->bs->getCapacity() * UR_TARGET;

  /////////////////////////////////
  // then calculate the U and sort them (initBubble or oscBubble)
  /////////////////////////////////
	TrafficUnit *p_tu;
	// Get the possible TUs
  P_TU_V &allTU = agent->getPossibleTU();
	// check if it is the first time (initBubble) or not (oscillation)
	if (agent->oscNum == 0)	{		// initBubble
		// Calculate the utility for each of them, and sort them into sortedTU
		utilTU.clear();
		for(unsigned int i=0; i<allTU.size(); i++) {
			p_tu = allTU[i];
			Point initForce = agent->evaluator->getRepulsionForce(*p_tu);
			// create a ForceInfo to store the repulsion and attraction (actually stored in tu) force. 
			ForceInfo force;
			force.setRepulsion(initForce);
			utilTU.push_back( FI_P_TU(force, p_tu) );
		} 
	}
	else {								// oscillation
		// create a new TU vector to store all the blocked TU, so that we don't need to go through the allTU each time
		P_TU_V blkTU;
		for(unsigned int i=0; i<allTU.size(); i++) {
			if( !allTU[i]->isServed() ) {	// blocked tu
				blkTU.push_back(allTU[i]);
			}
		}
		// get all the blocked tu near this cell, use them as vacuum to attract the bubble.
		for( PAIR_V::iterator it = utilTU.begin(); it != utilTU.end(); it++ ) {
			ForceInfo &newForce = it->first;     // to get the original force
			p_tu = it->second;							// to check the traffic unit
			for(unsigned int i=0; i<blkTU.size(); i++) {
				Point temp_pt = agent->evaluator->getAttractionForce(*p_tu, *blkTU[i]);
				newForce.addAttraction( temp_pt );
			}
		}
	}

	// copy TU from utilTU into sortedTU, sorted by the resultant force
	sortedTU.clear();
	for( PAIR_V::iterator it = utilTU.begin(); it != utilTU.end(); it++ ) {
		ForceInfo &finalForce = it->first;
		p_tu = it->second;
		// calculate the projection of pt at the original vector (from BS to TU)
		double util = finalForce.getResultant();
		sortedTU.insert(P_TU_MAP::value_type( util, p_tu));
	}

	// Increase the oscillation counter
	agent->oscNum ++;

  /////////////////////////////////
  // at last use sortedTU to prepare a TU vector for nextScheme
  /////////////////////////////////
  double tmp_target = load_target;
	P_TU_V *scheme = agent->nextScheme;
// For debug
_ASSERT(scheme->size()==0);
// for debug

  for( P_TU_MAP::reverse_iterator r_it = sortedTU.rbegin(); r_it != sortedTU.rend(); r_it++ ) {
// For debug
#ifdef _DEBUG
    double u = r_it->first;     // to check the sequence of utility values
#endif
// for debug
	  p_tu = r_it->second;
    // Check the load
    tmp_target -= p_tu->getDemand();
    if ( tmp_target > 0) 
      scheme->push_back(p_tu);
    else 
      break;
  }
}

⌨️ 快捷键说明

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