特定范围内的节点数 [英] Count of nodes in an specific range

查看:75
本文介绍了特定范围内的节点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用静脉 5,并且我正在尝试获取距节点一定距离内的节点位置.更具体地说,我试图立即获得所有节点的映射位置,以处理节点的位置.

I'm using veins 5 and I am trying to obtain the position of nodes around in a certain distance from a node. More specifically, I'm trying to get a mapping position of all nodes in an instant to work with the positions of the nodes.

我阅读了这个问题 如何获取汽车数量特定范围,但是它以静脉 4.6 为中心,而且我不知道如何使用 Christoph Sommer 建议的方法.是否可以在静脉 5 中进行映射?我该如何工作?

I read this question How to get count of cars in specific range, however it centered in veins 4.6 and also I didn't get how to use the method suggested by Christoph Sommer. Is it possible to get the mapping in veins 5? How can I work this?

我将不胜感激谢谢!

推荐答案

最后我得到了模拟中所有节点的位置,并计算了它们与标记汽车的距离.

Finally I got the position of all nodes in the simulation and calculate their distance from a tagged car.

为此,我翻译"了Ahmad Ahsan 在问题 How to get Coordinates of each车辆在静脉? 到静脉 5.0 以下列方式:

To do this I "translate" the answer of Ahmad Ahsan in the question How to get Coordinates of each vehicle in VEINS? to veins 5.0 in the following way:

void MessageGenerator::getMapping(){

    // Get my position on the scenario
    veins::Coord myPosition = mobility->getPositionAt(simTime());
    EV << myPosition << endl;

    // Get all available nodes in simulation
    std::map<std::string, cModule*> allNodes = mobility->getManager()->getManagedHosts();

    // Iterate through collection and find distance,
    std::map<std::string, cModule*>::iterator it;

    for(it = allNodes.begin(); it != allNodes.end(); it++)
    {
        TraCIMobility* auxMobility = TraCIMobilityAccess().get(it->second);
        veins::Coord receiverPosition = auxMobility->getPositionAt(simTime());

        //returns distance in meters
        double dist = myPosition.distance(receiverPosition);
        EV << "Distance: " << dist << endl;
    }
}

关键变化在于 getPositionAt(simTime()) 方法.

The key change is in the getPositionAt(simTime()) method.

另外一条评论,如this 如果将此数据用于实际模拟目的,则发布在模拟中获取所有车辆的方法是一种不好的做法,因为很少有可能在一个时间步长中获取所有位置.就我而言,我仅将其用于评估目的.

One additional comment, as discussed in this post the method of obtain all vehicles in simulation is a bad practice if this data is used for realistic simulation purposes, because it is rarely possible to obtain all positions in one time step. In my case, I used it for only evaluation purposes.

这篇关于特定范围内的节点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