gpt4 book ai didi

c++ - Lemon Graph Library C++ - 使用循环添加节点

转载 作者:太空狗 更新时间:2023-10-29 23:18:44 34 4
gpt4 key购买 nike

是否有可能在 C++ 中使用循环创建柠檬图?

我的问题:

  1. 列为节点的数据库表(我们称之为 t_nodes)
  2. 带有图形信息的数据库表(我们称之为 t_edges):node1 |节点2 |边缘得分
  3. 超过 10000 个条目

我想要的结果:

  1. 有向图:例如N1 -> N2; N2 -> N3; N3 -> N1

我的问题

  1. 是否可以在 t_nodes 表中对每个条目使用一个循环将节点添加到图形

    • 到目前为止,我只是找到了他们手动添加每个节点的实现(参见下面的示例)
    • 真的没有机会使用循环向柠檬图添加节点吗?
  2. 如何对 t_edges 中提到的所有关系使用循环?

感谢您的宝贵时间,非常感谢您的帮助!


在周末有空闲时间并花了一些时间骑自行车后,我找到了解决方案:)

我的解决方案:

看来,柠檬并没有提供支持图形边缘附加信息的可能性。因此,我刚刚创建了一个额外的 vector 来存储这些信息。但是,出于某些目的,使用 HashMap 访问节点可能更明智。

看看开发的示例脚本(非常简单;))


柠檬 C++-代码示例(引用:http://lemon.cs.elte.hu/pub/tutorial/a00022.html):

 /* -*- mode: C++; indent-tabs-mode: nil; -*-
*
* This file is a part of LEMON, a generic C++ optimization library.
*
* Copyright (C) 2003-2010
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
*
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
*
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
* purpose.
*
*/


#include <iostream>
#include <lemon/list_graph.h>

using namespace lemon;
using namespace std;

int main()
{
ListDigraph g;


ListDigraph::Node u = g.addNode();
ListDigraph::Node v = g.addNode();
ListDigraph::Arc a = g.addArc(u, v);

cout << "Hello World! This is LEMON library here." << endl;
cout << "We have a directed graph with " << countNodes(g) << " nodes "
<< "and " << countArcs(g) << " arc." << endl;

return 0;


// Further development
ListDigraph graph;

vector <string> name;
name.push_back("A");
name.push_back("B");
name.push_back("C");

for (unsigned int n=0; n<name.size(); n++) {
ListDigraph::Node node = graph.addNode();
lemon_node_vector[n].id = n;
lemon_node_vector[n].name = name[n];
}

}

最佳答案

当然也可以循环执行AddNode和AddArc。或者在递归函数中。或者以您想要的任何其他方式。

你试过吗?有什么错误吗?

关于c++ - Lemon Graph Library C++ - 使用循环添加节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13052027/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com