Algorithm 相关网络实现

Algorithm 相关网络实现,algorithm,boost,graph,graph-algorithm,minimum-spanning-tree,Algorithm,Boost,Graph,Graph Algorithm,Minimum Spanning Tree,我一直在研究我的图形/网络问题,我想我终于知道我想做什么了。现在我已经开始实现了,我在决定使用什么库时遇到了一些问题。图本身非常简单,每个节点都用一个字符串标记,每个节点都是两个节点(变量)之间的概率/相关系数,并且是无向的。我要在图形上执行的操作有: 插入新节点/边(快速) 查找所有对的最短(1/概率)路径,并记住路径中的节点-可能是Johnson算法 构造k个特定顶点的最小权Steiner树 使用Johnson算法构建最短路径 迭代路径p中的当前节点,找到k中剩余节点的最短路径 看看图

我一直在研究我的图形/网络问题,我想我终于知道我想做什么了。现在我已经开始实现了,我在决定使用什么库时遇到了一些问题。图本身非常简单,每个节点都用一个字符串标记,每个节点都是两个节点(变量)之间的概率/相关系数,并且是无向的。我要在图形上执行的操作有:

  • 插入新节点/边(快速)
  • 查找所有对的最短(1/概率)路径,并记住路径中的节点-可能是Johnson算法
  • 构造k个特定顶点的最小权Steiner树
    • 使用Johnson算法构建最短路径
    • 迭代路径p中的当前节点,找到k中剩余节点的最短路径
  • 看看图的平均度数
  • 评估节点的介数
  • 获得聚类系数
  • 求图的模性
对于其中的许多,我想将结果与鄂尔多斯仁义模型进行比较,并将其作为无效假设进行检验。此外,能够通过马尔可夫场使用统计力学定义也会很有帮助,因为这样我可以计算两个不相同节点之间的相关性,并询问有关熵等的图形问题。因此,良好的映射到某种马尔可夫场库也会很有用

问题的症结在于我正在努力寻找一个C++库来工作。我已经看了R,但我想要的是更健壮、更快的东西。我正在考虑的三个图书馆是:

  • 柠檬
    • 易于使用和安装
    • 直观的文档
    • 已经有一些我想要的功能了
    • 通过读取文本文件动态创建图形,并确保没有重复的节点,这是一个我一直无法理解的噩梦
  • Boost图形库
    • 难以理解的对象定义,以及如何使用它们
    • 文档与代码不匹配,这是必然的
    • 它有许多我想要的算法,以及从文本文件创建图形的非常简单的方法
  • 多线程图形库
    • 已合并并行性
    • 比BGL更容易阅读
    • 没有那么多功能
    • 仍然神秘
沿着这条路走下去,我设想这个图形生活在一个分布式网络上,带有分布式存储(hadoop或其他东西)。我怀疑整个图形将无法放入内存,因此我必须提出一个缓存场景来查看图形的各个部分

对于我所描述的问题,人们会推荐什么图书馆?使用BGL并编写自己的函数会更好吗?多线程版本呢?有没有哪种库更适合我想做的工作,特别是我想计算的数量

谢谢

Edit1 所以我对BGL感到非常沮丧。我有一个邻接列表图,我想在图上运行我自己版本的Johnson(或Floyd,在这一点上,我并不挑剔),并返回距离矩阵供我查看。除了我不能让它工作。以下是我迄今为止的完整代码实现:

using namespace boost;

