C++ 平面图形图C++;
我读过很多关于在平面上绘制平面图的文章,我尝试了很多库 最后,我需要指定输入图形,输出以获得其顶点的新坐标,以便边不相交 选择权落在Boost图形库中的函数chrobak_payne_straight_line_drawing上 我在下图中对其进行了测试: 但它不起作用,在chrobak_payne_drawing.hpp文件的125行调用了System.AccessViolationException:C++ 平面图形图C++;,c++,graph,C++,Graph,我读过很多关于在平面上绘制平面图的文章,我尝试了很多库 最后,我需要指定输入图形,输出以获得其顶点的新坐标,以便边不相交 选择权落在Boost图形库中的函数chrobak_payne_straight_line_drawing上 我在下图中对其进行了测试: 但它不起作用,在chrobak_payne_drawing.hpp文件的125行调用了System.AccessViolationException: delta_x[v3] = 1; 但在这张图上它起作用了: 请帮助,我需要函数来处理所有
delta_x[v3] = 1;
但在这张图上它起作用了:
请帮助,我需要函数来处理所有平面图,并且不会导致严重错误。下面我展示了代码,我测试了第一个图形,发现了一个严重错误,顺便说一下,我使用的是VisualStudio2010
#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 <stack>
#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>
> graph;
//Define the storage type for the planar embedding
typedef std::vector< std::vector< graph_traits<graph>::edge_descriptor > >
embedding_storage_t;
typedef boost::iterator_property_map
< embedding_storage_t::iterator,
property_map<graph, vertex_index_t>::type
>
embedding_t;
// Create the graph - a maximal planar graph on 7 vertices. The functions
// planar_canonical_ordering and chrobak_payne_straight_line_drawing both
// require a maximal planar graph. If you start with a graph that isn't
// maximal planar (or you're not sure), you can use the functions
// make_connected, make_biconnected_planar, and make_maximal planar in
// sequence to add a set of edges to any undirected planar graph to make
// it maximal planar.
graph g(5);
add_edge(0,3, g);
add_edge(0,4, g);
add_edge(1,3, g);
add_edge(1,4, g);
add_edge(2,3, g);
add_edge(2,4, g);
// Create the planar embedding
embedding_storage_t embedding_storage(num_vertices(g));
embedding_t embedding(embedding_storage.begin(), get(vertex_index,g));
boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
boyer_myrvold_params::embedding = embedding
);
// Find a canonical ordering
std::vector<graph_traits<graph>::vertex_descriptor> ordering;
planar_canonical_ordering(g, embedding, 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(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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间boost;
//一个保持直线嵌入坐标的类
结构协调
{
标准:尺寸×t;
std::尺寸y;
};
int main(int argc,字符**argv)
{
typedef邻接列表
图形;
//定义平面嵌入的存储类型
typedef std::vector>
嵌入存储;
typedef boost::迭代器属性映射
嵌入t;
//创建图-7个顶点上的最大平面图。函数
//平面正则序和chrobak payne直线
//需要一个最大平面图。如果你从一个非最大平面图开始
//最大平面(或者您不确定),您可以使用函数
//使_连通,使_双连通_平面,使_最大平面
//将一组边添加到任何无向平面图以生成
//它是平面的。
图g(5);
添加_边(0,3,g);
添加_边(0,4,g);
添加_边(1,3,g);
添加_边(1,4,g);
添加_边(2,3,g);
添加_边(2,4,g);
//创建平面嵌入
嵌入存储嵌入存储(顶点数(g));
嵌入(嵌入存储.begin(),get(顶点索引,g));
boyer_myrvold_平面度_检验(boyer_myrvold_参数::graph=g,
boyer_myrvold_参数::嵌入=嵌入
);
//找到一个正则序
std::向量排序;
平面正则序(g,嵌入,std::back_插入器(序));
//设置属性贴图以保留从顶点到坐标的映射
typedef std::向量直线\u绘图\u存储\u t;
typedef boost::迭代器属性映射
直线图;
直线图存储直线图存储
(顶点数(g));
直线图
(直线图存储。开始(),
获取(顶点索引,g)
);
//计算直线图
chrobak_payne_直线图(g,
嵌入,
排序。开始(),
ordering.end(),
直线图
);
std::cout这看起来像boost::graph中的一个bug。我有一个不同的访问冲突,可能是因为不同的boost版本,但肯定有一个bug
left[v] = right[leftmost];
vertex_t next_to_rightmost;
for(vertex_t temp = leftmost; temp != rightmost;
temp = right[temp]
)
{
next_to_rightmost = temp;
}
right[next_to_rightmost] = graph_traits<Graph>::null_vertex();
left[v]=右[最左边];
最右边的顶点;
对于(顶点温度=最左侧;温度!=最右侧;
温度=右[温度]
)
{
最右边的下一个=温度;
}
右[最右边的下一个]=图特征::空顶点();
在这里,当leftmost==rightsest
时,for
循环的不会执行,并且next\u to\u rightsest
保持未初始化状态。崩溃!这就是我看到的情况。您使用的图形不是最大平面图。在到达ca之前,您需要使用函数make\u connected、make\u biconnected\u plantar和maximum\u plantar非数值排序或嵌入。虽然源代码中的注释解释了这一点,但它们的使用并不完全直观,我找不到使用它们和函数chrobak_payne_straight_line_drawing的源代码。我认为这不是一个bug,它说在使用chrobak_payne_straight_line_drawing之前,必须先使用t三个函数串联,使_连通,使_双连通_平面,使_最大,但我没有在一个代码中把它们全部放在一起,什么都没有,并请求帮助。这些错误很可能是由于图形传递的不是最大平面。。