2013-10-14 3 views
2

Я использую адаптер adjacency_list и subgraph для создания моего типа графика.Как получить доступ к свойствам подстроки подграфа?

#include <boost/graph/subgraph.hpp> 
#include <boost/graph/adjacency_list.hpp> 

struct VertexProperties 
{ 
    bool bIsExpandable;   
    string sId; 
    string sCoord_X; 
    string sCoord_Y; 
    std::size_t order; 
}; 

struct EdgeProperties 
{ 
    string sId; 
    bool bBidirectional; 
}; 

//Graph properties 
enum graph_index_t {graph_index=111}; 
namespace boost{ 
BOOST_INSTALL_PROPERTY(graph,index); 
} 

typedef boost::property<boost::vertex_index_t, std::size_t , VertexProperties> vertex_prop; 
typedef boost::property<boost::edge_index_t, std::size_t , EdgeProperties> edge_prop; 
typedef boost::property<graph_index_t, std::size_t> graph_prop; 

typedef boost::adjacency_list< 
boost::listS, 
boost::vecS, 
boost::bidirectionalS, 
vertex_prop , 
edge_prop, 
graph_prop> 
Graph; 

typedef boost::subgraph<Graph> Subgraph; 

Я использую связанные свойства для вершин и ребер. Я попытался передать свойство bundled в 'graph', для adjacency_list он отлично работает, но не может быть использован для адаптера subgraph, я обнаружил, что он не поддерживается адаптером подзаголовка boost. Поэтому я добавил graph_index_t в свойства графика, но я не могу получить к нему доступ. Я написал следующую карту свойств для доступа к ней, но кажется, что это не правильный путь.

typedef property_map<Subgraph , graph_index_t>::type GraphIndexPropertyMap; 

Это дает ошибку в adjacency_list.hpp

d:\boost_1_53_0\boost\graph\detail\adjacency_list.hpp:2543: error: forming reference to void 

Я проверил подталкивание 1,53 документации, но не может найти путь, связанный с этим.

Так что у меня 2 вопроса:

1) Как получить доступ к свойству graph_index чтение-запись?

2) Могу ли я использовать связанное свойство для «графа» с подграфом boost каким-то образом?

Может ли кто-нибудь помочь?

Спасибо,

Pratik

ответ

0

Вот решение вашей проблемы, которая рассматривает метод доступа через повышающий подграф с помощью комплектного свойства и динамических свойств, как показано ниже:

#include <QtCore/QCoreApplication> 

#include <boost/config.hpp> 
#include <iostream> 
#include <algorithm> 
#include <boost/graph/adjacency_list.hpp> 
#include <boost/property_map/property_map.hpp> 
#include <string> 
#include <boost/graph/subgraph.hpp> 
#include <QMap> 

using namespace std; 
using namespace boost; 

enum graph_IDproperty_t 
{ 
    graph_IDproperty 
}; 
namespace boost 
{ 
    BOOST_INSTALL_PROPERTY(graph,IDproperty); 
} 
struct GraphProperties { 
std::string strName; 
std::string id; 
}; 

typedef boost::subgraph<boost::adjacency_list< boost::listS, 
boost::vecS, 
boost::bidirectionalS, 
boost::property<boost::vertex_index_t, int , property<boost::vertex_color_t, boost::default_color_type > > , 

boost::property<boost::edge_index_t,int, property<boost::edge_color_t , default_color_type> > , 

boost::property<graph_IDproperty_t,GraphProperties > > > 
Graph; 

Graph gMainGraph; 

typedef QMap<Graph*,GraphProperties*> mapGraphToProperty; 
mapGraphToProperty getMap(Graph& graph); 
void graphMapRecur(mapGraphToProperty& map, Graph& graph); 

int main(int argc, char *argv[]) 
{ 
    QCoreApplication a(argc, argv); 

Graph& subG = gMainGraph.create_subgraph(); 
Graph& subG1 = gMainGraph.create_subgraph(); 

boost::ref_property_map<Graph*, GraphProperties> 
     graph_propt1(boost::get_property(subG1,graph_IDproperty)); 

graph_propt1[&subG1].id = "SubG1"; 
cout<<graph_propt1[&subG1].id<<endl; 

boost::ref_property_map<Graph*, GraphProperties> 
     graph_propt(boost::get_property(subG,graph_IDproperty)); 

graph_propt[&subG].id = "SubG"; 
cout<<graph_propt[&subG].id<<endl; 

boost::ref_property_map<Graph*, GraphProperties> 
     graph_proptMain(boost::get_property(gMainGraph,graph_IDproperty)); 

graph_proptMain[&gMainGraph].id = "gMain"; 
cout<<graph_proptMain[&gMainGraph].id<<endl; 

mapGraphToProperty map = getMap(gMainGraph); 

boost::ref_property_map<Graph*, GraphProperties> 
     graph_proptMain1(*(map.value(&gMainGraph))); 

boost::ref_property_map<Graph*, GraphProperties> 
     graph_proptsubG(*(map.value(&subG))); 

boost::ref_property_map<Graph*, GraphProperties> 
     graph_proptsubG1(*(map.value(&subG1))); 

cout<<"Main G Value : "<<graph_proptMain1[&gMainGraph].id<<endl; 
cout<<"Sub G Value : "<<graph_proptsubG[&subG].id<<endl; 
cout<<"Sub G1 Value : "<<graph_proptsubG1[&subG1].id<<endl; 


cout<<"Map Value Main: "<<(map.value(&gMainGraph))<<endl; 
cout<<"Map Value SubG: "<<(map.value(&subG))<<endl; 
cout<<"Map Value SubG1b: "<<(map.value(&subG1))<<endl; 
return a.exec(); 
} 
mapGraphToProperty getMap(Graph &graph) 
{ 
mapGraphToProperty map; 
graphMapRecur(map,graph); 
return map; 
} 

void graphMapRecur(mapGraphToProperty &map, Graph &graph) 
{ 
Graph::children_iterator itrSubgraph, itrSubgraph_end; 

for (boost::tie(itrSubgraph, itrSubgraph_end) = (graph).children(); itrSubgraph != itrSubgraph_end; ++itrSubgraph) 
{ 
    graphMapRecur(map,(*itrSubgraph)); 
} 

GraphProperties* gp = &(get_property(graph,graph_IDproperty)); 

map.insert(&graph,gp); 
cout<<"Recurrr"<<endl; 

} 
Смежные вопросы