473,569 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in creating Graph Object using Boost Graph Library

151 New Member
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;
using namespace boost;
class hello
{
public:
typedef adjacency_list< > Graph;

Graph create_Graph(ve ctor <int> s1,vector <int> s2,int count_vetices)
{
typedef adjacency_list <>Graph;
Graph g(count_vetices );
for (unsigned int i = 0; i < s1.size(); i++)
{
add_edge(s1[i], s2[i], g);
}
return g;
}

int no_of_elements( vector<int> v2,vector<int> v3)
{
vector<int> v4;
for (unsigned int i = 0; i < v2.size(); i++)
{
v4.push_back(v2[i]);
v4.push_back(v3[i]);
}
std::set< int, std::less< int > > doubleSet( v4.begin(), v4.end());;
return doubleSet.size( );
}

void get_adjacencyLi st(const Graph&g)
{
int name[]={0,1,2,3,4,5,6 ,7,8,9};
graph_traits < adjacency_list <> >::vertex_itera tor i, end;
graph_traits < adjacency_list <> >::adjacency_it erator ai, a_end;
property_map < adjacency_list <>, vertex_index_t >::type
index_map = get(vertex_inde x, g);

for (tie(i, end) = vertices(g); i != end; ++i)
{
std::cout << name[get(index_map, *i)];
tie(ai, a_end) = adjacent_vertic es(*i, g);
if (ai == a_end)
std::cout << " no children";
else
std::cout << " is the parent of ";
for (; ai != a_end; ++ai)
{
std::cout << name[get(index_map, *ai)];
if (boost::next(ai ) != a_end)
std::cout << ", ";
}
std::cout << std::endl;
}
}

};
int main()
{
using namespace boost;
hello h;
typedef adjacency_list <>Graph;
vector<int> s1,s2;
s1.push_back(1) ;
s1.push_back(2) ;
s1.push_back(3) ;
s1.push_back(4) ;
s1.push_back(5) ;
s1.push_back(6) ;
s2.push_back(7) ;
s2.push_back(8) ;
s2.push_back(4) ;
s2.push_back(1) ;
s2.push_back(9) ;
s2.push_back(5) ;
int n=h.no_of_eleme nts(s1,s2);
cout<<"no of elements ="<< h.no_of_element s(s1,s2)<<endl;
Graph g = h.create_Graph( s1,s2,n);////////////////getting graph object
h.get_adjacency List(g);
return EXIT_SUCCESS;
}



But when i am trying with vertex and edge property.


#include <boost/config.hpp>
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <boost/graph/adjacency_list. hpp>
#include <boost/graph/graph_utility.h pp>
#include <boost/property_map.hp p>
#include "ed.h"
#include "ve.h"
using namespace boost;
using namespace std;
class Network
{
public:
typedef adjacency_list< boost::vecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies> Graph;
Graph create_graph(in t s1[],int s2[],int s3[])
{
typedef adjacency_list< boost::vecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies> Graph;
const int V = 50;
Graph g(V);
property_map<Gr aph, std::size_t ve::VertexPrope rties::*>::type
id = get(&ve::Vertex Properties::ind ex, g);
property_map<Gr aph, std::string ed::EdgePropert ies::*>::type
name = get(&ed::EdgePr operties::name, g);
boost::graph_tr aits<Graph>::ve rtex_iterator vi, viend;
int vnum = 0;
for (boost::tie(vi, viend) = vertices(g); vi != viend; ++vi)
id[*vi] = vnum++;
for (int i = 0; i <40 ; i++)
{
if(s3[i]==1){
add_edge(vertex (s1[i], g), vertex(s2[i], g), ed::EdgePropert ies("single bond"), g);
}
if(s3[i]==2)
{
add_edge(vertex (s1[i], g), vertex(s2[i], g), ed::EdgePropert ies("double bond"), g);
}
if(s3[i]==3){
add_edge(vertex (s1[i], g), vertex(s2[i], g), ed::EdgePropert ies("triple_bon d"), g);
}
}
return g;
}

void get_edges( Graph g)
{
property_map<Gr aph, std::size_t ve::VertexPrope rties::*>::type id = get(&ve::Vertex Properties::ind ex, g);
property_map<Gr aph, std::string ed::EdgePropert ies::*>::type name = get(&ed::EdgePr operties::name, g);
boost::graph_tr aits<Graph>::ve rtex_iterator vi, viend;
int vnum = 0;
for (boost::tie(vi, viend) = vertices(g); vi != viend; ++vi)
id[*vi] = vnum++;
graph_traits<Gr aph>::vertex_it erator i, end;
graph_traits<Gr aph>::out_edge_ iterator ei, edge_end;
for (boost::tie(i,e nd) = vertices(g); i != end; ++i)
{
cout << id[*i] << " ";
for (boost::tie(ei, edge_end) = out_edges(*i, g); ei != edge_end; ++ei)
cout << " --" << name[*ei] << "--> " << id[target(*ei, g)] << " ";
cout << endl;
}
print_edges(g, id);
}

};



int main(int , char* [])
{
Network h;
typedef adjacency_list< boost::vecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies> Graph;
int s1[]={1,1,2,2,3,3,4 ,4,5,5,6,6,6,7, 7,7,8,8,8,8,9,9 ,10,1 0,11,11,12,12,1 3,14,17,19,19,1 9,20,20,20,21,2 1,21} ;
int s2[]={13,19,14,20,1 5,21,16,18,17,1 8,16,27,28,18,3 8,39, 9,10,22,23,11,1 2,16,17,14,24,1 3,25,15,15,26,2 9,30, 31,32,33,34,35, 36,37};
int s3[]={1,1,1,1,1,1,2 ,1,1,2,1,1,1,1, 1,1,1,1,1,1,2,1 ,1,2, 1,1,2,1,1,2,1,1 ,1,1,1,1,1,1,1, 1};
Graph obj= h.create_graph( s1,s2,s3);
h.get_edges(obj );
return 0;
}


It is giving error.
/usr/include/boost/graph/detail/adjacency_list. hpp:986: instantiated from ‘std::pair<type name Config::edge_de scriptor, bool> boost::add_edge (typename Config::vertex_ descriptor, typename Config::vertex_ descriptor, boost::undirect ed_graph_helper <C>&) [with Config = boost::detail:: adj_list_gen<bo ost::adjacency_ list<boost::vec S, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, boost::listS, boost::vecS, boost::undirect edS, boost::property <boost::vertex_ bundle_t, ve::VertexPrope rties, boost::no_prope rty>, boost::property <boost::edge_bu ndle_t, ed::EdgePropert ies, boost::no_prope rty>, boost::no_prope rty, boost::listS>:: config]’

/usr/include/boost/graph/detail/adjacency_list. hpp:986: instantiated from ‘std::pair<type name Config::edge_de scriptor, bool> boost::add_edge (typename Config::vertex_ descriptor, typename Config::vertex_ descriptor, boost::undirect ed_graph_helper <C>&) [with Config = boost::detail:: adj_list_gen<bo ost::adjacency_ list<boost::vec S, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, boost::listS, boost::vecS, boost::undirect edS, boost::property <boost::vertex_ bundle_t, ve::VertexPrope rties, boost::no_prope rty>, boost::property <boost::edge_bu ndle_t, ed::EdgePropert ies, boost::no_prope rty>, boost::no_prope rty, boost::listS>:: config]’

/usr/include/boost/graph/detail/adjacency_list. hpp:1705: instantiated from ‘boost::adj_lis t_impl<Derived, Config, Base>::adj_list _impl(const boost::adj_list _impl<Derived, Config, Base>&) [with Derived = boost::adjacenc y_list<boost::v ecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, Config = boost::detail:: adj_list_gen<bo ost::adjacency_ list<boost::vec S, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, boost::listS, boost::vecS, boost::undirect edS, boost::property <boost::vertex_ bundle_t, ve::VertexPrope rties, boost::no_prope rty>, boost::property <boost::edge_bu ndle_t, ed::EdgePropert ies, boost::no_prope rty>, boost::no_prope rty, boost::listS>:: config, Base = boost::undirect ed_graph_helper <boost::detail: :adj_list_gen<b oost::adjacency _list<boost::ve cS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, boost::listS, boost::vecS, boost::undirect edS, boost::property <boost::vertex_ bundle_t, ve::VertexPrope rties, boost::no_prope rty>, boost::property <boost::edge_bu ndle_t, ed::EdgePropert ies, boost::no_prope rty>, boost::no_prope rty, boost::listS>:: config>]’

/usr/include/boost/graph/adjacency_list. hpp:368: instantiated from ‘boost::adjacen cy_list<OutEdge ListS, VertexListS, DirectedS, VertexProperty, EdgeProperty, GraphProperty, EdgeListS>::adj acency_list(con st boost::adjacenc y_list<OutEdgeL istS, VertexListS, DirectedS, VertexProperty, EdgeProperty, GraphProperty, EdgeListS>&) [with OutEdgeListS = boost::vecS, VertexListS = boost::listS, DirectedS = boost::undirect edS, VertexProperty = ve::VertexPrope rties, EdgeProperty = ed::EdgePropert ies, GraphProperty = boost::no_prope rty, EdgeListS = boost::listS]’

create_object.c pp:43: instantiated from here
Please help me out of this pblm .I will be thankful to you.
Apr 3 '08 #1
2 2300
weaknessforcats
9,208 Recognized Expert Moderator Expert
Re-posting your problem isn't going to get you more help.

I really have no idea why you are getting these messages. Especially, since there is no error code.

You may need to contact the Boost folks and ask them the question.
Apr 3 '08 #2
Man4ish
151 New Member
Re-posting your problem isn't going to get you more help.

I really have no idea why you are getting these messages. Especially, since there is no error code.

You may need to contact the Boost folks and ask them the question.
Thankyou sir,
i wll contact Boost folks and ask them.
Apr 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1683
by: Dax | last post by:
Hi, I'm using boost library, I want to create a graph of a library in c++, and, for example, every leave is a book, inside it there are some variables, like title, if is available, description, number of archive etc etc. I can do it? Thanks Daniele
2
2770
by: Christian Christmann | last post by:
Hi, I need to write a graph which provides at least the following functions: 1) stores nodes and edges (both store further information which can be of any type) 2) manipulations on nodes and edges like delete, add ... 3) provides a list of all successors/predecessors for a given node 4) provides a list of all nodes that can be reached...
8
2430
by: Jef Driesen | last post by:
I'm working on an image segmentation algorithm. An essential part of the algorithm is a graph to keep track of the connectivity between regions. At the moment I have a working implementation, but it's not flexible enough anymore and I need something more advanced. I already have a data structure in mind, but I don't know how to implement that...
3
7820
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, ...
6
1633
by: cppnow | last post by:
Hello. I have a strange conceptual problem I'm trying to think about. I would like to build a library that allows the user to do the following: 1) User defined types: The user defines their own types as needed for their particular application and registers them with the library. class ClassA {};
5
2522
by: Fei Liu | last post by:
Hello, I have a situation where I need to design a library for multi-thread application, each thread does some work in a client supplied std::ptr_fun(free_function) or a functor. Now since it's a multi-threaded application, naturally I want the call back functor to be created on a per thread basis. Suppose my thread is so defined ...
4
2541
by: Man4ish | last post by:
namespace ve/////////////////ve.h { struct VertexProperties { std::size_t index; boost::default_color_type color; }; } /////////////////////////////////////////////////////////////////////////////////////////////////// namespace ed///////////////////////ed.h
1
1847
by: Man4ish | last post by:
I am creating a graph using boost library, I am making the network using create_Network function() i am adding the vertices to this graph by creating the object g of class Graph. I am trying to use this object g in the another function get_neighbours() but it is not giving any result.Should I make it global or should use constructor so that...
1
3152
by: rboorgapally | last post by:
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...
0
7633
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7941
Oralloy
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. ...
0
8147
jinu1996
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...
1
7699
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...
0
7997
tracyyun
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...
0
6320
agi2029
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...
1
5520
isladogs
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...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3669
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.