助推力定向布局问题

发布于 2024-11-24 20:06:16 字数 3227 浏览 1 评论 0原文

我是 boost 库的新手,我尝试从 boost 文档网站应用强制定向布局,但当我尝试编译代码时遇到了这样的错误:

错误:没有匹配的函数可调用 'random_graph_layout(MyGraph&, CoordSqMap&, double, double, double, double, boost::minstd_rand&)'

错误:没有匹配的函数可调用 'fruchterman_reingold_force_directed_layout(MyGraph&, CoordSqMap&, double&, double&, boost::bgl_named_pa​​rams)'

我已附上我的代码。

#include <boost/graph/fruchterman_reingold.hpp>
#include <boost/graph/random_layout.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/simple_point.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <boost/random/linear_congruential.hpp>
#include <boost/progress.hpp>
#include <boost/shared_ptr.hpp>

#include <boost/graph/small_world_generator.hpp>
#include <boost/random/linear_congruential.hpp>

using namespace boost;

struct decomposition_index_t{
  typedef vertex_property_tag kind;
};
struct coordinates_sq_t{
  typedef vertex_property_tag kind;
};
struct coordinates_circle_t{
  typedef vertex_property_tag kind;
};

template<typename T>
struct Polar {
  T rad;
  T angle;
};

struct VParams {
  int a;
  double b;
  long c;
  // std::complex<double> d;
};

typedef adjacency_list<vecS, vecS, undirectedS,
                       property<vertex_name_t, std::string,
                       property<decomposition_index_t, int,
                       property<coordinates_sq_t, simple_point<double>,
                       property<coordinates_circle_t, Polar<double>,
                       VParams > > > > > MyGraph;

typedef property_map<MyGraph,coordinates_sq_t>::type CoordSqMap;
typedef property_map<MyGraph,coordinates_circle_t>::type CoordCMap;

typedef graph_traits<MyGraph>::vertex_descriptor Vertex;

class progress_cooling : public linear_cooling<double>
{
  typedef linear_cooling<double> inherited;

 public:
  explicit progress_cooling(std::size_t iterations) : inherited(iterations)
  {
    display.reset(new progress_display(iterations + 1, std::cerr));
  }

  double operator()()
  {
    ++(*display);
    return inherited::operator()();
  }

 private:
  shared_ptr<boost::progress_display> display;
};

typedef boost::small_world_iterator<boost::minstd_rand, MyGraph> SWGen;

int main()
{
  boost::minstd_rand gen;
  // Create graph with 10000 nodes
  int nodecount = 90000;
  MyGraph g(SWGen(gen, nodecount, 6, 0.03), SWGen(), nodecount);

  double width = 2;
  double height = 2;

  CoordSqMap position = get(coordinates_sq_t(), g);
  random_graph_layout(g, position, -width/2, width/2, -height/2, height/2, gen);

  int iterations = 20;
  fruchterman_reingold_force_directed_layout
    (g, position, width, height,
     cooling(progress_cooling(iterations)) /* .force_pairs(all_force_pairs()) */  );

  return 0;
}

我尽了一切可能的方法来解决这个问题仍然无法做到这一点。对此您有什么建议吗?您有 Kamada kawai 弹簧布局的可行示例代码吗?

I am newbie in boost library, I tried to apply force directed layout from the boost documentation website but I encountered the error like this when I try to compile my code:

error: no matching function for call to ‘random_graph_layout(MyGraph&, CoordSqMap&, double, double, double, double, boost::minstd_rand&)’

error: no matching function for call to ‘fruchterman_reingold_force_directed_layout(MyGraph&, CoordSqMap&, double&, double&, boost::bgl_named_params<progress_cooling, boost::cooling_t, boost::no_property>)’

I have attached my code.

#include <boost/graph/fruchterman_reingold.hpp>
#include <boost/graph/random_layout.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/simple_point.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <boost/random/linear_congruential.hpp>
#include <boost/progress.hpp>
#include <boost/shared_ptr.hpp>

#include <boost/graph/small_world_generator.hpp>
#include <boost/random/linear_congruential.hpp>

using namespace boost;

struct decomposition_index_t{
  typedef vertex_property_tag kind;
};
struct coordinates_sq_t{
  typedef vertex_property_tag kind;
};
struct coordinates_circle_t{
  typedef vertex_property_tag kind;
};

template<typename T>
struct Polar {
  T rad;
  T angle;
};

struct VParams {
  int a;
  double b;
  long c;
  // std::complex<double> d;
};

typedef adjacency_list<vecS, vecS, undirectedS,
                       property<vertex_name_t, std::string,
                       property<decomposition_index_t, int,
                       property<coordinates_sq_t, simple_point<double>,
                       property<coordinates_circle_t, Polar<double>,
                       VParams > > > > > MyGraph;

typedef property_map<MyGraph,coordinates_sq_t>::type CoordSqMap;
typedef property_map<MyGraph,coordinates_circle_t>::type CoordCMap;

typedef graph_traits<MyGraph>::vertex_descriptor Vertex;

class progress_cooling : public linear_cooling<double>
{
  typedef linear_cooling<double> inherited;

 public:
  explicit progress_cooling(std::size_t iterations) : inherited(iterations)
  {
    display.reset(new progress_display(iterations + 1, std::cerr));
  }

  double operator()()
  {
    ++(*display);
    return inherited::operator()();
  }

 private:
  shared_ptr<boost::progress_display> display;
};

typedef boost::small_world_iterator<boost::minstd_rand, MyGraph> SWGen;

int main()
{
  boost::minstd_rand gen;
  // Create graph with 10000 nodes
  int nodecount = 90000;
  MyGraph g(SWGen(gen, nodecount, 6, 0.03), SWGen(), nodecount);

  double width = 2;
  double height = 2;

  CoordSqMap position = get(coordinates_sq_t(), g);
  random_graph_layout(g, position, -width/2, width/2, -height/2, height/2, gen);

  int iterations = 20;
  fruchterman_reingold_force_directed_layout
    (g, position, width, height,
     cooling(progress_cooling(iterations)) /* .force_pairs(all_force_pairs()) */  );

  return 0;
}

I tried all my best possible way to solve this still not able to do this. Do you have any suggestion for this. Do you have a workable sample code for Kamada kawai spring layout.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话里做英雄 2024-12-01 20:06:16

如果您使用的是相对较新的版本但不是最新版本,则某些版本中存在一个错误,即功能接口已更新但文档尚未更新。正确的文档位于 http://www.boost。 org/doc/libs/1_47_0/libs/graph/doc/fruchterman_reingold.html(以及其他当前的 BGL 文档页面)。

If you are using a relatively new version but not the latest release, there was a bug in some versions where the interfaces to the functions had been updated but the documentation hadn't been. The correct documentation is at http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/fruchterman_reingold.html (and the other current BGL documentation pages).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文