如何输出一个有向图在graphml格式
How to output a directed graph in graphml format?
如何将下面的图形输出到graphml中?
typedef struct Vertex{ std::string name; std::string cmdb_id;
Vertex& operator= (const Vertex& rhs)
{
if (this == &rhs)
return *this;
name = rhs.name;
cmdb_id = rhs.cmdb_id;
}
bool operator< (const Vertex& rhs) const
{
return cmdb_id < rhs.cmdb_id;
};
bool operator== (const Vertex& rhs) const
{
return ((cmdb_id == rhs.cmdb_id) && (name == rhs.name));
};
}vertex_container;
typedef struct Edge {std::string name;} edge_container;
boost::directed_graph<vertex_container, edge_container> Graph g;
这是另一个不使用c++11特性的版本:
#include <iostream>
#include <boost/graph/directed_graph.hpp>
#include <boost/graph/graphml.hpp>
typedef struct Vertex
{
std::string name;
std::string cmdb_id;
Vertex& operator= (const Vertex& rhs)
{
if (this == &rhs)
return *this;
name = rhs.name;
cmdb_id = rhs.cmdb_id;
}
bool operator< (const Vertex& rhs) const
{
return cmdb_id < rhs.cmdb_id;
};
bool operator== (const Vertex& rhs) const
{
return ((cmdb_id == rhs.cmdb_id) && (name == rhs.name));
};
}vertex_container;
typedef struct Edge {std::string name;} edge_container;
typedef boost::directed_graph<vertex_container, edge_container> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
int main()
{
Graph g;
vertex_container A, B;
edge_container AB;
A.name="A";
A.cmdb_id="1";
B.name="B";
B.cmdb_id="2";
AB.name="A-B";
vertex_descriptor v0 = g.add_vertex(A);
vertex_descriptor v1 = g.add_vertex(B);
g.add_edge(v0,v1,AB);
boost::dynamic_properties dp;
dp.property("vertex_name",get(&vertex_container::name,g));
dp.property("vertex_cmdb_id",get(&vertex_container::cmdb_id,g));
dp.property("edge_name",get(&edge_container::name,g));
write_graphml(std::cout, g, dp);
}
#include <iostream>
#include <boost/graph/directed_graph.hpp>
#include <boost/graph/graphml.hpp>
typedef struct Vertex
{
std::string name;
std::string cmdb_id;
Vertex& operator= (const Vertex& rhs)
{
if (this == &rhs)
return *this;
name = rhs.name;
cmdb_id = rhs.cmdb_id;
}
bool operator< (const Vertex& rhs) const
{
return cmdb_id < rhs.cmdb_id;
};
bool operator== (const Vertex& rhs) const
{
return ((cmdb_id == rhs.cmdb_id) && (name == rhs.name));
};
}vertex_container;
typedef struct Edge {std::string name;} edge_container;
typedef boost::directed_graph<vertex_container, edge_container> Graph;
int main()
{
Graph g;
auto v0 = g.add_vertex({"A","1"});
auto v1 = g.add_vertex({"B","2"});
g.add_edge(v0,v1,{"A-B"});
boost::dynamic_properties dp;
dp.property("vertex_name",get(&vertex_container::name,g));
dp.property("vertex_cmdb_id",get(&vertex_container::cmdb_id,g));
dp.property("edge_name",get(&edge_container::name,g));
write_graphml(std::cout, g, dp);
}
相关文章:
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- C++创建指向有向图中节点的指针数组
- 如何仅在 2 个节点之间获取最短路径,给定邻接列表有向图?
- 有向图 - 如何计算图中彼此顶点可到达的顶点数?
- C++计算有向图中的最短路径
- 使用非递归 DFS 检测有向图中的周期
- 如何将这些节点连接为有向图
- 如何使用广度优先搜索确定是否可以在有向图中到达顶点
- 在有向图中精确访问所有节点一次
- 在有向图中查找第二条最短路径
- 关于如何处理有向图的一个想法
- 找到有向图C 的最短路径
- 分析输入文件以创建有向图C++
- 在使用无序多映射实现的有向图中查找循环
- 如何找到在c++中实现的有向图的所有路径作为邻接列表
- 如何创建具有多个数据的节点的有向图
- 有向图中的广度优先搜索
- 查找路径的有向图邻接矩阵
- 从文件构建有向图
- 如何输出一个有向图在graphml格式