Comparing 2 graphs created by Boost Graph Library
By : Brian Pedersen
Date : March 29 2020, 07:55 AM

Find all linesegments=edges within a certain distance to a point in a graph, how to combine boostgraph with boostgeome
By : Mahmoud Hamdy
Date : March 29 2020, 07:55 AM
Hope this helps It is certainly possible to attach properties to linestrings in Boost.Geometry, actually Boost.Geometry is made for doing such things. You can just derive from boost::geometry::model::linestring, or implement any other rangebased structure (e.g. std::vector) and register that as a linestring. See the c03 example. For the relation with Boost.Graph, see one of the examples in Boost.Geometry: 07_a or 07_b where a similar thing is done. What is done there is storing a Boost.Geometry linestring into the Boost.Graph edge (with a property), together with other properties, so that is another way of doing this.

DFS in boost::graph with changing the graphs content
By : 이은미
Date : March 29 2020, 07:55 AM
With these it helps Have a look at how Boost implements connected_components. In order to store the component id the following visitor is used: code :
// This visitor is used both in the connected_components algorithm
// and in the kosaraju strong components algorithm during the
// second DFS traversal.
template <class ComponentsMap>
class components_recorder : public dfs_visitor<>
{
typedef typename property_traits<ComponentsMap>::value_type comp_type;
public:
components_recorder(ComponentsMap c,
comp_type& c_count)
: m_component(c), m_count(c_count) {}
template <class Vertex, class Graph>
void start_vertex(Vertex, Graph&) {
if (m_count == (std::numeric_limits<comp_type>::max)())
m_count = 0; // start counting components at zero
else
++m_count;
}
template <class Vertex, class Graph>
void discover_vertex(Vertex u, Graph&) {
put(m_component, u, m_count);
}
protected:
ComponentsMap m_component;
comp_type& m_count;
};
template <class PropertyMap>
struct vertex_visitor : public boost::dfs_visitor<>
{
PropertyMap m_pmap;
vertex_visitor(PropertyMap pmap) : m_pmap(pmap) {}
template <class Vertex, class Graph>
void discover_vertex(Vertex v, const Graph& g)
{
boost::put(m_pmap, v, 42);
}
};
typedef boost::property_map<graph_t, int vertex::*>::type NumbersProperty;
vertex_visitor<NumbersProperty> vis(boost::get(&vertex::number, g));

Graphs  Python  Store a graph db made of graphs  Graph db theory
By : user2476288
Date : March 29 2020, 07:55 AM
will help you You did not label "J" in your diagram, so I will ignore it (and HELLO, whatever that is) in this answer. [EDITED] code :
(foo:Subgraph {name: "Foo"})
(bar:Subgraph {name: "Bar"})
(world:Subgraph {name: "World"})
(foo)[:MEMBER]>(a)
(foo)[:MEMBER]>(b)
(foo)[:MEMBER]>(c)
(bar)[:MEMBER]>(x)
(bar)[:MEMBER]>(y)
(bar)[:MEMBER]>(z)
(world)[:MEMBER]>(harry)
(world)[:MEMBER]>(terry)
(world)[:MEMBER]>(jerry)
(c)[rel1]>(z)
(harry)[rel2]>(bar)

