Reputation: 149
I am trying to learn Boost Graph library and came across an example called "Six Degrees of Kevin Bacon". Here is the URL https://www.boost.org/doc/libs/1_61_0/libs/graph/doc/kevin_bacon.html
In that example, I see:
...
boost::tie(pos, inserted) = actors.insert(std::make_pair(actors_name, Vertex()));
...
What does Vertex()
refer to?
I see an alias called Vertex
a few lines above the Vertex()
like below but I am not understanding what Vertex()
is for:
typedef graph_traits<Graph>::vertex_descriptor Vertex;
Can someone please help me understand this one? I am new to Boost and feel like I am already lost!
The documentation is very difficult to read through and understand.
Thanks.
Upvotes: 0
Views: 116
Reputation: 117238
The Vertex (graph theory) is used to record an actor's connections to other actors. They are directly connected if they have appeared in the same movie.
The Vertex used in the example is described here: boost::graph_traits<Graph>
This line:
boost::tie(pos, inserted) = actors.insert(std::make_pair(actors_name, Vertex()));
tries to insert a pair
with the actor's name and a default constructed (empty) Vertex
. If it fails (inserted==false
), it's because the actor was already present and pos
will be pointing at the existing pair
with a Vertex
that already has at least one connection. If it succeeds pos
will point at the newly inserted pair
with an empty Vertex
.
The add_edge
step later on is what connects the two actors. When the file has been processed you'll have a graph of how all the actors in the file are connected (via edges).
Upvotes: 2