Hello Kavan, Thanks alot for the reply. I haven't tried it yet because of a complication with NS2 (it aint cleaning any of the .o files). Ill try it soon.
One question, in God::IsNeighbor function, a constant called RANGE is used do have any idea where it is being defined !? Thanks alot, Mathiew :D Quoting kavan sheth <shethka...@gmail.com>: > Hi Mathiew > > I needed to the same in my project. > what I did is used god object. > you can study and you can do many more things using it . > here I am just describing what I did: > > I added following function in ns-2.33/mobile/god.cc (you will need to add > declaration in god.h) > > double God::getdistance(int i,int k) > > { > > double x1=mb_node[i]->X(); > > double y1=mb_node[i]->Y(); > > double x2=mb_node[k]->X(); > > double y2=mb_node[k]->Y(); > > double distance; > > distance=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))); > > return distance; > > } > then I was able to get distance between two nodes by writing following code > in c++ > > > *God::instance()->getdistance(i,k); // i and k are the id of the nodes* > > you will also need to include following statements in your .tcl file > > 1 after creating topography > > set topo [new Topography] > $topo load_flatgrid $val(x) $val(y) > > *set god_ [create-god $val(nn)]* > > 2. when you are dynamically creating nodes > > for { set i 0 } { $i < $val(nn) } { incr i } { > set node_($i) [$ns_ node $i] > $node_($i) random-motion 0 ;# disable random motion > *$god_ new_node $node_($i) > *} > > following is a function of my agent for your reference: > > void Manetconf::neighbors(int i) > { > int nodes=God::instance()->nodes(); > cout<<"neighbors of node "<<i<<":"<<endl; > for(int k=0;k<nodes;k++) > { > if(k!=i) > { > if(God::instance()->IsNeighbor(i,k)) > cout<<k<<":"<<God::instance()->getdistance(i,k)<<" yes"<<endl; > else > cout<<k<<":"<<God::instance()->getdistance(i,k)<<" no"<<endl; > } > } > cout<<endl; > } > > > > > > cheers > > Kavan > > On Mon, Jan 26, 2009 at 1:28 PM, Mathiew Moussa <mm...@aub.edu.lb> wrote: > >> >> >> Hello Walid, >> >> Thanks for replying. >> Here's the deal : im trying to simulate a WSN with nodes that are not >> mobile. >> In a topology.tcl file i have the nodes coordinates stored in the >> following form: >> >> $node_(0) set X_ 60 >> $node_(0) set Y_ 0 >> $node_(0) set Z_ 0 >> $node_(1) set X_ 92 >> $node_(1) set Y_ 43 >> $node_(1) set Z_ 0 ... >> >> Although i have these coordinates in the tcl files i still need to >> access them in C++, the reason is because i wanted to find distances >> between nodes as well as whether some nodes lied in the range of other >> (so its a couple of loops in C++) >> >> so id need something that look like this: >> >> for(i=0 ; i<numbNodes; i++) >> for (j=0 ; j<numNodes; j++) >> if(nodes[i].x == nodes[j].x) //just a stupid example >> (...) >> >> My algorithm is centralized at the base station.. over there i have >> the freedom to access the coordinates of the nodes from topology.tcl, >> the question is how ? >> >> I hope this is enough. >> Thanks again. >> Mathiew >> >> >> >> >> Quoting Waleed Tuffaha <tuff...@gmail.com>: >> > Hello Mathiew, >> > >> > Sorry for the late reply. I guess it would be best if you can explain a >> > little what you are trying to do. Is every node trying to find its >> > coordinates only ? >> > >> > On Thu, Jan 22, 2009 at 11:48 AM, Mathiew Moussa <mm...@aub.edu.lb> >> wrote: >> > >> >> Hello Walid, >> >> >> >> Thanks for the reply. >> >> >> >> You said getting the coordinates from the TCL file easier... i have them >> >> stored in a topography.tcl file (or so i recall) that has the X Y Z >> >> coordinates of each sensor. >> >> >> >> So what's the way to get them from the TCL file directly to be used in >> C++ >> >> ?? >> >> >> >> Thanks alot, >> >> Mathiew >> >> >> >> >> >> >> >> >> >> Quoting Waleed Tuffaha <tuff...@gmail.com>: >> >> >> >> Hello Mathiew, >> >>> >> >>> ( Note that I didn't test this ! ) >> >>> >> >>> The "Node class" uses a "Location class" in which the X,Y,Z variables >> are >> >>> defined. The "mobilenode class" inherits from the node class. >> >>> >> >>> So, if node_ is a pointer to a mobilenode, then you should be able to >> get >> >>> the coordinates using: >> >>> int x,y,z; >> >>> node_->location_->getLocation(&x, &y, &z) >> >>> >> >>> So if you have an array containing pointers to all the nodes then you >> can >> >>> loop on the array and get the coordinates for each node. >> >>> >> >>> I think that getting the coordinates from Tcl is easier, but I don't >> know >> >>> what exactly you are doing. >> >>> >> >>> Hope this helps >> >>> -- Waleed >> >>> >> >>> On Thu, Jan 22, 2009 at 9:59 AM, Mathiew Moussa <mm...@aub.edu.lb> >> wrote: >> >>> >> >>> >> >>>> Dear NS Users, >> >>>> >> >>>> Can someone please tell me how you can retrieve the coordinates of the >> >>>> network nodes from a TCL file into C++. >> >>>> So is their some loop or something that can be written in C++ and >> >>>> traverses all the nodes and gets X, Y, & Z, and how is it written. >> >>>> >> >>>> >> >>>> Hope you can help me. >> >>>> Thanks, >> >>>> Mathiew >> >>>> >> >>>> >> >>>> >> >>> >> >> >> >> >> >> >> > >> > >> > -- >> > Waleed Tuffaha. >> > >> >> >> >> >> >