簡體   English   中英

Boost圖分割錯誤

[英]Boost graph segmentation fault

我正在嘗試使用Boost通過Chrobak-Payne算法嵌入平面圖。 我能夠成功運行該示例 ,但是當我嘗試對其進行修改並使用其他圖形時,它將無法正常運行。 我試圖嵌入第二張柏拉圖圖,但是它不起作用,並且我的代碼因“分段錯誤:11”而崩潰。 我以為是因為我需要使用make_connected,make_biconnected_planar和make_maximal_planar,但是添加它們並不能解決問題。

這是使用第二張柏拉圖和三個輔助函數的修改后的源示例:

//=======================================================================
// 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;
}

但是由於某種原因,我仍然遇到細分錯誤。 我知道是在電話中:

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

因為沒有它,它運行良好(但不計算嵌入)。 導致此分段錯誤的內存問題在哪里? 我要嵌入的圖形比示例小。

必須是至少具有3個頂點的最大平面圖,成功要有 k> 2的要求。 您對“ 平面規范訂購”的調用返回了兩個頂點。 捕獲是chrobak_payne_straight_line_drawing不檢查您,它在std中的向量迭代器測試中聲明。

加:

assert( ordering.size( ) > 2 );

致電還是有條件之前,取決於您的工作。

另一優勢:

add_edge(1,4,g);

它本來可以。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM