change the mobility models over time

84 views
Skip to first unread message

Themasters22 Iraqis

unread,
Jun 25, 2024, 10:34:15 AM6/25/24
to ns-3-users
could any one help me please i made this function for changing from random waypoint to random walk using the hierarchical mobility model:
 void ChangeToRandomWalk(NodeContainer nodes, std::vector<Vector> initialPositions)
{
        for (uint32_t i = 0; i < nodes.GetN(); ++i)
    {
        Ptr<Node> node = nodes.Get(i);
        NS_LOG_UNCOND("Changing Node " << node->GetId() << " to RandomWalk2dMobilityModel");
        Ptr<HierarchicalMobilityModel> hierarchicalMobility = node->GetObject<HierarchicalMobilityModel>();
        if (hierarchicalMobility)
        {
            Ptr<RandomWalk2dMobilityModel> randomWalk = CreateObject<RandomWalk2dMobilityModel>();
            randomWalk->SetAttribute("Bounds", RectangleValue(Rectangle(0.0, 200.0, 0.0, 200.0)));
            randomWalk->SetAttribute("Distance", DoubleValue(10.0));
            randomWalk->SetAttribute("Speed", StringValue("ns3::ConstantRandomVariable[Constant=0.5]"));

            hierarchicalMobility->SetChild(randomWalk);
            randomWalk->SetPosition(initialPositions[i]); // Set the initial position

            NS_LOG_UNCOND("Mobility model for Node " << node->GetId() << " changed to RandomWalk2dMobilityModel.");
        }
        else
        {
            NS_LOG_ERROR("Node " << node->GetId() << " has no HierarchicalMobilityModel");
        }
    }
} but igot error as soon as it changed after 2 seconds: At time +62.4454s on-off application sent 250 bytes to 10.1.1.13 port 50000 total Tx 37750 bytes
At time +62.4455s packet sink received 250 bytes from 10.1.1.12 port 49153 total Rx 37750 bytes
At time +62.4469s on-off application sent 250 bytes to 10.1.1.11 port 50000 total Tx 37750 bytes
At time +62.4471s packet sink received 250 bytes from 10.1.1.10 port 49153 total Rx 37750 bytes
Command 'build/scratch/ns3.38-chain9thExp-default --routingProtocol=AODV --nNodes=15 --simtime=120' died with <Signals.SIGSEGV: 11>.

Tommaso Pecorella

unread,
Jun 26, 2024, 11:19:50 AM6/26/24
to ns-3-users
Can you attach a simple script highlighting the problem?
That would help in tracking it down.

Thanks

Shyam Parekh

unread,
Sep 24, 2025, 6:04:06 AMSep 24
to ns-3-users
I'm also trying to use the hierarchical mobility model to change the mobility model over time. The attached script switches the mobility model from ConstantPosition to SteadyStateRandomWaypoint, and then switches back to ConstantPosition. Can't figure out why the SteadyStateRandomWaypoint model is not getting activated here. Please let me know if you can provide any insight.

Thanks,

Shyam
testMobilityChange.py

Tom Henderson

unread,
Sep 24, 2025, 6:43:24 AMSep 24
to ns-3-...@googlegroups.com

Please note that SteadyStateRandomWaypoint model does a lot of things at object initialization time (see the DoInitialize() and DoInitializePrivate() methods).  I don't know whether this applies to your situation, but you mention that you are switching between mobility models during runtime, and SteadyState is not really designed to do this (start after time zero).  Anyway, since you are reporting that you do not know why SteadyState is not starting, this reliance on DoInitializePrivate() may be the reason (just a guess).

I was going to suggest that you turn on ns-3 logging of SteadyStateRandomWaypointMobilityModel, to see what methods are callled when, but discovered upon looking just now that there is not much logging in that code so you may have to add some log statements to be able to do that.

- 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/ce23e1d1-020d-478d-9256-dcad873cf399n%40googlegroups.com.

Shyam Parekh

unread,
Sep 24, 2025, 7:24:51 AMSep 24
to ns-3-users
Thank you, Tom!

Shyam

Shyam Parekh

unread,
Sep 26, 2025, 1:45:27 AMSep 26
to ns-3-users
In the attached script, I have made the following change: it now switches the mobility model from ConstantPosition to RandomWalk2d, and then switches back to ConstantPosition. I'm not able to figure out why the script crashes right after the last switching. Please take a look to see if you can help.

Thanks,

Shyam
testMobilityChange1.py
Reply all
Reply to author
Forward
0 new messages