How to create a map to insert elements based on an event

Hello All,
I need a help to create a map of vehicle ID, pedestrian ID and its corresponding distance from vehicle and then to find the minimum distance for a particular vehicle. Something like the following:
VehID PedID Distance
0 0 X0
0 1 X1
0 2 X2
1 0 Y0
1 1 Y1
1 2 Y2 and so on..

I get each of these entries in different time based on events, like:
Event #1 at time t1 (Pedestrian_ID:0 have distance of X0 from Vehicle_ID:0)
Event #2 at time t2 (Pedestrian_ID:1 have distance of X1 from Vehicle_ID:0)
and so on....

I want to create a map so that it can store each line of entry and keep appending for next entries according to next events. Finally at the last event I should get the full map with all the entries
Then I need to find:
The pedestrian which has the minimum distance from Vehicle_ID:0
The pedestrian which has the minimum distance from Vehicle_ID:1 and so on..

I have started with this code as below:
 
std::map <int vehicle_ID std::map<<int pedestrian_ID, double distance>> my_Map;


But I am not able to find, how to add subsequent entries based on events generated at different time and to store them.

Thanks
Last edited on
Rather than go down the container within a container route you can keep things more simple by designing classes/structs to capture the information that you need. For eg, based on what you've written but without seeing the actual assignment, such a struct might look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
struct Pedestrian{};
struct Vehicle{};//forward declarations
struct Event
{
	double m_time;
	Pedestrian m_ped;
	Vehicle m_vehc;
};
struct Pedestrian
{
	string m_name;
	double m_x_p;
	double m_y_p;//since you are measuring distance I suppose you need some form of co-ordinates;

	Pedestrian(string name, double x_p, double y_p) : m_name(name), m_x_p(x_p), m_y_p(y_p) {}
	//I have taken the relatively straight-forward approach of getting all Pedestrian details through the ctor, you can also have getters if you wish
};
struct Vehicle
{
	string m_vehc-id;
	double m_x_v;
	double m_y_v;

	Vehicle(string vehc-id, double x_v, double y_v) : m_vehc-id(vehc-id), m_x_v(x_v), m_y_v(y_v) {}
};

So now each event object would have all the information requried and you can create vector<Event> to capture all events. Then for any vehicle you can iterate over the vector to see which pedestrian was closest and so on.



Last edited on
Thank you, I am trying that.
Topic archived. No new replies allowed.