[j-sim-users] two nodes are neighbours if they are in the same transmission range
Hung-ying Tyan
tyanh at ieee.org
Mon Oct 15 22:59:03 CDT 2007
Yes, I think those are the right places to change.
HT
On 10/15/07, wafa Berrayana <wafa.berrayana at gmail.com> wrote:
>
> Hello,
>
> I understand from the implementation of the SensorNodePositionTracker that
> two sensor nodes are neighbours if they are separated by a distance less
> than or equals to the transmission range (called radius in the
> implementation code).
>
> In my work, I simulate an ad hoc network and I have to consider that two
> nodes are neighbours if they are separated by a distance less than or equals
> to the transmission range (the same definition as in sensor implementation).
> Unfortunately, in J-Sim, (see file NodePositionTracker.java) two nodes are
> neighbours if they are located at the same grid space.
>
> So, should I change the method "processQuery" in the file "
> NodePositionTracker.java" by the method "processQuery" in the
> SensorNodePositionTracker.java file for this purpose.Thank you very much
> for your help.
>
> Wafa
>
> ------------------
>
> Next the implementation of "processQuery" in the file "
> NodePositionTracker.java"
>
> /*** Processes the neighbouring node inquery.*/
>
> protected void processQuery(Object data_, Port inPort_) {
>
> if ( !(data_ instanceof NeighborQueryContract.Message) ) {
>
> error(data_, "processQuery()", inPort_, "unknown
> object");
>
> return;
>
> }
>
> NeighborQueryContract.Message msg = (
> NeighborQueryContract.Message) data_;
>
> long id;
>
> double X, Y, Z;
>
> long[] nodeList;
>
> int nGrids;
>
> X = msg.getX();
>
> Y = msg.getY();
>
> Z = msg.getZ();
>
> nGrids = msg.getnGrids();
>
> int i, j, il, ir, jl, jr;
>
> i = (int)((X-minX)/dX);
>
> j = (int)((Y-minY)/dY);
>
> il = Math.max(0, i-nGrids);
>
> ir = Math.min(m-1, i+nGrids);
>
> jl = Math.max(0, j-nGrids);
>
> jr = Math.min(n-1, j+nGrids);
>
> int nn = 0;
>
> int ki, kj, kk, kv;
>
> for ( ki = il; ki <= ir; ki ++ )
>
> for ( kj = jl; kj <= jr; kj ++ )
>
> nn = nn + g[ki][kj].size();
>
> nodeList = new long[nn];
>
> kk = 0;
>
> for ( ki = il; ki <= ir; ki ++ ) {
>
> for ( kj = jl; kj <= jr; kj ++ ) {
>
> for ( kv = 0; kv < g[ki][kj].size(); kv ++ ) {
>
> nodeList[kk] =
> ((Long)(g[ki][kj].elementAt(kv))).longValue();
>
>
>
> kk = kk + 1;
>
> }
>
> }
>
> }
>
> // debug("query X = " + X + " Y = " + Y + " il = " + il + " i
> = " + i + " ir = " + ir + " jl = " + jl + " j = " + j + " jr = " + jr + "
> nodeList size = " + nn);
>
> channelPort.doSending(new NeighborQueryContract.Message
> (nodeList));
>
> }
>
> }
> ------------------
>
> And the the implementation of "processQuery" in the file "
> SensorNodePositionTracker.java"
>
> /** Handles query and replies with a list of neighbors */
>
> protected synchronized void processQuery(Object data_, Port inPort_) {
>
> if ( !(data_ instanceof SensorNeighborQueryContract.Message) ) {
>
> error(data_, "processQuery()", inPort_, "unknown object");
>
> return;
>
> }
>
> SensorNeighborQueryContract.Message msg = (
> SensorNeighborQueryContract.Message) data_;
>
> long nid;
>
> double X, Y, Z;
>
> double Radius; double sqmnr ;
>
> long[] nodeList;
>
> SensorLocationInformation current = new SensorLocationInformation()
> ;
>
> X = msg.getX();
>
> Y = msg.getY();
>
> Z = msg.getZ();
>
> nid = msg.getNid();
>
> Radius = msg.getRadius();
>
> int grid_x, grid_y, i, j, ulx, uly, lly, llx, adj ;
>
> grid_x = aligngrid((int)X - (int)minX, dim_x_);
>
> grid_y = aligngrid((int)Y - (int)minY, dim_y_);
>
> sqmnr = Radius * Radius ;
>
> adj = (int)(Math.ceil(Radius));
>
> ulx = Math.min(dim_x_-1, grid_x + adj);
>
> uly = Math.min(dim_y_-1, grid_y + adj);
>
> lly = Math.max(0, grid_y - adj);
>
> llx = Math.max(0, grid_x - adj);
>
> long id ;
>
> int kv ;
>
> int nn = 0;
>
> for (i = llx; i <= ulx; i++)
>
> for (j = lly; j <= uly; j++)
>
> for ( kv = 0; kv < g[i][j].size(); kv++ )
>
> {
>
> current =
> (SensorLocationInformation)(g[i][j].get(kv));
>
> id = current.nid ;
>
> if ( id != nid )
>
> { // only if id of potential neighbor is different.
>
> nn = nn + 1;
>
> } // end if id != nid
>
> } // end for kv
>
> nodeList = new long[nn];
>
> int kk = 0 ;
>
> for (i = llx; i <= ulx; i++) {
>
> for (j = lly; j <= uly; j++) {
>
> for ( kv = 0; kv < g[i][j].size(); kv ++ ) {
>
> current =
> (SensorLocationInformation)(g[i][j].get(kv));
>
> id = current.nid ;
>
> if ( id != nid ) { // only if the id of the
> potential neighbor is different.
>
> if ( distance(current.X, X, current.Y, Y) <
> sqmnr )
>
> {
>
> nodeList[kk] = id ;
>
> kk = kk + 1;
>
> } // end if d2
>
> } // end if id != nid
>
> } // end for kv
>
> } // end for j
>
> } // end for i
>
> channelPort.doSending(new SensorNeighborQueryContract.Message
> (nodeList));
>
> }
>
> _______________________________________________
> j-sim-users mailing list
> j-sim-users at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/j-sim-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.uiuc.edu/pipermail/j-sim-users/attachments/20071016/cb101caf/attachment-0001.html
More information about the j-sim-users
mailing list