📄 testbed.cpp
字号:
// int PtStyleNum[] = { 82, 47, 84, 15, 13, 05, 63, 88, 72}; // for postscript output
try{
long i;
// Open macro file.
ofstream fout(FileName);
// write global setting for gnuplot
fout << "set multiplot" << endl;
fout << "set noautoscale" << endl;
fout << "set lmargin 0" << endl;
fout << "set bmargin 0" << endl;
fout << "set rmargin 0" << endl;
fout << "set tmargin 0" << endl;
fout << "set noxtics" << endl;
fout << "set noytics" << endl;
fout << "set noborder" << endl;
fout << "set xrange [-3:27]" << endl;
fout << "set yrange [-9:21]" << endl;
// set the linestyle for windows terminal
// fout << "load \"PointStyle.def\"" << endl;
// plot all base stations
fout << "#Plot all base stations" << endl;
fout << "set label \"Optimisation Result\" at 10,16 left" << endl;
fout << "set pointsize 1.0" << endl;
fout << "plot \"-\" notitle w point " << PtStyleNum[8] << endl;
for ( i = 0; i < BS_NUMBER; i++) {
fout << bs[i]->getX() << " " << bs[i]->getY() << endl;
}
fout << "EOF" << endl << endl;
/*
// plot all silent MS
fout << "#Plot all silent traffic units" << endl;
fout << "set nolabel" << endl;
fout << "set pointsize 0.1" << endl;
fout << "plot \"-\" notitle w point pointtype7" << endl;
for (long i = 0; i < TU_NUMBER; i++) {
if ( !tu[i]->isTalking(simTime) ) {
fout << tu[i]->getX() << " " << tu[i]->getY() << endl;
}
}
fout << "EOF" << endl << endl;
*/
// plot all served TU
fout << "#Plot all served traffic units" << endl;
fout << "set nolabel" << endl;
fout << "set pointsize 0.2" << endl;
// For served users
int color;
fout << "#Plot served-by-1-BS traffic units" << endl;
for ( color = 0; color < 3; color ++ ) {
fout << "plot \"-\" notitle w point " << PtStyleNum[color] << endl;
for ( i = 0; i < TU_NUMBER; i++) {
if ( tu[i]->isTalking(simTime) && tu[i]->isServed(0) && !tu[i]->isServed(1)
&& tu[i]->getServedBS(0)->getColor() == (color+1) ) {
// For those normal served TUs
fout << tu[i]->getX() << " " << tu[i]->getY() << endl;
}
}
fout << "EOF" << endl << endl;
}
// For shared users (soft handover)
fout << "#Plot served-by-2-BS traffic units" << endl;
for ( color = 3; color < 6; color ++ ) {
fout << "plot \"-\" notitle w point " << PtStyleNum[color] << endl;
for ( i = 0; i < TU_NUMBER; i++) {
if ( tu[i]->isTalking(simTime) && tu[i]->isServed(1) && !tu[i]->isServed(2) ) {
int color1 = tu[i]->getServedBS(0)->getColor(); // 1, 2, or 3
int color2 = tu[i]->getServedBS(1)->getColor(); // 1, 2, or 3
if (color1 + color2 == color) { // 1+2=3, 1+3=4, 2+3=5
// For those shared TUs
fout << tu[i]->getX() << " " << tu[i]->getY() << endl;
}
}
}
fout << "EOF" << endl << endl;
}
// For shared-by-3-BS users (softer handover)
fout << "#Plot served-by-3-BS traffic units" << endl;
fout << "plot \"-\" notitle w point " << PtStyleNum[6] << endl;
for ( i = 0; i < TU_NUMBER; i++) {
if ( tu[i]->isTalking(simTime) && tu[i]->isServed(2) ) {
// For those shared-by-3-BS TUs
fout << tu[i]->getX() << " " << tu[i]->getY() << endl;
}
}
fout << "EOF" << endl << endl;
// plot all blocked TUs
fout << "#Plot all un-served traffic units" << endl;
fout << "set nolabel" << endl;
fout << "set pointsize 0.7" << endl;
fout << "plot \"-\" notitle w point " << PtStyleNum[7] << endl;
for ( i = 0; i < TU_NUMBER; i++) {
if ( tu[i]->isTalking(simTime) && !tu[i]->isServed() ) {
fout << tu[i]->getX() << " " << tu[i]->getY() << endl;
}
}
fout << "EOF" << endl << endl;
// set nomulti
fout << "set nomultiplot" << endl;
fout << "reset" << endl;
// Finish the plotting
fout.close();
}
catch(...){
cout << "Fatal Error with writing result file: " << FileName << endl;
exit(1);
}
}
//////////////////////////////////////////////////////////////////////
// Output the macro file for matlab
//////////////////////////////////////////////////////////////////////
void TestBed::writeMatlabResult( char *FileName ){
const double MIN_X = 12;
const double MAX_X = 19;
const double MIN_Y = 4;
const double MAX_Y = 11;
long i, tu_i;
double x,y;
try {
// Open macro file.
ofstream fout(FileName);
// some global setting
// fout << "clear;" << endl;
// fout << "close all;" << endl;
fout << "figure(11);" << endl;
fout << "axis off equal tight;" << endl;
fout << "hold on" << endl;
// plot all base stations
fout << "% Plot base stations" << endl;
fout << "bs_loc=[" << endl;
for (i = 0; i < BS_NUMBER; i++) {
x = bs[i]->getX();
y = bs[i]->getY();
if ( x > MIN_X && x < MAX_X && y > MIN_Y && y < MAX_Y )
fout << x << " " << y << endl;
}
fout << "];" << endl << endl;
fout << "scatter(bs_loc(:,1), bs_loc(:,2), '^', 'k');" << endl;
fout << "axis off" << endl;
fout << "clear bs_loc;" << endl;
/*
// plot all silent MS
fout << "% Plot all silent traffic units" << endl;
fout << "silent_loc=[" << endl;
for (long i = 0; i < TU_NUMBER; i++) {
if ( !tu[i]->isTalking(simTime) ) {
fout << tu[i]->getX() << " " << tu[i]->getY() << endl;
}
}
fout << "];" << endl << endl;
*/
// plot all served TU
fout << "% Plot all served traffic units." << endl;
fout << "color_code=[[0,0,1];[0,1,0];[1,0,0];[0,1,1];[1,1,0];[1,0,1];[0.5,0.5,0.5];[0,0,0]];" << endl;
fout << "marker_code=['.','.','.','.','.','.','.','^'];" << endl;
fout << "size_code=[5,5,5,5,5,5,5,7];" << endl;
// For served users
int color;
i=0;
fout << "%Plot served-by-1-BS traffic units" << endl;
for ( color = 0; color < 3; color ++ ) {
fout << "tu_loc=[" << endl;
for (tu_i = 0; tu_i < TU_NUMBER; tu_i++) {
if ( tu[tu_i]->isTalking(simTime) && tu[tu_i]->isServed(0) && !tu[tu_i]->isServed(1)
&& tu[tu_i]->getServedBS(0)->getColor() == (color+1) ) {
// For those normal served TUs
x = tu[tu_i]->getX();
y = tu[tu_i]->getY();
if ( x > MIN_X && x < MAX_X && y > MIN_Y && y < MAX_Y ) {
fout << x << " " << y << endl;
i++;
}
}
}
if(i>0) {
fout << "];" << endl << endl;
fout << "h=scatter(tu_loc(:,1), tu_loc(:,2));" << endl;
fout << "axis off" << endl;
fout << "set(h,'Marker', marker_code(" << color+1 << ") );" << endl;
fout << "set(h,'MarkerSize', size_code(" << color+1 << ") );" << endl;
fout << "set(h,'MarkerEdgeColor',color_code(" << color+1 << ",:) );" << endl;
fout << "set(h,'MarkerFaceColor',color_code(" << color+1 << ",:) );" << endl;
fout << "clear tu_loc;" << endl;
}
}
// Plot served-by-2-BS traffic units
i=0;
fout << "%Plot served-by-2-BS traffic units" << endl;
for ( color = 3; color < 6; color ++ ) {
fout << "tu_loc=[" << endl;
for (tu_i = 0; tu_i < TU_NUMBER; tu_i++) {
if ( tu[tu_i]->isTalking(simTime) && tu[tu_i]->isServed(1) && !tu[tu_i]->isServed(2) ) {
int color1 = tu[tu_i]->getServedBS(0)->getColor(); // 1, 2, or 3
int color2 = tu[tu_i]->getServedBS(1)->getColor(); // 1, 2, or 3
if (color1 + color2 == color) { // 1+2=3, 1+3=4, 2+3=5
// For those normal served TUs
x = tu[tu_i]->getX();
y = tu[tu_i]->getY();
if ( x > MIN_X && x < MAX_X && y > MIN_Y && y < MAX_Y ) {
fout << x << " " << y << endl;
i++;
}
}
}
}
if(i>0) {
fout << "];" << endl << endl;
fout << "h=scatter(tu_loc(:,1), tu_loc(:,2));" << endl;
fout << "axis off" << endl;
fout << "set(h,'Marker', marker_code(" << color+1 << ") );" << endl;
fout << "set(h,'MarkerSize', size_code(" << color+1 << ") );" << endl;
fout << "set(h,'MarkerEdgeColor',color_code(" << color+1 << ",:) );" << endl;
fout << "set(h,'MarkerFaceColor',color_code(" << color+1 << ",:) );" << endl;
fout << "clear tu_loc;" << endl;
}
}
// Plot served-by-3-BS traffic units
i=0;
fout << "%Plot served-by-3-BS traffic units" << endl;
fout << "tu_loc=[" << endl;
for (tu_i = 0; tu_i < TU_NUMBER; tu_i++) {
if ( tu[tu_i]->isTalking(simTime) && tu[tu_i]->isServed(2) ) {
// For those normal served TUs
x = tu[tu_i]->getX();
y = tu[tu_i]->getY();
if ( x > MIN_X && x < MAX_X && y > MIN_Y && y < MAX_Y ) {
fout << x << " " << y << endl;
i++;
}
}
}
if(i>0){
fout << "];" << endl << endl;
fout << "h=scatter(tu_loc(:,1), tu_loc(:,2));" << endl;
fout << "axis off" << endl;
fout << "set(h,'Marker', marker_code(7) );" << endl;
fout << "set(h,'MarkerSize', size_code(7) );" << endl;
fout << "set(h,'MarkerEdgeColor',color_code(7,:) );" << endl;
fout << "set(h,'MarkerFaceColor',color_code(7,:) );" << endl;
fout << "clear tu_loc;" << endl;
}
// plot all blocked TUs
fout << "% Plot all un-served traffic units" << endl;
fout << "tu_loc=[" << endl;
int blk_num = 0;
for ( tu_i = 0; tu_i < TU_NUMBER; tu_i++) {
if ( tu[tu_i]->isTalking(simTime) && !tu[tu_i]->isServed() ) {
x = tu[tu_i]->getX();
y = tu[tu_i]->getY();
if ( x > MIN_X && x < MAX_X && y > MIN_Y && y < MAX_Y ) {
fout << x << " " << y << endl;
blk_num ++;
}
}
}
fout << "];" << endl << endl;
if (blk_num > 0) {
fout << "h=scatter(tu_loc(:,1), tu_loc(:,2));" << endl;
fout << "axis off" << endl;
fout << "set(h,'Marker', marker_code(8) );" << endl;
fout << "set(h,'MarkerSize', size_code(8) );" << endl;
fout << "set(h,'MarkerEdgeColor',color_code(8,:) );" << endl;
fout << "set(h,'MarkerFaceColor',color_code(8,:) );" << endl;
fout << "clear tu_loc;" << endl;
fout << "hold off" << endl;
}
// Finish the plotting
fout.close();
}
catch(...){
cout << "Fatal Error with writing result file: " << FileName << endl;
exit(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -