 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
ialexei Guest
|
Posted: Sat Sep 27, 2003 10:18 am Post subject: Problem using Boost Graph Library |
|
|
Hi,
I am posting this here because, I saw that the author of this
library(Boost Graph Library) had replied to questions reg its usage
here in the past.
I am doing a topological sort on a graph with vertices
V = {0,1,2,3,4,5}
and edges
E = {(0,1), (2,4), (2,5), (0,3), (1,4), (4,3), (2,3) }
On running the sample I get the result as
6 2 5 0 1 4 3
I am not able to fifgure out, where this 6 came from ??????
-Alexei
//---------------------------------------------------------------------------
// TopoTest.cpp : Defines the entry point for the console application.
//---------------------------------------------------------------------------
// Platform Win32, MSVC++ 7.1 (VS.NET 2003)
#include "stdafx.h"
#include <iostream> // for std::cout
#include <utility> // for std::pair
#include <algorithm> // for std::for_each
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
using namespace boost;
using namespace std;
typedef int vertex_type;
typedef pair<vertex_type, vertex_type> Pair;
int _tmain(int argc, _TCHAR* argv[])
{
typedef adjacency_list< vecS, vecS, directedS>/*, color_property<>
| Quote: | */ Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; |
typedef std::vector< Vertex > container;
Pair edges[] = { Pair(0,1), Pair(2,4),
Pair(2,5),
Pair(0,3), Pair(1,4),
Pair(4,3), Pair(2,3) };
int nCount = sizeof(edges)/sizeof(Pair);
Graph G(edges, edges + nCount, nCount);
container c;
try {
topological_sort(G, std::back_inserter(c));
}catch(not_a_dag e)
{
cout << "Cycle found" <
}
cout << "A topological ordering: ";
for ( container::reverse_iterator itr=c.rbegin(); itr!=c.rend();
itr++)
cout << (*itr) << " ";
cout << endl;
return 0;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
David Abrahams Guest
|
Posted: Sat Sep 27, 2003 2:51 pm Post subject: Re: Problem using Boost Graph Library |
|
|
[email]ialexei (AT) hotmail (DOT) com[/email] (ialexei) writes:
| Quote: | Hi,
I am posting this here because, I saw that the author of this
library(Boost Graph Library) had replied to questions reg its usage
here in the past.
|
Didn't he also tell you that the boost developers' list
(http://www.boost.org/more/mailing_lists.htm) was a better place to
get help with the graph library? If not, he should have. The Boost
developers don't always read this newsgroup; I think you'll have
better luck there.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Derek Ledbetter Guest
|
Posted: Wed Oct 01, 2003 8:22 am Post subject: Re: Problem using Boost Graph Library |
|
|
On Sat, 27 Sep 2003 3:18:23 -0700, ialexei wrote
(in message <6ef50842.0309260641.257dbbe (AT) posting (DOT) google.com>):
| Quote: | I am doing a topological sort on a graph with vertices
V = {0,1,2,3,4,5}
and edges
E = {(0,1), (2,4), (2,5), (0,3), (1,4), (4,3), (2,3) }
On running the sample I get the result as
6 2 5 0 1 4 3
I am not able to fifgure out, where this 6 came from ??????
.....
Pair edges[] = { Pair(0,1), Pair(2,4),
Pair(2,5),
Pair(0,3), Pair(1,4),
Pair(4,3), Pair(2,3) };
int nCount = sizeof(edges)/sizeof(Pair);
Graph G(edges, edges + nCount, nCount);
|
The third parameter to this constructor is the number of vertices, so
G has a vertex "6" that is not connected to any other vertex.
Replace nCount with 6.
--
Derek Ledbetter
[email]derekledbetter (AT) attbi (DOT) com[/email]
"Life's short and hard like a body-building elf."
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|