gpt4 book ai didi

c++ - 如何使用 setS 顶点列表创建 boost 子图?

转载 作者:行者123 更新时间:2023-11-30 05:42:22 24 4
gpt4 key购买 nike

以下代码有错误:

AAA.cpp:23:15:   required from here
.../boost/include/boost/graph/subgraph.hpp:333:5: error: static assertion failed: (!is_same<edge_index_type,
boost::detail::error_property_not_found>::value)

AAA.cpp:27:21: error: no matching function for call to ‘add_vertex(foo(int, char**)::<anonymous enum>, Graph&)’

AAA.cpp:27:21: note: candidates are:
.../boost/include/boost/graph/subgraph.hpp: In instantiation of ‘boost::subgraph<Graph>::subgraph(boost::subgraph<Graph>::vertices_size_type,
const graph_property_type&) [with Graph =
boost::adjacency_list<boost::setS, boost::setS, boost::directedS,
boost::no_property, boost::no_property, boost::no_property,
boost::setS>; boost::subgraph<Graph>::vertices_size_type = long
unsigned int; boost::subgraph<Graph>::graph_property_type =
boost::no_property]’:
#include <boost/config.hpp>
#include <iostream>
#include <boost/graph/subgraph.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>

int foo(int,char*[])
{
using namespace boost;
typedef subgraph<
adjacency_list<
setS,
setS,
directedS,
no_property,
no_property,
no_property, // graph prop
setS // edgelist
>
> Graph;

const int N = 6;
Graph G0(N);
enum { A, B, C, D, E, F};

Graph& G1 = G0.create_subgraph();
add_vertex(C, G1); // global vertex C becomes local A1 for G1

return 0;
}

如果我将顶点列表的 setS 更改为 vecS,它可以被编译。如何使用 setS 顶点列表创建 boost 子图?

谢谢,

最佳答案

首先,它不会为 VertexContainer 使用 vecS 进行编译:

To create a graph and subgraphs, first create the root graph object. Here we use adjacency_list as the underlying graph implementation. The underlying graph type is required to have vertex_index and edge_index internal properties, so we add an edge index property to the adjacency list. (docs)

所以让我们添加一些东西。现在编译:

Live On Coliru

#include <boost/config.hpp>
#include <iostream>
#include <boost/graph/subgraph.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>

int main()
{
using namespace boost;
using containerS = vecS;
typedef subgraph< adjacency_list<containerS, containerS, directedS,
property<vertex_index_t, size_t>,
property<edge_index_t, size_t>
>
> Graph;

const int N = 6;
Graph G0(N);
enum { A, B, C, D, E, F};

Graph& G1 = G0.create_subgraph();
Graph::vertex_descriptor CG1 = add_vertex(G1);
Graph::vertex_descriptor EG1 = add_vertex(G1);

add_edge(CG1, EG1, G1);

print_graph(G0);
std::cout << "SUBGRAPH:\n";
print_graph(G1);
}

打印

0 --> 
1 -->
2 -->
3 -->
4 -->
5 -->
6 --> 7
7 -->
SUBGRAPH:
0 --> 1
1 -->

使用setS

坦率地说,虽然文档间接暗示可以选择 listSsetS 之类的东西,但老实说我认为这行不通。

问题似乎是如何实现 local_to_globalm_global_vertex

这可能是人为限制/未实现的功能。您可能想在开发人员列表/Trac 问题中提出这个问题。

关于c++ - 如何使用 setS 顶点列表创建 boost 子图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30688606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com