Boost图分割错误 [英] Boost graph segmentation fault

查看:67
本文介绍了Boost图分割错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Boost来通过Chrobak-Payne算法嵌入平面图. 我能够成功运行示例 ,但是当我尝试修改它并使用其他图形时,它无法正常工作.我试图嵌入第二张柏拉图图,但是它不起作用,并且我的代码因崩溃而崩溃分段错误:11".我以为是因为我需要使用make_connected,make_biconnected_planar和make_maximal_planar,但是添加它们并不能解决问题.

I am trying to use Boost to embed a planar graph using the Chrobak-Payne algorithm. I am able to run the example successfully, but when I try to modify it and use different graphs it does not work correctly. I am trying to embed the second platonic graph but it does not work, and my code crashes with "Segmentation fault: 11". I assumed it is because I needed to use make_connected, make_biconnected_planar, and make_maximal_planar, but adding them did not fix it.

这是使用第二张柏拉图和三个帮助函数的修改后的源示例:

Here is the modified source example using the second platonic graph and the three helper functions:

//=======================================================================
// Copyright 2007 Aaron Windsor
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/property_map.hpp>
#include <vector>

#include <boost/graph/planar_canonical_ordering.hpp>
#include <boost/graph/is_straight_line_drawing.hpp>
#include <boost/graph/chrobak_payne_drawing.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp>



using namespace boost;

//a class to hold the coordinates of the straight line embedding
struct coord_t
{
  std::size_t x;
  std::size_t y;
};


int main(int argc, char** argv)
{
typedef adjacency_list
    < vecS,
      vecS,
      undirectedS,
      property<vertex_index_t, int>,
      property<edge_index_t, int>
    > 
    graph;

  graph g(7);
  add_edge(0,1,g);
  add_edge(1,2,g);
  add_edge(2,3,g);
  add_edge(3,0,g);
  add_edge(0,4,g);
  add_edge(1,5,g);
  add_edge(2,6,g);
  add_edge(3,7,g);
  add_edge(4,5,g);
  add_edge(5,6,g);
  add_edge(6,7,g);
  add_edge(7,4,g);

  make_connected(g); //Make connected (1/3)

  //Compute the planar embedding as a side-effect
  typedef std::vector< graph_traits<graph>::edge_descriptor > vec_t;
  std::vector<vec_t> embedding(num_vertices(g));
  boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
                                   boyer_myrvold_params::embedding = 
                                     &embedding[0]
                                   );


  make_biconnected_planar(g, &embedding[0]); //Make biconnected planar (2/3)

  make_maximal_planar(g, &embedding[0]); //Make maximal planar (3/3)

  //Find a canonical ordering
  std::vector<graph_traits<graph>::vertex_descriptor> ordering;
  planar_canonical_ordering(g, &embedding[0], std::back_inserter(ordering));

  //Set up a property map to hold the mapping from vertices to coord_t's
  typedef std::vector< coord_t > straight_line_drawing_storage_t;
  typedef boost::iterator_property_map
    < straight_line_drawing_storage_t::iterator, 
      property_map<graph, vertex_index_t>::type 
    >
    straight_line_drawing_t;

  straight_line_drawing_storage_t straight_line_drawing_storage
    (num_vertices(g));
  straight_line_drawing_t straight_line_drawing
    (straight_line_drawing_storage.begin(), 
     get(vertex_index,g)
     );

  // Compute the straight line drawing
  chrobak_payne_straight_line_drawing(g, 
                                      embedding, 
                                      ordering.begin(),
                                      ordering.end(),
                                      straight_line_drawing
                                      );



  std::cout << "The straight line drawing is: " << std::endl;
  graph_traits<graph>::vertex_iterator vi, vi_end;
  for(boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
    {
      coord_t coord(get(straight_line_drawing,*vi));
      std::cout << *vi << " -> (" << coord.x << ", " << coord.y << ")" 
                << std::endl;
    }

  // Verify that the drawing is actually a plane drawing
  if (is_straight_line_drawing(g, straight_line_drawing))
    std::cout << "Is a plane drawing." << std::endl;
  else
    std::cout << "Is not a plane drawing." << std::endl;

  return 0;
}

但是由于某些原因,我仍然遇到细分错误.我知道是在接电话:

But for some reason I am still getting a segmentation fault. I know it is at the call:

chrobak_payne_straight_line_drawing(g, 
                                  embedding, 
                                  ordering.begin(),
                                  ordering.end(),
                                  straight_line_drawing
                                  );

因为没有它,它运行良好(但不计算嵌入).导致此分段错误的内存问题在哪里?我要嵌入的图形比示例小.

because it runs fine without it (but does not compute the embedding). Where is the memory issue causing this segmentation fault? The graph I am embedding is smaller than the example.

推荐答案

来自必须是具有至少3个顶点的最大平面图,成功需要k> 2的要求.您对chrobak_payne_straight_line_drawing不会对您进行检查,它会在std中的向量迭代器测试中断言.

From must be a maximal planar graph with at least 3 vertices, the requirement that k > 2 is needed for success. Your call to Planar Canonical Ordering returned two vertices. Catch is chrobak_payne_straight_line_drawing does no checking for you and it asserts at the vector iterator test in the std.

添加:

assert( ordering.size( ) > 2 );

在调用还是有条件之前,取决于您要做什么.

before calling, or a conditional, depends what you are up to.

一个优势:

add_edge(1,4,g);

那会奏效的.

这篇关于Boost图分割错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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