I am making a graph using an adjacency list represented by a map with Vertex keys, and a map of weighted edges as a value. This looks like so:
map<Vertex, map<Vertex, double> > m;
The program loads a set of verticies an edges from a file in to this. Then I have to use Dijkstra's shortest path algorithm, given a starting an ending node in the Graph. In order to do this, you need to store certain attributes for each vertex, such as the min_distance and a pointer to the previous_node (so that you can trace the path after the algorithm finishes). The question is, how do I make it so that the keys' attributes in the vertex map are modifiable?
Selecting a key using an iterator and changing a variable in the Vertex object did not reflect any change.
map<Vertex, map<Vertex,double> >::iterator i;
i = m.find(Vertex);
Vertex v = i->first;
v.min_dist = 2;
v.prevNode = pnode; // this would point to a vertex obtained in a similar fashon to v
I can't get that to work, and am wasting space storing it in a separate map<Vertex,distance> and map<Vertex,prevNode> right now, there has to be a smarter way.