Hi everyone,
I am trying to run BFS on a graph that is created with input from a file. I am facing problems with the output though the code is compiling: - #include <boost/graph/adjacency_list.hpp>
-
#include <boost/graph/depth_first_search.hpp>
-
#include <fstream>
-
#include <utility>
-
#include <boost/graph/breadth_first_search.hpp>
-
#include <algorithm>
-
-
namespace std {
-
-
using namespace boost;
-
-
template <typename T>
-
std::istream& operator>> (std::istream& in, std::pair<T,T>& p) {
-
in >> p.first >> p.second;
-
return in;
-
}
-
-
class graph_out : public default_bfs_visitor {
-
public:
-
graph_out() : ecounter(0) {}
-
-
template <typename Edge, typename Graph>
-
void tree_edge(Edge u, const Graph&) {
-
std::cout << "discovered an edge" << endl;
-
std::cout << ecounter++ << u;
-
}
-
-
private:
-
int ecounter;
-
-
};
-
-
}
-
-
-
-
int main(){
-
using namespace std;
-
using namespace boost;
-
typedef adjacency_list <listS, vecS, directedS> file_dep_graph;
-
-
std::ifstream file_in("directed_graph.dat");
-
typedef graph_traits<file_dep_graph>::vertices_size_type size_type;
-
size_type n_vertices;
-
-
if(file_in >> n_vertices){
-
std::cout << n_vertices << endl; // read in number of vertices
-
}
-
-
istream_iterator<std::pair<size_type, size_type> >
-
input_begin(file_in), input_end;
-
-
file_dep_graph g(input_begin, input_end, n_vertices);
-
-
graph_out vis;
-
graph_traits<file_dep_graph>::vertex_descriptor a = *vertices(g).first;
-
breadth_first_search(g,a,visitor(vis));
-
-
}
The directed_graph. dat file is: - 14
-
(1,2)
-
(2,3)
-
(3,4)
-
(3,5)
-
(4,6)
-
(6,7)
-
(7,8)
-
(7,9)
-
(7,10)
-
(8,11)
-
(9,12)
-
(12,13)
-
(13,14)
Please dont suggest me any alternatives, such as without using a file etc as I need to do it this way only.
1 3157
Hi everyone,
I found the answer :)
I entered the values in the directed_graph. dat file wrongly.
We shouldn't enter the values in pairs.
We should do so in inegers.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jeremy Siek |
last post by:
CALL FOR PAPERS/PARTICIPATION
C++, Boost, and the Future of C++ Libraries
Workshop at OOPSLA
October 24-28, 2004
Vancouver, British Columbia, Canada
http://tinyurl.com/4n5pf
Submissions
|
by: nin234 |
last post by:
My apologies in advance if any one is offended by this post. I have an
unstable job in a start up company and thought of sharpening my skill
sets. I noticed that many companies are asking for boost and austria
C++ library knowledge. I am thinking of using that in my
project/learning them.
For the past 20 months , I developed a fairly complex real time multi
threaded (Posix threads) daemon in C++ using Berkeley DB, sockets, C++
concepts...
|
by: JD Kronicz |
last post by:
Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right version of the MS Graph type
library. Up until now I have been walking them through
the process of setting the references to include their
version of MS Graph library.
My problem is that I can not seem to get the syntax
correct .. or perhaps...
|
by: Jef Driesen |
last post by:
I'm trying to create a graph from an image, where pixel values are
regions labels. I have defined my graph to use lists instead of the
vectors (because I need to add/remove vertices and edges) and one extra
property for the vertex (the region label):
typedef boost::adjacency_list<
boost::listS, // Adjacency list
boost::listS, // Vertex list
boost::undirectedS, // Undirected graph
unsigned int, // Vertex property...
|
by: George Sakkis |
last post by:
I've just started toying with the python bindings of BGL and I'm
puzzled from the following:
True
False
It seems that the vertices iterator creates new vertex objects every
time instead of iterating over the existing ones. This essentially
prevents, among other things, storing vertices as keys in a dictionary
since the hashes of the stored and the new vertex differ although they
| |
by: =?UTF-8?B?SmVucyBNw7xsbGVy?= |
last post by:
(I also posted this to boost-user)
The BGL implementation of breadth-first search uses a dedicated color map.
I had the following idea: Some algorithms don't need to distinguish
black/gray, but have an unused value in e.g. a distance map, e.g. -1, to
which the map can be initialised.
So I tried to write a map adapter which can be passed such a map
together with the value indicating "white". This adapter will return
|
by: Tim Frink |
last post by:
Hi,
I want to use the depth_first_search algorithm from the Boost
Graph Library. However, I've problems with the definition of
my own ColorMap. To illustrate this, here is an example
(taken from http://www.boost.org/libs/graph/example/dfs-example.cpp):
int
main()
{
|
by: Man4ish |
last post by:
namespace ve/////////////////ve.h
{
struct VertexProperties
{
std::size_t index;
boost::default_color_type color;
};
}
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace ed///////////////////////ed.h
|
by: Man4ish |
last post by:
I have created Graph object without vertex and edge property.It is working fine.
#include <boost/config.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/tuple/tuple.hpp>
#include <set>
using namespace std;
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |