Debugging graphs can sometimes be annoying a useful way is to visualise it. No problem Boost has not only a graph solution but a way to visualise it too.
It is really simple first the header,
#include <boost/graph/graphviz.hpp>
Define the name of each node, easily done by an array
const std::string names [] = {"A", "B", "C", "D", "E" } ;
or via a vector
std::vector<std::string> names;
for (int i = 0 ; i < _nodes.size() ; i++){
std::stringstream ss;
names.push_back(ss.str());
}
Then save it out
std::ofstream dmp;
dmp.open("dmp.dot");
boost::write_graphviz(dmp,g, boost::make_label_writer(&names[0]));
And then the result:
Left undirected graph, right directed hence the arrow heads.
Stuart James …
Assistant Professor in Visual Computing at Durham University. Stuart's research focus is on Visual Reasoning to understand the layout of visual content from Iconography (e.g. Sketches) to 3D Scene understanding and their implications on methods of interaction. He is currently a co-I on the RePAIR EU FET, DCitizens EU Twinning, and BoSS EU Lighthouse. He was a co-I on the MEMEX RIA EU H2020 project coordinated at IIT for increasing social inclusion with Cultural Heritage. Stuart has previously held a Researcher & PostDoc positions at IIT as well as PostDocs at University College London (UCL), and the University of Surrey. Also, at the University of Surrey, Stuart was awarded his PhD on visual information retrieval for sketches. Stuart holds an External Scientist at IIT, Honorary roles UCL and UCL Digital Humanities, and an international collaborator of ITI/LARSyS. He also regularly organises Vision for Art (VISART) workshop and Humanities-orientated tutorials and was Program Chair at British Machine Conference (BMVC) 2021.