[英]Lemon Graph Library C++ - addNode using loop
是否有可能在C ++中使用循環創建檸檬圖?
我的問題:
我期望的結果:
我的問題
是否可以為t_nodes
表中的每個條目使用循環, 以將節點添加到圖形中
如何為t_edges
提到的所有關系使用循環?
感謝您的時間,非常感謝任何幫助!
在周末有一些空閑時間並在我的自行車上花了一些時間后我找到了解決方案:)
我的解決方案
似乎檸檬沒有提供支持圖中邊緣的附加信息的可能性。 因此,我剛剛創建了一個用於存儲此信息的附加向量。 但是,出於某些目的,使用散列映射來訪問節點可能更為明智。
看看開發的示例腳本(非常簡單;))
Lemon 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。 或者在遞歸函數中。 或者以你想要的任何其他方式。
你試過嗎? 有什么錯誤嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.