Boost Undirected Graph Merging Vertices
By : user3414526
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I don't know what you're actually trying to achieve with the algorithm shown in the OP. Here's, however, one that simplifies the code considerably, so that at least it works safely: code :
#include <boost/graph/adjacency_list.hpp>
#include <iostream>
struct Vertex {
int id;
const char* name;
Vertex(int i = 1, const char* name = "default") : id(i), name(name) {}
};
template <typename It> boost::iterator_range<It> mir(std::pair<It, It> const& p) {
return boost::make_iterator_range(p.first, p.second);
}
template <typename It> boost::iterator_range<It> mir(It b, It e) {
return boost::make_iterator_range(b, e);
}
typedef typename boost::adjacency_list<
boost::vecS, boost::vecS,
boost::undirectedS,
Vertex, // bundled properties (id, name)
boost::property<boost::edge_weight_t, float> // interior property
> Graph;
Graph make() {
Graph graph;
auto Jeanie = add_vertex(Vertex { 0, "Jeanie" }, graph);
auto Debbie = add_vertex(Vertex { 1, "Debbie" }, graph);
auto Rick = add_vertex(Vertex { 2, "Rick" }, graph);
auto John = add_vertex(Vertex { 3, "John" }, graph);
auto Amanda = add_vertex(Vertex { 4, "Amanda" }, graph);
auto Margaret = add_vertex(Vertex { 5, "Margaret" }, graph);
auto Benjamin = add_vertex(Vertex { 6, "Benjamin" }, graph);
add_edge(Jeanie, Debbie, 0.5f, graph);
add_edge(Jeanie, Rick, 0.2f, graph);
add_edge(Jeanie, John, 0.1f, graph);
add_edge(Debbie, Amanda, 0.3f, graph);
add_edge(Rick, Margaret, 0.4f, graph);
add_edge(John, Benjamin, 0.6f, graph);
return graph;
}
Graph reduce(Graph graph) {
/* vertex iterator */
using vertex_descriptor = boost::graph_traits<Graph>::vertex_descriptor;
std::cout << "# of vertices: " << num_vertices(graph) << "\n";
std::cout << "# of edges: " << num_edges(graph) << "\n";
std::set<vertex_descriptor> to_remove;
/* iterator throught the graph */
for (auto self : mir(vertices(graph)))
{
std::cout << graph[self].name << (boost::empty(mir(out_edges(self, graph)))? " has no children " : " is the parent of ");
for(auto edge : mir(out_edges(self, graph))) {
auto weight = boost::get(boost::edge_weight, graph, edge);
auto mid_point = target(edge, graph);
if (to_remove.count(mid_point)) // already elided
break;
if (weight > 0.3f) {
std::set<vertex_descriptor> traversed;
for (auto hop : mir(out_edges(mid_point, graph))) {
auto hop_target = target(hop, graph);
if (hop_target != self)
add_edge(self, hop_target, graph);
std::cout << "\n DEBUG: " << graph[self].name << " " << graph[mid_point].name << " " << graph[hop_target].name << " ";
}
std::cout << "\n";
clear_vertex(mid_point, graph);
to_remove.insert(mid_point);
}
std::cout << graph[mid_point].name;
}
std::cout << "\n\n";
}
for(auto vd : to_remove)
{
clear_vertex(vd, graph);
remove_vertex(vd, graph);
}
std::cout << "# of vertices: " << num_vertices(graph) << "\n";
std::cout << "# of edges: " << num_edges(graph) << "\n";
return graph;
}
void save(Graph const& g, const char* fname);
int main() {
auto const g = make();
auto const h = reduce(g);
save(g, "before.dot");
save(h, "after.dot");
}
#include <boost/graph/graphviz.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/property_map/function_property_map.hpp>
#include <boost/property_map/transform_value_property_map.hpp>
#include <boost/format.hpp>
#include <fstream>
void save(Graph const& g, const char* fname) {
std::ofstream ofs(fname);
using namespace boost;
write_graphviz(
ofs,
g,
make_label_writer(make_function_property_map<Graph::vertex_descriptor, std::string>([&] (Graph::vertex_descriptor v){ return g[v].name; })),
make_label_writer(make_transform_value_property_map([](float v){return boost::format("%1.1f") % v;}, boost::get(edge_weight, g)))
);
}
# of vertices: 7
# of edges: 6
Jeanie is the parent of
DEBUG: Jeanie Debbie Jeanie
DEBUG: Jeanie Debbie Amanda
DebbieJohnAmanda
Debbie has no children
Rick is the parent of Jeanie
DEBUG: Rick Margaret Rick
Margaret
John is the parent of Jeanie
DEBUG: John Benjamin John
Benjamin
Amanda is the parent of Jeanie
Margaret has no children
Benjamin has no children
# of vertices: 4
# of edges: 3

