- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用无向 DFS ( Depth First Search ) 算法 implemented in boost::graph .
此算法需要顶点和边上的颜色值来跟踪已解析的颜色值。在 the provided example ,代码将这些颜色值存储为图形的内部属性:
typedef adjacency_list<
vecS,
vecS,
undirectedS,
no_property, // vertex properties
property<edge_color_t, default_color_type> // edge colors
> graph_t;
调用是使用“命名属性”版本完成的:
undirected_dfs(g, root_vertex(vertex_t(0)).visitor(vis)
.edge_color_map(get(edge_color, g)));
我的问题是我有顶点和边的自定义值。我用的似乎是 the preferred way of doing , 这就是所谓的“捆绑属性”:
struct my_vertex { int a1; float a2; }
struct my_edge { int b1; float b2; }
typedef adjacency_list<
vecS,
vecS,
undirectedS,
my_vertex, // vertex properties
my_edge // edge properties
> graph_t;
当然,之前的DFS函数调用对这个图类型定义不起作用。对于顶点,手册指出提供了默认值,并且它确实可以仅使用特定的顶点类型和边类型构建良好,如上所示。但是如果我想要特定的边缘类型,我得出的结论是我需要单独提供算法所需的颜色,因为我不能使用示例代码中所示的属性。所以我认为这可以通过将它们提供为“外部属性”来完成。
我的问题是:我该怎么做?
UTIL: edge_color_map(EdgeColorMap edge_color) This is used by the algorithm to keep track of which edges have been visited. The type EdgeColorMap must be a model of Read/Write Property Map and its key type must be the graph's edge descriptor type and the value type of the color map must model ColorValue.
这对我来说不清楚,我已经尝试阅读有关属性映射的部分,但我就是无法理解。
在this answer的帮助下,我在下面尝试过,但是失败了:(使用“未命名参数”版本)
std::vector<int> edge_color( boost::num_edges(g), 0);
std::vector<int> vertex_color( boost::num_vertices(g), 0 );
boost::undirected_dfs(
g,
boost::visitor( boost::default_dfs_visitor() ),
boost::vertex_color_map( vertex_color ),
boost::edge_color_map( edge_color ),
boost::root_vertex( vertex_t(0) )
);
如果有人能指出我正确的方向......
最佳答案
您需要满足记录的确切参数要求:http://www.boost.org/doc/libs/1_63_0/libs/graph/doc/undirected_dfs.html
这意味着您/可以/摆脱顶点颜色的 vector ,但边缘颜色需要在关联容器中,因为边缘描述符不像顶点描述符用于您的图形类型那样是完整的。
std::vector<default_color_type> vertex_color(num_vertices(g));
std::map<graph_t::edge_descriptor, default_color_type> edge_color;
auto idmap = get(vertex_index, g);
auto vcmap = make_iterator_property_map(vertex_color.begin(), idmap);
auto ecmap = make_assoc_property_map(edge_color);
graph_t::vertex_descriptor const start = 0;
现在您可以调用算法的固定参数版本:
undirected_dfs(g, vis, vcmap, ecmap, start);
或者,使用命名参数版本调用完全相同的方法:
undirected_dfs(g,
root_vertex(graph_t::vertex_descriptor(0))
.visitor(vis)
.vertex_color_map(vcmap)
.edge_color_map(ecmap)
);
#include <iostream>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/undirected_dfs.hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
struct my_vertex { int a1; float a2; };
struct my_edge { int b1; float b2; };
struct detect_loops : public boost::dfs_visitor<> {
template <class Edge, class Graph>
void back_edge(Edge e, const Graph& g) {
std::cout << g[source(e,g)].a1 << " -- " << g[target(e,g)].a1 << "\n";
}
};
typedef adjacency_list<vecS, vecS, undirectedS, my_vertex, my_edge> graph_t;
int main() {
detect_loops vis;
graph_t g;
std::vector<default_color_type> vertex_color(num_vertices(g));
std::map<graph_t::edge_descriptor, default_color_type> edge_color;
auto idmap = get(vertex_index, g);
auto vcmap = make_iterator_property_map(vertex_color.begin(), idmap);
auto ecmap = make_assoc_property_map(edge_color);
graph_t::vertex_descriptor const start = 0;
undirected_dfs(g, vis, vcmap, ecmap, start);
undirected_dfs(g,
root_vertex(graph_t::vertex_descriptor(0))
.visitor(vis)
.vertex_color_map(vcmap)
.edge_color_map(ecmap)
);
}
关于c++ - 无向 DFS : how can I provide color maps as exterior properties?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43477020/
您好,下面是我在 AWS 中创建启用了弹性 IP 的实例的模板。但是我不确定我哪里出错了。我已经通过在线 json 验证器验证了 json,仍然面临问题请帮忙 { "AWSTemplateForm
标题有点乱,但已经说明了一切。我想在一个属性的属性上有一个属性观察器: class A { var b: B init() { b = B() } fu
假设我的一个 Controller 中有这样的方法: [Route("api/Products")] public IQueryable GetProducts() { return db.P
这有效: // @flow import React, {Component} from 'react'; type Props = {}; class Delete extends Componen
我有一个 ViewModelBase 类,我在其中为 INotifyPropertyChanged 接口(interface)定义了 RaisePropertyChanged 方法。大多数 MVVM
我创建了类: class StorageBase { public Queue Slices {get;set;} } 和 wpf 自定义控件,它具有 StorageBase 类型的依赖属性
我的 java 应用程序问题是 log4j2 系统日志不是写在 'local1.log' 中而是'消息'。我的/etc/rsyslog.conf 在/etc/rsyslog.conf 中配置为 'lo
为什么需要在对象中使用 this.property = property ?它是用来定义对象的“外部世界”的属性吗? function Person(property) { this.property
摘要: 这个问题是关于属性的继承与从彼此继承属性的类的内部和外部的不同读/写访问相结合。 详细信息: 我有一个类 A 和另一个继承自 A 的类 B。 A 中声明了属性someProperty。我希望该
我正在开发 ASP.NET MVC 应用,设计域模型,使用(测试)新的 EF Code First 功能。 我有一个可能有也可能没有截止日期的事件实体,处理它的最佳方法是什么? 1 个属性: publ
我在配置项目时经常使用它们,但大多数情况下都是按照指示添加 fragment 。我完全不知道哪个文件到底是做什么的。谁能清楚地说明每个文件的用途。 到目前为止我认为 local.properties
在运行 python 文件以使用 rasa nlu 训练文件时,我在命令提示符下收到此错误 我目前正在使用 Windows 10 rasa_core==0.8.2 rasa_nlu==0.11.4 p
我在这方面遇到了一些麻烦,尽管我已经搜索了答案,但还是找不到。 为了使用 AsyncAppender,我看到了很多不同的 log4j 配置,无论如何,它们都与 .properties 配置文件无关。
我正在编写一个 Python 类,并使用 @property 装饰器为该类创建属性。 我在文档中没有找到太多关于这个装饰器的信息,但是从我可以从 Stack Overflow 和我的 Python l
在 gradle 任务中,我可以创建这样的路径: System.env.FOLDER_PATH + '/subFolder' 但我想在我的 gradle.properties 中设置它,所以它会像 s
如何在属性文件的 log4j2 中创建键值对? 我知道在 log4j 版本 1 中它是这样完成的: log4j.appender.x.additionalFields={'key': 'value'}
我想通了 struct PropertyTest { @property int x() { return val; } @property void x( int newVal )
我有 REST (Jersey) webservice,它利用了一些编码/解码到/来自 XML 的数据对象。数据对象位于 webservice war 所依赖的单独项目/jar 中。 我使用 MOXy
我正在创建一个 LinkedList 类: function LinkedList(){ ... 有什么区别: this.addNode = function(data){
关于语义的快速问题:) 如果我正在编写一个协议(protocol),这是首选: // (a) @protocol MyProtocol @property (nonatomic, copy) NSSe
我是一名优秀的程序员,十分优秀!