hello all,
 
we are trying to use a DFS visitor in a similar way as the BFS visitor which is used in the example "bfs.cpp" (boost 1.31.0), that is the code, but it complains about a lot of errors in the internal boost library files...
 

#include <boost/config.hpp>

#include <assert.h>

 

#include <vector>

#include <algorithm>

#include <utility>

#include <iostream>

#include <boost/graph/adjacency_list.hpp>

#include <boost/graph/depth_first_search.hpp>

#include <boost/graph/visitors.hpp>

#include <boost/property_map.hpp>

#include <boost/graph/graph_utility.hpp>

 

using namespace boost;

using namespace std;

 

 

 

// visitor que muestra el orden en que se encuentran los arcos

template <class NewGraph, class Tag>

struct muestra_orden

: public boost::base_visitor<muestra_orden<NewGraph, Tag> >

{

typedef Tag event_filter;

muestra_orden(NewGraph& graph) : new_g(graph) { }

template <class Edge, class Graph>

void operator()(Edge e, Graph& g) {

cout << "arco: " << e << endl;

}

private:

NewGraph& new_g;

};

template <class NewGraph, class Tag>

inline muestra_orden<NewGraph, Tag>

MuestraOrden(NewGraph& g, Tag) {

return muestra_orden<NewGraph, Tag>(g);

}

//**************************************************************************+

template <class NewGraph, class Tag>

struct muestra_ordenV

: public boost::base_visitor<muestra_ordenV<NewGraph, Tag> >

{

typedef Tag event_filter;

muestra_ordenV(NewGraph& graph) : new_g(graph) { }

template <class Vertex, class Graph>

void operator()(Vertex v, Graph& g) {

cout << "ARCO: " << v << endl;

}

private:

NewGraph& new_g;

};

template <class NewGraph, class Tag>

inline muestra_ordenV<NewGraph, Tag>

MuestraOrdenV(NewGraph& g, Tag) {

return muestra_ordenV<NewGraph, Tag>(g);

}

/********************************************************/

int main(int , char* [])

{

using namespace boost;

typedef boost::adjacency_list<

boost::mapS, boost::vecS, boost::undirectedS,

boost::property<boost::vertex_color_t, boost::default_color_type,

boost::property<boost::vertex_degree_t, int,

boost::property<boost::vertex_in_degree_t, int,

boost::property<boost::vertex_out_degree_t, int> > > >

> Graph;

Graph G(11);

boost::add_edge(5, 6, G);

boost::add_edge(0, 1, G); // 0 es el +

boost::add_edge(1, 2, G);

boost::add_edge(1, 3, G);

boost::add_edge(2, 4, G);

boost::add_edge(3, 5, G);

boost::add_edge(4, 6, G);

boost::add_edge(5, 7, G); // 7 es el -

boost::add_edge(5, 10, G);

boost::add_edge(10, 11, G);

boost::add_edge(11, 12, G);

typedef graph_traits<Graph>::vertex_descriptor Vertex;

typedef graph_traits<Graph>::vertices_size_type size_type;

Graph G_copy(11);

size_type d[11];

std::vector<Vertex> p(num_vertices(G));

std::fill_n(d,11,0);

Vertex s=7;

p[s]=s;

boost::depth_first_search (G,

visitor(boost::make_dfs_visitor(

std::make_pair(boost::record_predecessors(&p[0],boost::on_tree_edge()),

std::make_pair(MuestraOrdenV(G_copy,boost::on_finish_vertex()),

MuestraOrden(G_copy, boost::on_tree_edge())))) ),

s); // we can compile the visitor(...) clause alone, but not inside depth_first_search (...) clause.

return 0;

}

 

thanks a lot

Gus



Nuevo Yahoo! Búsquedas