int main()
{
//Read in the file
std::ifstream datafile("stuff");
if (!datafile)
{
    std::cerr << "No Stuff file" << std::endl;
    return EXIT_FAILURE;
}

//Build the graph
typedef adjacency_list < vecS, vecS, undirectedS, property < vertex_name_t,
    std::string >, property < edge_weight_t, double > > Graph;
Graph g;

//Build the two properties we want, string and double
//Note, you have to nest properties for more
typedef property_map< Graph, vertex_index_t >::type vertex_index_map_t;
vertex_index_map_t vertex_index_map = get(vertex_index, g);
typedef property_map < Graph, vertex_name_t >::type name_map_t;
name_map_t name_map = get(vertex_name, g);
typedef property_map < Graph, edge_weight_t >::type probability_map_t;
probability_map_t probability = get(edge_weight, g);

//Map of of the vertices by string
typedef graph_traits < Graph >::vertex_descriptor Vertex;
typedef std::map < std::string, Vertex > NameVertexMap;
NameVertexMap AllNodes;

//Load the file into the graph
for (std::string line; std::getline(datafile, line);)
{
    char_delimiters_separator < char >sep(false, "", ";");
    tokenizer <> line_toks(line, sep);
    tokenizer <>::iterator i = line_toks.begin();
    std::string conditionA = *i++;
    NameVertexMap::iterator pos;
    bool inserted;
    Vertex u, v;

    boost::tie(pos, inserted) = AllNodes.insert(std::make_pair(conditionA, Vertex()));
    if (inserted)
    {
        u = add_vertex(g);
        name_map[u] = conditionA;
        pos->second = u;
    }
    else
    {
        u = pos->second;
    }

    std::string correlation = *i++;
    std::istringstream incorrelation(correlation);
    double correlate;
    incorrelation >> correlate;

    boost::tie(pos, inserted) = AllNodes.insert(std::make_pair(*i, Vertex()));
    if (inserted) {
        v = add_vertex(g);
        name_map[v] = *i;
        pos->second = v;
    }
    else
    {
        v = pos->second;
    }

    graph_traits < Graph >::edge_descriptor e;
    boost::tie(e, inserted) = add_edge(u, v, g);
    if (inserted)
        probability[e] = 1.0/correlate;
}

typedef boost::graph_traits<Graph>::edge_iterator edge_iter;
std::pair<edge_iter, edge_iter> edgePair;
Vertex u, v;
for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first)
{
    u = source(*edgePair.first, g);
    v = target(*edgePair.first, g);
    std::cout << "( " << vertex_index_map[u] << ":" << name_map[u] << ", ";
    std::cout << probability[*edgePair.first] << ", ";
    std::cout << vertex_index_map[v] << ":" << name_map[v] << " )" << std::endl;
}  
}
使用名称空间boost;
int main()
{
//读入文件
std::ifstream数据文件(“stuff”);
如果(!数据文件)
{
标准:cerr>图形;
图g;
//构建我们想要的两个属性:string和double
//注意,您必须嵌套属性以获取更多信息
typedef属性映射<图形,顶点索引映射>::键入顶点索引映射;
顶点索引映射顶点索引映射=get(顶点索引,g);
typedef属性映射<图形,顶点名称映射>::类型名称映射;
name\u map\u t name\u map=get(顶点名称,g);
typedef property_map<图,边_-weight_-t>::type probability_-map\t;
概率图概率=get(边权,g);
//通过字符串映射顶点
typedef graph_traits:顶点描述符顶点;
typedef std::mapNameVertexMap;
NameVertexMap所有节点;
//将文件加载到图形中
for(std::string行;std::getline(数据文件,行);)
{
字符分隔符分隔符sep(false,“,”;”);
令牌发生器线路(线路,sep);
标记器::迭代器i=line_toks.begin();
std::string conditionA=*i++;
NameVertexMap::迭代器pos;
布尔插入;
顶点u,v;
boost::tie(pos,inserted)=所有节点。insert(std::make_pair(conditionA,Vertex());
如果(插入)
{
u=添加_顶点(g);
name_map[u]=conditionA;
pos->second=u;
}
其他的
{
u=位置->秒;
}
std::string correlation=*i++;
std::istringstream不相关(相关);
双重关联;
不相关>>相关;
boost::tie(pos,inserted)=所有节点。insert(std::make_pair(*i,Vertex());
如果(插入){
v=添加顶点(g);
name_map[v]=*i;
pos->second=v;
}
其他的
{
v=位置->秒;
}
图形特征<图形>::边描述符e;
boost::tie(e,inserted)=添加_边(u,v,g);
如果(插入)
概率[e]=1.0/相关;
}
typedef boost::graph_traits::edge_迭代器edge_iter;
标准:对边pair;
顶点u,v;
对于(edgePair=边(g);edgePair.first!=edgePair.second;++edgePair.first)
{
u=来源(*边空气优先,g);
v=目标(*边缘第一,g);
标准::cout