randomwalk2dmobility model

25 views
Skip to first unread message

Binus, Newuleko Bayo (The grey)

unread,
Sep 29, 2025, 8:10:51 PMSep 29
to ns-3-users
hi, please i have a problem. i am using the randomwalk2dmobility model. but my simulation area is circular. My concern is that the boundary is set in rectangle while the simulation area is in a circle. how do i deal with this situation?
here is my code snippet: 

MobilityHelper mobilityMobile;
    mobilityMobile.SetPositionAllocator("ns3::UniformDiscPositionAllocator",
                                        "rho",
                                        DoubleValue(radiusMeters),
                                        "X",
                                        DoubleValue(0.0),
                                        "Y",
                                        DoubleValue(0.0));
    mobilityMobile.SetMobilityModel(
        "ns3::RandomWalk2dMobilityModel",
        "Speed",
        StringValue("ns3::UniformRandomVariable[Min=2.0|Max=5.0]"),
        "Bounds",
        RectangleValue(Rectangle(-radiusMeters, radiusMeters, -radiusMeters, radiusMeters)));

Tommaso Pecorella

unread,
Sep 30, 2025, 3:09:33 PMSep 30
to ns-3-users
I'm afraid you'll need to develop a new RandomWalk model.
The good news is that it's not that complicated, just look at the existing ones.

Binus, Newuleko Bayo (The grey)

unread,
Oct 1, 2025, 7:32:11 AMOct 1
to ns-3-users
thank you. can you give me a clue, please, of what to consider in my modification??

Tom Henderson

unread,
Oct 1, 2025, 10:28:40 AMOct 1
to ns-3-...@googlegroups.com, Binus, Newuleko Bayo (The grey)

Unfortunately, I think it is a bit of work but certainly doable if you follow the pattern of the existing rectangular model.

It may be instructive to enable ns-3 logging of the existing model on a program that uses it, and observe how it works:

NS_LOG="RandomWalk2d" ./ns3 run ..... (program name)

The basic idea is as follows.  There is a bounding object (class Rectangle).  The mobility model moves by repeatedly drawing a random direction and speed; these constitute a velocity.  The mobility model will move at that velocity for either a pre-determined (constant) amount of time, or a pre-determined (constant) distance.  Whether distance or time is used is set by the Mode attribute.

When the mobility model reaches its destination, it draws a new velocity.  It then looks ahead to see whether its next eventual destination is within the bounds, or outside.  If it is inside, it just determines the time that it will reach that (interior) new position, and schedules the next mobility event then, and moves in that direction.  If, however, the eventual destination is outside the bounds, the model determines at what point it will hit the boundary.  It then schedules a Rebound event for the time that it will hit the boundary, and calculates the angle with which it will rebound from the bounding box, and the remaining motion time left until it draws a new random velocity.

So if you want to follow this approach, you will have to create a new 'Circle' or 'Disc' object similar to 'Rectangle', and define how circular rebound works (e.g., reflect based on the incident angle from the normal of the circle to the rebound point).

Because Rectangle is not a subclass of any common base class that can be used to generalize the existing mobility model, you will have to choose either refactoring the existing model to be more general, or else copy the RandomWalk2dMobilityModel class into some other new class.  If we were to merge these extensions to ns-3, we'd probably ask for the former solution, but if you are just writing for your private use, you may find it to be faster to clone and edit the existing.

I will put some more details into an issue in the issue tracker when I get a chance.

- Tom

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/a20f2093-98cb-4584-ad9b-136c1c9cea9an%40googlegroups.com.

Binus, Newuleko Bayo (The grey)

unread,
Oct 2, 2025, 6:33:44 AMOct 2
to ns-3-users
thank you for this great help. Let me get to work and see how I can do it. once again, I really appreciate this huge help. I will be coming back with something to show you.
Reply all
Reply to author
Forward
0 new messages