是否有可能在 C ++ 中使用循环创建一个柠檬图?
我的问题:
具有列的数据库表(我们称之为 t_nodes):节点
具有图信息的数据库表(我们称之为 t_edges):node1 | node2 | edgeScore
超过 10000 个条目
我想要的结果:
有向图:如 N1-& gt;N2;N2-& gt;N3;N3-& gt;N1
我的问题
是否可以对t_nodes
表中的每个条目使用循环将节点添加到图
到目前为止,我刚刚发现他们手动添加每个节点的实现(见下面的例子)
真的没有机会使用循环将节点添加到柠檬图中吗?
我怎么能使用一个循环中提到的所有关系t_edges
?
感谢您的时间和任何帮助非常感谢!
在周末有一些空闲时间并花一些时间在我的自行车上之后,我找到了解决方案:)
我的解决方案:
看来,柠檬没有提供支持额外信息到图中的边缘的可能性。因此,我只是创建了一个额外的向量来存储这些信息。但是,出于某些目的,使用 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。或者在递归函数中。或者以任何其他你想要的方式
你试过了吗?有什么错误吗?
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(58条)