写作提升动力性能,使用Boost Graph库文件 [英] Writing boost dynamic properties to a file using Boost Graph Library

查看:261
本文介绍了写作提升动力性能,使用Boost Graph库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经问了一个问题<一href=\"http://stackoverflow.com/questions/34132273/adding-custom-properties-to-vertex-of-a-grid-in-boost-graph-library/34139227#34139227\">here有关使用Boost Graph库和图形写入到文件中。由于在我的要求改变,我需要编写动态图形性能到一个点文件。经过一番查找,我设法想出一些code,但它不工作。下面是我迄今所做的:

I have already asked a question here about using Boost Graph Library and writing graph into file. Due to change in my requirements, I need to write dynamic graph properties into a DOT file. After some look up, I managed to come up with some code but it does not work. Below is what I have done so far:

地图类使用Cell类为顶点和Cell类使用单独的CellProperty类设置和获取所有的单元格属性。

Map class uses the Cell class as vertices and Cell class uses a separate CellProperty class for setting and getting all the Cell properties.

和最后地图类。

Map.h

class Map {
 public:
  typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, Cell> Graph;
  typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;

  explicit Map(std::string pGraphFilePath);
  virtual ~Map();
  void LoadGraph();
 private:
  Graph mGraph;
  std::vector<std::vector<Vertex>> mGrid;
};

Map.cpp

Map.cpp

const unsigned int RowNum = 3;
const unsigned int ColumnNum = 4;

Map::Map(std::string pGraphFilePath) : mGraph(), mGrid() {}
Map::~Map() {}

void Map::LoadGraph() {
  int dummyID = 1;
  for (unsigned int row = 0; row < RowNum; row++) {
    mGrid.resize(RowNum);
    for (unsigned int col = 0; col < ColumnNum; col++) {
      mGrid[row].resize(ColumnNum);

      Vertex vID = boost::add_vertex(mGraph);
      mGraph[vID].SetProperty<unsigned int>("ID", dummyID);
      mGraph[vID].SetProperty<bool>("Navigable", true);
      mGrid[row][col] = vID;
      dummyID++;
      // add the edges for the contained cells in the grid
      if (col > 0) { boost::add_edge(mGrid[row][col - 1], mGrid[row][col], mGraph); }
      if (row > 0) { boost::add_edge(mGrid[row - 1][col], mGrid[row][col], mGraph); }
    }
  }

  // write cell properties
  boost::dynamic_properties propertiesOutPut;

  propertiesOutPut.property("ID", boost::get(boost::vertex_index, mGraph));

  // As Navigable is an external property, it need to be mapped with the internal graph property
  // the lines below are the update after I got the answers and link for my query
  // cell.GetProperty() is a templated method the takes a default parameter, thus passing "false" bool parameter which returns the "Navigable" cell property
  auto valueNavigable = boost::make_transform_value_property_map([](Cell &cell) { return cell.GetProperty<bool>("Navigable", false); }, boost::get(boost::vertex_bundle, mGraph));
  propertiesOutPut.property("Navigable", valueNavigable);

  std::ofstream fout("MyGraph.dot");
  boost::write_graphviz_dp(fout, mGraph, propertiesOutPut, std::string("ID"));
}

我得到的问题是为提振propertiesOutPut.property()方法得到::()。我想不出正确的参数的boost :: get()方法。请帮助我。谢谢!

The problem I am getting is with the propertiesOutPut.property() method for boost::get(). I can not figure out the correct parameters for boost::get(). Please help me out. Thanks !!

推荐答案

您可以对包含顶点属性结构的propertymap的顶部使用 transform_value_property_map 。 (你没有表现出来)。

You could use a transform_value_property_map on top of the propertymap that contains the vertex properties struct. (You didn't show it).

我有很多答案,说明如何做到这一点的,虽然这些都是使用内部属性,也没有很大的区别,因为阿努属性映射可以以同样的方式进行改造,无论属性映射是内部的还是外部的(这是属性映射的全部目的:去耦属性被访问的方式的)。

I have a number of answers showing how to do that, although these are all using internal properties, there is no big difference because anu property map can be transformed in the same way, regardless of whether the property map is internal or external (that's the whole purpose of property maps: decoupling the way properties are accessed).

最相关的:


  • <一个href=\"https://stackoverflow.com/questions/29947535/overloading-streaming-operators-for-a-boost-graph-bundle-output-for-graphviz/29957367?s=8|0.0000#29957367\">Overloading流媒体运营商升压捆绑图形输出的GraphViz

<一个href=\"https://stackoverflow.com/questions/29949480/manually-colouring-of-boosts-graphs/29956404?s=6|0.0000#29956404\">Manually提升的图形着色

其他:


  • 看到这些搜索结果:<一href=\"https://stackoverflow.com/search?tab=votes&q=user%3a85371%20make_transform_value_property_map\">https://stackoverflow.com/search?tab=votes&q=user%3a85371%20make_transform_value_property_map

这篇关于写作提升动力性能,使用Boost Graph库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