vertex_occupancy_t blallaglalalalahaia…

Creating tag types for properties :

enum vertex_occupancy_t { vertex_occupancy };
namespace boost {
BOOST_INSTALL_PROPERTY(vertex, occupancy);}

Use new property tag in the definition of properties:

typedef property<vertex_occupancy_t, int> Occ;

Create a typedef for the Graph type, bidirectionalS means undirected graph:

typedef adjacency_list<vecS, vecS, bidirectionalS, Occ> GraphCG;

Get the property map for vertex indices:

typedef property_map<GraphCG, vertex_occupancy_t>::type StatusVertex;

Declaring the graph object:

GraphCG g(num_vertices);
StatusVertex status = get(vertex_occupancy, g);

Adding the edges to the graph object:

for (int i = 0; i < num_edges; ++i)
   add_edge(edge_array[i].first, edge_array[i].second, g);

The property maps for these properties can be obtained from the graph via the get(Property, g) function:

property_map<GraphCG, vertex_occupancy_t>::type occupancy
= get(vertex_occupancy, g);

Setting occupancy for vertex:

put(occupancy, 3, 9);
put(occupancy, 9, 3);
occupancy[2] = 7; // you can use operator[] too

Accesing the vertex set:

typedef graph_traits<GraphCG>::vertex_iterator vertex_iter;
cout << "vertices(g) occupancy status = ";
pair<vertex_iter, vertex_iter> vp;  //first iterator points to the beginning,
                                    //second iterator points "past the end" of the vertices
for (vp = vertices(g); vp.first != vp.second; ++vp.first)
    cout << status[*vp.first] << " ";
Advertisements