home  

Bug in RandomWalk mobility model

 

 

Noam Mori has found a bug in the Random Walk mobility model. The bug manifests in the behavior of nodes once they reach the bounds of the simulation area. The intended behavior in these scenarios was for the nodes to bounce off the walls. However, when nodes hit the right or the bottom walls they will not bounce off the wall, but rather teleport themselves to the opposite wall as if the space was wrapped around.

This bug is originated from the following method (this is the original code). File: Mobility.java, class: RandomWalk:

public void next(FieldInterface f, Integer id, Location loc, MobilityInfo info)
{

// compute new random position with fixedRadius+randomRadius() distance
double randomAngle = 2*Math.PI*Constants.random.nextDouble();
double
r = fixedRadius + Constants.random.nextDouble()*randomRadius;
double x = r * Math.cos(randomAngle), y = r * Math.sin(randomAngle);
double lx = loc.getX()+x, ly = loc.getY()+y;

// bounds check and reflect
if(lx<0) lx=-lx;
if(ly<0) ly=-ly;
if
(lx>bounds.getX()) lx = bounds.getX()-lx;
if
(ly>bounds.getY()) ly = bounds.getY()-ly;
// move
if(pauseTime>0)
{
    JistAPI.sleep(pauseTime);
    Location l = new Location.Location2D((float)lx, (float)ly);
   
//System.out.println("move at t="+JistAPI.getTime()+" to="+l);
   
f.moveRadio(id, l);
}

}

The fix is:

public void next(FieldInterface f, Integer id, Location loc, MobilityInfo info)
{

// compute new random position with fixedRadius+randomRadius() distance
double randomAngle = 2*Math.PI*Constants.random.nextDouble();
double
r = fixedRadius + Constants.random.nextDouble()*randomRadius;
double x = r * Math.cos(randomAngle), y = r * Math.sin(randomAngle);
double lx = loc.getX()+x, ly = loc.getY()+y;

// bounds check and reflect
if(lx<0) lx=-lx;
if(ly<0) ly=-ly;
if
(lx>bounds.getX()) lx = 2*bounds.getX()-lx;    //Changed by Noam Mori
if(ly>bounds.getY()) ly = 2*bounds.getY()-ly;    //Changed by Noam Mori
// move
if(pauseTime>0)
{
    JistAPI.sleep(pauseTime);
    Location l = new Location.Location2D((float)lx, (float)ly);
   
//System.out.println("move at t="+JistAPI.getTime()+" to="+l);
   
f.moveRadio(id, l);
}

}

This fix reflects the intended behavior.


 

Gabriel Kliot

07/15/2008