Boost logo

Boost Users :

From: Juergen (juergen.duerrwang_at_[hidden])
Date: 2019-07-19 12:38:28


Sorry in my last post, the code was not insert...

Hello, everybody,
I have followed your conversation and since I have a similar problem, I
would be happy if you could help me. At the moment I am really lost. The
problem is to create the color map that can be used in Depth_First_Search. A
special feature that I have is that I want to change the Vertex color of DFS
to modify the DFS. For example like this:

template < typename Vertex, typename Graph >
        void finish_vertex(Vertex u, const Graph & g)
        {
                diGraph::vertex_descriptor vertex;
                vertex = boost::vertex(u, g);

                if (u == m_destination)
                {
                        *m_result = true;
                        //save current path
                        m_allPaths->insert(std::make_pair(m_numPaths, m_spath));
                        m_numPaths++;
                }

                if (u == m_source)
                {
                        for (auto vd : boost::make_iterator_range(vertices(g)))
                        {
                                vertex_coloring[vd] = boost::black_color;
                        }
                }
        }

If I make the color map global and pass it to the visitor, everything works:

//global version (working)
typedef boost::property< boost::vertex_name_t, std::string,
boost::property<boost::vertex_index_t, int> > vertex_properties;
typedef boost::property< boost::edge_weight_t, float,
boost::property<boost::edge_index_t, int > > edge_properties;
typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS,
vertex_properties, edge_properties> diGraph;

//global version (working)
typedef std::map<diGraph::vertex_descriptor, default_color_type> colormap;
colormap vertex_coloring;

my_vis vis(0, 3, &foundDestination, &tempPaths);
//global version (working version)
//depth_first_search(ee_archi, vis,
boost::make_assoc_property_map(vertex_coloring),0);

If the color map is not global but external, I can write the map, but it is
not the same as the DFS color map and therefore I cannot manipulate the DFS
algorithm:

//external map
typedef boost::property< boost::vertex_color_t, boost::default_color_type>
color_properties;
typedef boost::property< boost::vertex_name_t, std::string,
boost::property<boost::vertex_index_t, int > > vertex_properties;
typedef boost::property< boost::edge_weight_t, float,
boost::property<boost::edge_index_t, int > > edge_properties;
typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS,
vertex_properties, edge_properties, color_properties> diGraph;

struct my_vis : default_dfs_visitor {
        //internal map
        using colormap = std::map<diGraph::vertex_descriptor, default_color_type>;
        colormap vertex_coloring;
….};

//not working
my_vis vis(0, 3, &foundDestination, &tempPaths);
depth_first_search(ee_archi, vis,
boost::make_assoc_property_map(vis.vertex_coloring),0);

I then tried to create an internal map and work with the get() and put()
functions, but I didn't succeed:

//internal map
typedef boost::property< boost::vertex_name_t, std::string,
boost::property<boost::vertex_index_t, int, boost::property&lt;
boost::vertex_color_t, boost::default_color_type> > > vertex_properties;
typedef boost::property< boost::edge_weight_t, float,
boost::property<boost::edge_index_t, int > > edge_properties;
typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS,
vertex_properties, edge_properties> diGraph;

I'd be so grateful if you'd give me a hint.

--
Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html

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