|
Boost Users : |
Subject: Re: [Boost-users] Confused with BGL-- Six Degrees of KevinBaconexample
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2013-05-30 13:32:35
On Fri, 31 May 2013, lizy10b wrote:
> Dear Jeremiah Willcock,
> Thanks for your explanations.
> I think I am starting to walk out of the chaos...
> For the adjacency_list, there isn't an edge_index property.Â
> That means the edge_index property is not used by the
> graph internally, but could be used by user just like the edge_weight or edge_name, and these property should be assgined by user manually.
> So in the examples "exterior_properties.cpp", I could replace all the strings "edge_index" with "edge_weight", and doing this will not affect the result.
Yes, except that algorithms that create their own external property maps
on edges (I don't know if there are any) would by default use the name
edge_index_t, and you would need to pass in a different property map as an
argument to use it instead.
> The property map works in this case beacuse the edge_index property is type of int, and the value of the edge_index property
> is the offset to the beginning of the underlying property containers (int capacity[] and int flow[]).
> And the whole mapping process when calling the "boost::get(capacity, *out)" includes two mappings:
> Frist mapping: KEY=*out (edge descriptor)-->VALUE = offset value (int)
> Second mapping: KEY=offset value (int) --> VALUE= the corresponding property value
> Am I right?
Yes, that's exactly how it works. For put(), the first mapping is the
same, while the second one writes to the array at the offset instead of
reading from it.
-- Jeremiah Willcock
> Â
> Â
> "exterior_properties.cpp":
> typedef boost::adjacency_list<boost::vecS, boost::vecS,Â
>     boost::bidirectionalS, boost::no_property,Â
>     boost::property<boost::edge_index_t, std::size_t> > Graph;
> int capacity[] = { 10, 20, 20, 20, 40, 40, 20, 20, 20, 10 };
> int flow[] = { 8, 12, 12, 12, 12, 12, 16, 16, 16, 8 };
> boost::add_edge(0, 1, 0, G);Â
> boost::add_edge(1, 4, 1, G);
> ...
> typedef boost::property_map<Graph, boost::edge_index_t>::type EdgeIndexMap;
> EdgeIndexMap edge_id = boost::get(boost::edge_index, G);
> boost::iterator_property_map <int*, EdgeIndexMap, int, int&>
>   capacity_array(capacity, edge_id), flow_array(flow, edge_id);
> print_network(G, capacity_array, flow_array);
> inside the function print_network:Â
> boost::get(capacity, *out) ...
> Â
> Â
>
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net