This is the two classes I have
class Graph
{
private:
unordered_map<int, Vertex> _vertices;
};
class Vertex
{
private:
unordered_map<Vertex *, int> _edges;//key: pointer to a vertex, data: edge weight from this vertex to a certain vertex
int _load_factor = 0;
int _id = 0;
};
If I want to use Dijkstra's algorithm to compute the shortest path from a certain pass, I need to use a priority queue. I have no Idea how can I write a comparator class for:
priority_queue<Vertex, vector<Vertex>, PathWeightComparer> dijkstra_queue{};
This is what I found online:
class PathWeightComparer
{
public:
bool operator()(Vertex lhs, Vertex rhs)
{
return (lhs.getPathWeight() > rhs.getPathWeight());
}
};
What is lhs and rhs refer to? Is it the vertices from the priority_queue
? If so to get a path weight for this comparison, I need to know where from to factors. Can I just create a new variable name _path_weight
and only use it for findShortestPath()
? The main thing I don't understand is the notion of lhs and rhs, what are they? One more thing, my current comparator class will result in max heap or min heap?
Thank you so much