Сохранение непараллельного граничного графа в файл graphml с использованием boost

В следующем коде сохраните график в файл graphml. Оно работает!. Но когда я заменяю typedef adjacency_list< vecS, vecS, directedS, с typedef adjacency_list< setS, setS, directedS, так что никакая дублирующая вершина или ребро не вставляются в граф, он жалуется.

#include <boost/graph/graphml.hpp>

using namespace std;
typedef struct {
string name;
string label;
} vertex_type_t;

int main(int,char*[])
{

using namespace boost;

typedef adjacency_list< vecS, vecS, directedS,
vertex_type_t > graph_t;

graph_t g;
graph_t::vertex_descriptor v1 = add_vertex(g);
graph_t::vertex_descriptor v2 = add_vertex(g);

dynamic_properties dp;
dp.property("name", get(&vertex_type_t::name, g));

write_graphml(std::cout, g, dp, true);

return 0;
}

Я не могу многое сделать из ошибки. Я считаю, что следующее является основной ошибкой.

/usr/include/boost/graph/graphml.hpp: In function ‘void boost::write_graphml(std::ostream&, const Graph&, VertexIndexMap, const boost::dynamic_properties&, bool) [with Graph = boost::adjacency_list<boost::setS, boost::setS, boost::directedS, vertex_type_t>, VertexIndexMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::setS, boost::directedS, vertex_type_t>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>, std::ostream = std::basic_ostream<char>]’:
/usr/include/boost/graph/graphml.hpp:345:5:   instantiated from ‘void boost::write_graphml(std::ostream&, const Graph&, const boost::dynamic_properties&, bool) [with Graph = boost::adjacency_list<boost::setS, boost::setS, boost::directedS, vertex_type_t>, std::ostream = std::basic_ostream<char>]’
write_graphviz.cpp:24:39:   instantiated from here
/usr/include/boost/graph/graphml.hpp:301:9: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits<char>]((* & out), ((const char*)"    <node id=\"n")) << boost::get [with PropertyMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::setS, boost::directedS, vertex_type_t>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>, Reference = const boost::detail::error_property_not_found&, K = void*]((*(const boost::put_get_helper<const boost::detail::error_property_not_found&, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::setS, boost::directedS, vertex_type_t>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)(& vertex_index)), (* & v.std::_Rb_tree_const_iterator<_Tp>::operator* [with _Tp = void*, std::_Rb_tree_const_iterator<_Tp>::reference = void* const&]()))’
/usr/include/boost/graph/graphml.hpp:301:9: note: candidates are:
/usr/include/c++/4.6/ostream:110:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/include/c++/4.6/ostream:110:7: note:   no known conversion for argument 1 from ‘const boost::detail::error_property_not_found’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/4.6/ostream:119:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>, std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]

Я действительно хочу использовать setS в качестве пограничных контейнеров. Я не уверен, как изменить эту программу так, чтобы она начала работать, так как сообщение об ошибке не имеет особого смысла для меня.

1

Решение

Проблема в том, что write_graphml требует VertexIndexMap в вашем графике и только adjacency_listс VertexList=vecS один создан по умолчанию. Вы должны создать его самостоятельно, если вы используете listS или же setS,

Я действительно хочу использовать setS в качестве пограничных контейнеров.

Если вам нужно только использовать setS в вашем OutEdgeList Вы можете просто использовать:

typedef adjacency_list< setS, vecS, directedS,
vertex_type_t > graph_t;

Если вы должны использовать setS для обоих, то ваша программа должна быть (на основе этот ответ):

#include <boost/graph/graphml.hpp>
#include <boost/graph/iteration_macros.hpp>

#include <map>

using namespace std;
typedef struct
{
string name;
string label;
} vertex_type_t;

int main ( int, char*[] )
{

using namespace boost;

typedef adjacency_list < setS, vecS, directedS,
vertex_type_t > graph_t;

typedef graph_t::vertex_descriptor NodeID; //define your Vertex Index Map
typedef std::map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
boost::associative_property_map<IndexMap> propmapIndex ( mapIndex );

graph_t g;
graph_t::vertex_descriptor v1 = add_vertex ( g );
graph_t::vertex_descriptor v2 = add_vertex ( g );

int i = 0;                                  //fill your Vertex Index Map
BGL_FORALL_VERTICES ( v, g, graph_t )
{
put ( propmapIndex, v, i++ );
}

g[v1].name="FirstVertex";
g[v2].name="SecondVertex";

dynamic_properties dp;
dp.property ( "name", get ( &vertex_type_t::name, g ) );

write_graphml ( std::cout, g, propmapIndex, dp, true );

return 0;
}
3

Другие решения

Моя первая мысль заключается в том, что новый тип графов (с setS) не удовлетворяет требованиям к функции write_graphml (..): http://www.boost.org/doc/libs/1_51_0/libs/graph/doc/write_graphml.html

В нем говорится, что «тип графа должен быть моделью VertexListGraph». который он описал здесь: http://www.boost.org/doc/libs/1_51_0/libs/graph/doc/VertexListGraph.html

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector