namespace ve/////////////////ve.h
{
struct VertexPropertie s
{
std::size_t index;
boost::default_ color_type color;
};
}
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace ed///////////////////////ed.h
{
struct EdgeProperties
{
EdgeProperties( const std::string& n) : name(n) { }
std::string name;
};
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#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 Construct
{
public:
void 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 <50 ; 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);
}
}
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* [])
{
Construct h;
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,10,11,11,12 ,12,13,14,17,19 ,19,19,20,20,20 ,21,21,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,12,16,17,14 ,24,13,25,15,15 ,26,29,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};
h.create_graph( s1,s2,s3);
return 0;
}
This is program is working fine but i want to return the graph object in one function.
and need to pass the graph object in other function for printing the adjacency list
like ...
#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 Gra
{
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);
}
}
/*graph_traits<G raph>::vertex_i terator 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);
* */
return g;
}
void get_edges(const 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* [])
{
Gra h;
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,10,11,11,12 ,12,13,14,17,19 ,19,19,20,20,20 ,21,21,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,12,16,17,14 ,24,13,25,15,15 ,26,29,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};
h.create_graph( s1,s2,s3);
h.get_edges(h.c reate_graph(s1, s2,s3));
return 0;
}
1.
It is giving the following error
create_graph1.c pp:57: error: conversion from ‘boost::bundle_ property_map<co nst boost::adjacenc y_list<boost::v ecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, void*, ve::VertexPrope rties, const unsigned int>’ to non-scalar type ‘boost::bundle_ property_map<bo ost::adjacency_ list<boost::vec S, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, void*, ve::VertexPrope rties, unsigned int>’ requested
2.
create_graph1.c pp:58: error: conversion from ‘boost::bundle_ property_map<co nst boost::adjacenc y_list<boost::v ecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, boost::detail:: edge_desc_impl< boost::undirect ed_tag, void*>, ed::EdgePropert ies, const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >’ to non-scalar type ‘boost::bundle_ property_map<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::detail:: edge_desc_impl< boost::undirect ed_tag, void*>, ed::EdgePropert ies, std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >’ requested
can you help me in doing this.I will be very thankful to you .
{
struct VertexPropertie s
{
std::size_t index;
boost::default_ color_type color;
};
}
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace ed///////////////////////ed.h
{
struct EdgeProperties
{
EdgeProperties( const std::string& n) : name(n) { }
std::string name;
};
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#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 Construct
{
public:
void 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 <50 ; 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);
}
}
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* [])
{
Construct h;
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,10,11,11,12 ,12,13,14,17,19 ,19,19,20,20,20 ,21,21,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,12,16,17,14 ,24,13,25,15,15 ,26,29,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};
h.create_graph( s1,s2,s3);
return 0;
}
This is program is working fine but i want to return the graph object in one function.
and need to pass the graph object in other function for printing the adjacency list
like ...
#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 Gra
{
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);
}
}
/*graph_traits<G raph>::vertex_i terator 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);
* */
return g;
}
void get_edges(const 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* [])
{
Gra h;
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,10,11,11,12 ,12,13,14,17,19 ,19,19,20,20,20 ,21,21,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,12,16,17,14 ,24,13,25,15,15 ,26,29,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};
h.create_graph( s1,s2,s3);
h.get_edges(h.c reate_graph(s1, s2,s3));
return 0;
}
1.
It is giving the following error
create_graph1.c pp:57: error: conversion from ‘boost::bundle_ property_map<co nst boost::adjacenc y_list<boost::v ecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, void*, ve::VertexPrope rties, const unsigned int>’ to non-scalar type ‘boost::bundle_ property_map<bo ost::adjacency_ list<boost::vec S, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, void*, ve::VertexPrope rties, unsigned int>’ requested
2.
create_graph1.c pp:58: error: conversion from ‘boost::bundle_ property_map<co nst boost::adjacenc y_list<boost::v ecS, boost::listS, boost::undirect edS, ve::VertexPrope rties, ed::EdgePropert ies, boost::no_prope rty, boost::listS>, boost::detail:: edge_desc_impl< boost::undirect ed_tag, void*>, ed::EdgePropert ies, const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >’ to non-scalar type ‘boost::bundle_ property_map<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::detail:: edge_desc_impl< boost::undirect ed_tag, void*>, ed::EdgePropert ies, std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >’ requested
can you help me in doing this.I will be very thankful to you .
Comment