📄 trafficunit.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
//
//////////////////////////////////////////////////////////////////////
#include "TrafficUnit.h"
TrafficUnit::TrafficUnit() {
ID = 0;
demand = 0;
}
TrafficUnit::TrafficUnit(Point &loc, int ID) {
demand = 0;
this->ID = ID;
this->set(loc);
}
TrafficUnit::TrafficUnit(Point &loc, double dem, int ID) {
this->ID = ID;
this->set(loc);
demand = dem;
}
TrafficUnit::TrafficUnit(double X, double Y, int ID) {
demand = 0;
this->ID = ID;
this->set(X, Y);
}
TrafficUnit::TrafficUnit(double X, double Y, double dem, int ID) {
this->ID = ID;
this->set(X, Y);
demand = dem;
}
TrafficUnit::~TrafficUnit() {
}
int TrafficUnit::getID() const {
return ID;
}
/**
* The BS providing service for this traffic unit.
* NULL_BS if this TU is blocked or not talking.
*/
BaseStation *TrafficUnit::getServedBS(int index) const {
return status[index].p_BS;
}
// Set the cell base station and serve/share status
void TrafficUnit::assigned( BaseStation *bs ) {
for (int i=0; i<MAX_SHARE_NUM; i++) {
if (!status[i].isSubscribed) {
status[i].isSubscribed = true;
status[i].p_BS = bs;
return;
}
}
}
// clear the cell base station and serve/share status
void TrafficUnit::drop( BaseStation *bs ) {
for (int i=0; i<MAX_SHARE_NUM; i++) {
if (status[i].p_BS == bs) {
for(int j=i+1; j<MAX_SHARE_NUM; j++) {
status[j-1] = status[j];
}
return;
}
}
}
// Change traffic unit's location.
void TrafficUnit::move( double X, double Y ) {
this->set(X, Y);
}
void TrafficUnit::move( Point &loc ) {
this->set(loc);
}
// Return demand of this TU
double TrafficUnit::getDemand() const {
return demand;
}
// Set demand of this TU
void TrafficUnit::setDemand(double dem) {
demand = dem;
}
// Return the call generator, used for saving and reseting state
CallGenerator *TrafficUnit::getCallGenerator() {
return &callGen;
}
// Check is this MS is talking or standing.
bool TrafficUnit::isTalking(double currentTime) {
return callGen.talking( currentTime );
}
// Check is this TU has been served. INCLUDES SHARED!!!
bool TrafficUnit::isServed() const {
return this->status[0].isSubscribed;
}
// Check is this TU has been served. INCLUDES SHARED!!!
bool TrafficUnit::isServed(int index) const {
_ASSERT(index<MAX_SHARE_NUM);
return this->status[index].isSubscribed;
}
// Check is this TU has been served by specific BS. NOT INCLUDES SHARED!!!
bool TrafficUnit::isServed(const BaseStation *bs) const {
for (int i=0; i<MAX_SHARE_NUM; i++) {
if (status[i].p_BS == bs) {
return true;
}
}
return false;
}
// Reset the TU's subscription status
void TrafficUnit::reset() {
for (int i=0; i<MAX_SHARE_NUM; i++) {
status[i].isSubscribed = false;
status[i].p_BS = NULL;
}
}
/**
* friend operators
*/
bool operator==(const TrafficUnit &ms1, const TrafficUnit &ms2) {
return (ms1.getID() == ms2.getID());
}
bool operator==(const TrafficUnit &ms1, int ID) {
return ms1.getID() == ID;
}
bool operator!=(const TrafficUnit &ms1, const TrafficUnit &ms2) {
return (ms1.getID() != ms2.getID());
}
bool operator!=(const TrafficUnit &ms1, int ID) {
return ms1.getID() != ID;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -