|
Boost Users : |
Subject: [Boost-users] [BGL]
From: Pablo Madoery (madoerypablo_at_[hidden])
Date: 2014-06-11 09:36:10
Hello, I Have 2 graphs: graph1 and graph2, and two sets of edge descriptors.
One set is associated to edges of graph1 and another set associated to
edges of graph2.
I don't understand why is it possible to access information about edges of
graph2 by using graph1 and the edge descriptors of graph2.
I realized of that because of an own mistake when using graphs.
What I would like to know is why is that possible to do and if it should be
an exception that can handle this situation.
I send the code I was using to test this:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <fstream>
#include "GraphInfo.h"
using namespace std;
using namespace boost;
typedef adjacency_list<setS, vecS, bidirectionalS, VertexInfo, EdgeInfo>
Graph;
void printGraph(Graph graph, string file)
{
ofstream ofs(file.c_str());
dynamic_properties dp;
dp.property("node_id", get(vertex_index, graph));
dp.property("label", get(&EdgeInfo::weight, graph));
write_graphviz_dp(ofs, graph, dp);
}
int main()
{
Graph graph1;
Graph::vertex_descriptor a1 = add_vertex(graph1);
Graph::vertex_descriptor b1 = add_vertex(graph1);
Graph::vertex_descriptor c1 = add_vertex(graph1);
Graph::edge_descriptor e1 = (add_edge(a1, b1, graph1)).first;
Graph::edge_descriptor e2 = (add_edge(b1, a1, graph1)).first;
graph1[a1].id = 10;
graph1[b1].id = 20;
graph1[c1].id = 30;
graph1[e1].weight = 1;
graph1[e2].weight = 2;
Graph graph2;
Graph::vertex_descriptor a2 = add_vertex(graph2);
Graph::vertex_descriptor b2 = add_vertex(graph2);
Graph::vertex_descriptor c2 = add_vertex(graph2);
Graph::vertex_descriptor d2 = add_vertex(graph2);
Graph::edge_descriptor e4 = (add_edge(c2, b2, graph2)).first;
Graph::edge_descriptor e5 = (add_edge(b2, c2, graph2)).first;
Graph::edge_descriptor e6 = (add_edge(d2, a2, graph2)).first;
Graph::edge_descriptor e7 = (add_edge(a2, d2, graph2)).first;
graph2[a2].id = 10;
graph2[b2].id = 20;
graph2[c2].id = 30;
graph2[e4].weight = 13;
graph2[e5].weight = 14;
graph2[e6].weight = 15;
graph2[e7].weight = 16;
// WHY IS THIS POSSIBLE TO DO
// IT IS ASKING FOR AN EDGE OF GRAPH2 BUT USING GRAPH1 ???
double weight = graph1[e7].weight;
cout<<"weight: "<<weight<<endl;
printGraph(graph1, "graph1.dot");
printGraph(graph2, "graph2.dot");
cout << "end" << endl;
return 0;
}
Thank you very much
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net