ns2 LEACH 協定與節點座標資訊

四月真是個練習程式的好日子,因為又到了每年論文趕稿時刻。左圖描述 MobileNode 類別與 Node 類別兩者間的關係,顯然 MobileNode 是 Node 的延伸類別。在 ns2 中如果想要得知節點的座標資訊,可以使用 getLoc() 這個函式。該函式定義在 mobilenode.h 底下,所以使用前記得引入這個標頭檔。函式內容如下:
class MobileNode : public Node
{
public:
inline void getLoc(double *x, double *y, double *z) {
update_position(); *x = X_; *y = Y_; *z = Z_;
}
}使用方法是先將 Node 指標強制轉型成 MobileNode 指標再引用該函式。下面是一個小小的範例:
#include "mobilenode.h" double x,y,z; Node *p = Node::get_node_by_address(index); ((mobileNode *)p)->getLoc(&x, &y, &z);
回歸正題 LEACH 為 Low-Energy Adaptive Clustering Hierarchy 的簡稱,是一個在 Sensor Network 上廣為人知的路由協定。手頭上拿到一份給 ns2 用的模組(mit.tar.gz)還有安裝文件。因為該模組是針對 ns2.27 進行修正,對於其他版本而言,不可以直接使用取代方式安裝該模組。
比較正確的作法是照著安裝文件中的「檔案列表」,找出該模組新增的區段,然後針對各原始檔複製加入該區段。這些區段其實都用 #ifdef MIT_uAMPS 與 #endif 包圍起來,所以還蠻好辨識,這是模組擴增的部份。
另一個要修改的地方是 Makefile,以便進行LEACH模組的編譯。
* 在 DEFINE list 中加入 -DMIT_uAMPS * 在 INCLUDEs list 中加入 -I./mit/rca -I./mit/uAMPS * 在 gaf/gaf.o \ 之前加入 mit/rca/energy.o mit/rca/rcagent.o \ mit/rca/rca-ll.o mit/rca/resource.o \ mac/mac-sensor-timers.o mac/mac-sensor.o mit/uAMPS/bsagent.o \
最後進行 make 收工;至於模組的使用方法跟架構,就留給有心研究的人去試了 :Q
在軍中念博班唷,還不忘寫模擬呢XD
小黑要的嘛...
Dear Sir,
I really need your help . I am beginner with ns-2. I want to elect cluster heads with the residual energy of the nodes within clusters. So I want to get the residual energy of the nodes within clusters in Decideclusterhead() LEACH procedure. (under mannasim , ns-2 module extension)
please give me some advice how should i do if I want to get this parameter.
PS: I have tried , in order to have the residual energy of sensor_ node on leachApp.cc
So I proceeded as follows
1. declare the procedure (on LeachApp.h : double residualEnergy() ) The code on .cc
double LeachApp :: residualEnergy()
{
return ((Battery *) sensor_node_->energy_model())->energy() ;
}
and call it by:
Double E =residualEnergy();
(E is the value of the residual energy)
But I wonder, please, if this is correct, and please , do you have any suggestions that i can use it to have the energy.
looking for your reply soon .