digraph模块是对图结构的一种封装,主要的description请参考http://www.erlang.org/doc/man/digraph.html
下面来看看digraph的一些方法:
图结构无非就是由一些节点和边组成的,在digraph中有个Label的东西,这个其实就是图节点的附加信息,类似在C语言中在一个节点中放个指针,指向一些附加的信息。
那么要创建图,就必须要先创建一些图的基本结构出来
new() -> digraph()
new(Type) -> digraph()
cyclic
Allow cycles in the digraph (default).
acyclic
The digraph is to be kept acyclic.
protected
Other processes can read the digraph (default).
private
The digraph can be read and modified by the creating process only.
cyclic表示的是有向有环图:如果一个有向图能从某个顶点出发经过若干条边回到该点,则这个图是一个有向有环图
acyclic表示的是有向无环图:如果一个有向图无法从某个顶点出发经过若干条边回到该点,则这个图是一个有向无环图
protected表示该图可以被其他进程访问
private表示只能被创建这个图的那个进程访问
那么可以看出图的信息应该是存储在ets表中的
add_vertex(G) -> vertex()
add_vertex(G, V) -> vertex()
add_vertex(G, V, Label) -> vertex()
这个三个方法就是给某个图增加一个节点上去,同时可以给出这个节点的附带信息Label
add_edge(G, V1, V2) -> edge() | {error, add_edge_err_rsn()}
add_edge(G, V1, V2, Label) -> edge() | {error, add_edge_err_rsn()}
add_edge(G, E, V1, V2, Label) ->
这三个方法就是给V1节点和V2节点之间建立一条边,并且给出这个边的附带信息Label
如果在一个有向无环图中创建一条边导致这个图可以构成有环图,那么就会抛出{error,{bad_edge,Path}}的错误,如果V1和V2节点中有任意一个不是图的节点,那么也会抛出{error,{bad_vertex,V}}的错误
还有一些删除图的边以及点,还有一些可以获取图中的点以及边的方法具体请参照官方文档
get_cycle(G, V) -> Vertices | false
Types:
G = digraph()
V = vertex()
Vertices = [vertex(), ...]
If there is a simple cycle of length two or more through the vertex V, then the cycle is returned as a list [V, ..., V] of vertices, otherwise if there is a loop through V, then the loop is returned as a list [V]. If there are no cycles through V, then false is returned.
上面的方法是在图中找出一条简单的可以构成环的路径出来,返回中间经过的点,请见例子
G = digraph:new([cyclic]).
digraph:add_vertex(G,1,{vertex1}).
digraph:add_vertex(G,2,{vertex2}).
digraph:add_vertex(G,3,{vertex3}).
digraph:add_edge(G,1,2).
digraph:add_edge(G,2,3).
digraph:add_edge(G,3,1).
digraph:get_cycle(G,2). 输出为[2,3,1,2]
get_path(G, V1, V2) -> Vertices | false
Types:
G = digraph()
V1 = V2 = vertex()
Vertices = [vertex(), ...]
Tries to find a simple path from the vertex V1 to the vertex V2 of the digraph G. Returns the path as a list [V1, ..., V2] of vertices, or false if no simple path from V1 to V2 of length one or more exists.
在途中找出一条从V1到V2的路径
digraph:get_path(G,1,2).
[1,2]
get_short_cycle(G, V) -> Vertices | false
Types:
G = digraph()
V = vertex()
Vertices = [vertex(), ...]
Tries to find an as short as possible simple cycle through the vertex V of the digraph G. Returns the cycle as a list [V, ..., V] of vertices, or false if no simple cycle through V exists. Note that a loop through V is returned as the list [V, V].
跟get_cycle差不多,只不过这里要最短的环
get_short_path(G, V1, V2) -> Vertices | false
Types:
G = digraph()
V1 = V2 = vertex()
Vertices = [vertex(), ...]
Tries to find an as short as possible simple path from the vertex V1 to the vertex V2 of the digraph G. Returns the path as a list [V1, ..., V2] of vertices, or false if no simple path from V1 to V2 of length one or more exists.
与get_path同理
in_degree(G, V) -> integer() >= 0
Types:
G = digraph()
V = vertex()
Returns the in-degree of the vertex V of the digraph G.
返回一个点的入度数量,图的入度,出度可以查阅图的知识
digraph:in_degree(G,1).
1
out_degree(G, V) -> integer() >= 0
Types:
G = digraph()
V = vertex()
Returns the out-degree of the vertex V of the digraph G.
与上面相对应,这个是计算某个节点出度的值
in_neighbours(G, V) -> Vertex
Types:
G = digraph()
V = vertex()
Vertex = [vertex()]
Returns a list of all in-neighbours of V of the digraph G, in some unspecified order.
通俗来说就是返回那些指向节点V的其他节点
digraph:in_neighbours(G,1).
[3]
out_neighbours(G, V) -> Vertices
Types:
G = digraph()
V = vertex()
Vertices = [vertex()]
Returns a list of all out-neighbours of V of the digraph G, in some unspecified order.
与上面的相反
digraph:out_neighbours(G,1).
[2]
info(G) -> InfoList
Returns a list of {Tag, Value} pairs describing the digraph G. The following pairs are returned:
{cyclicity, Cyclicity}, where Cyclicity is cyclic or acyclic, according to the options given to new.
{memory, NoWords}, where NoWords is the number of words allocated to the ETS tables.
{protection, Protection}, where Protection is protected or private, according to the options given to new.
这个方法的作用比较明显,不再累赘
erlang还提供digraph_util的工具模块,有兴趣的可以去查看,下面就看看rabbitmq用到了digraph_util的几个方法
方法一
reaching(Vertices, Digraph) -> Reaching
Types:
Digraph = digraph()
Vertices = Reaching = [digraph:vertex()]
Returns an unsorted list of digraph vertices such that for each vertex in the list, there is a path from the vertex to some vertex of Vertices. In particular, since paths may have length zero, the vertices of Vertices are included in the returned list.
返回这些节点之间在图中存在有path的点集
方法二:
subgraph(Digraph, Vertices) -> SubGraph
subgraph(Digraph, Vertices, Options) -> SubGraph
Types:
Digraph = SubGraph = digraph()
Vertices = [digraph:vertex()]
Options = [{type, SubgraphType} | {keep_labels, boolean()}]
SubgraphType = inherit | [digraph:d_type()]
Creates a maximal subgraph of Digraph having as vertices those vertices of Digraph that are mentioned in Vertices.
If the value of the option type is inherit, which is the default, then the type of Digraph is used for the subgraph as well. Otherwise the option value of type is used as argument to digraph:new/1.
If the value of the option keep_labels is true, which is the default, then the labels of vertices and edges of Digraph are used for the subgraph as well. If the value is false, then the default label, [], is used for the subgraph's vertices and edges.
subgraph(Digraph, Vertices) is equivalent to subgraph(Digraph, Vertices, []).
There will be a badarg exception if any of the arguments are invalid.
返回这些节点的最大子图,最大子图就是在给出的节点中,从原图中构造出一个节点最多的子图
方法三
topsort(Digraph) -> Vertices | false
Types:
Digraph = digraph()
Vertices = [digraph:vertex()]
Returns a topological ordering of the vertices of the digraph Digraph if such an ordering exists, false otherwise. For each vertex in the returned list, there are no out-neighbours that occur earlier in the list.
即是拓扑排序了。
一个简单的求拓扑排序的算法:首先要找到任意入度为0的一个顶点,删除它及所有相邻的边,再找入度为0的顶点,以此类推,直到删除所有顶点。顶点的删除顺序即为拓扑排序。
相关推荐
ECG利用Erlang强大的跟踪机制和可视化工具graphviz ,确保已安装graphviz ,并且由于此处使用Python绑定,因此还需要安装Digraph软件包。 图形生成流程如下: Start tracer -> Start program -> Stop trace -> ...
基于万能逼近原理的自适应模糊控制算法在多自由度AUV运动控制中的应用与抗干扰补偿Simulink仿真研究,自适应模糊控制算法的万能逼近原理与多自由度AUV运动控制的抗干扰补偿技术——基于Simulink的仿真研究,万能逼近原理自适应模糊控制算法的多自由度AUV运动控制抗干扰补偿simulink仿真 ,核心关键词:万能逼近原理; 自适应模糊控制算法; 多自由度AUV运动控制; 抗干扰补偿; Simulink仿真。,基于万能逼近的模糊控制算法多自由度AUV抗干扰补偿Simulink仿真
deepseek最新资讯、配置方法、使用技巧,持续更新中
deepseek最新资讯、配置方法、使用技巧,持续更新中
结合扩展卡尔曼滤波与滑模观测器的策略:优化电角度估计,反电势波形逼近完美正弦波,结合扩展卡尔曼滤波与滑模观测器的反电势波形优化:正弦波形展现近乎完美精度,电角度估算与实际应用差异微小,扩展卡尔曼滤波与滑模观测器的结合,反电势波形近乎完美的正弦波形,观测器估算转子电角度与实际电角度相差0.3弧度左右,转速跟随效果较好。 ,核心关键词:扩展卡尔曼滤波; 滑模观测器; 反电势波形; 转子电角度估算; 转速跟随效果。,卡尔曼滑模观测器:优化正弦波转子角度与转速估算
毕业设计_基于springboot+vue的**学生公寓管理系统**【源码+sql+可运行】【**50217**】.zip 全部代码均可运行,亲测可用,尽我所能,为你服务; 1.代码压缩包内容 代码:springboo后端代码+vue前端页面代码; 脚本:数据库SQL脚本 效果图:运行结果请看资源详情效果图 2.环境准备: - JDK1.8+ - maven3.6+ - nodejs14+ - mysql5.6+ - redis 3.技术栈 - 后台:springboot+mybatisPlus+Shiro - 前台:vue+iview+Vuex+Axios - 开发工具: idea、navicate 4.功能列表 - 系统设置:用户管理、角色管理、资源管理、系统日志 - **业务管理:业务管理:公寓信息、房间信息、入住记录、学生信息** 3.运行步骤: 步骤一:修改数据库连接信息(ip、port修改) 步骤二:找到启动类xxxApplication启动 4.若不会,可私信博主!!!
1、文件内容:xorg-x11-server-source-1.20.4-29.el7_9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/xorg-x11-server-source-1.20.4-29.el7_9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
1、文件内容:yum-plugin-ps-1.1.31-54.el7_8.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/yum-plugin-ps-1.1.31-54.el7_8.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
基于模型预测控制(MPC)的无人船与无人车编队一致性协同控制研究(附原文献),基于模型预测控制(MPC)的无人船与无人车编队一致性协同控制研究(附原文献),无人船编队 无人车编队 MPC 模型预测控制 多智能体协同控制 一致性 MATLAB 无人车 USV 带原文献 ,无人船编队; 无人车编队; MPC 模型预测控制; 多智能体协同控制; 一致性; MATLAB; USV; 原文献,无人系统协同控制:MPC模型预测控制下的多智能体编队与一致性研究(原文献支撑)
4套中级通信工程师综合真题及答案(2019,2020,2021,2023),适用于需要考中级通信工程师的人群
deepseek最新资讯,配置方法,使用技巧,持续更新中
基于matlab的锁相环PLL相位噪声拟合仿真代码集合:多个版本建模与仿真,高质量的锁相环PLL仿真代码集合:Matlab与Simulink建模研究,[1]锁相环 PLL 几个版本的matlab相位噪声拟合仿真代码,质量杠杠的,都是好东西 [2]锁相环matlab建模稳定性仿真,好几个版本 [3]锁相环2.4G小数分频 simulink建模仿真 ,PLL; Matlab相位噪声拟合仿真; Matlab建模稳定性仿真; 锁相环2.4G小数分频Simulink建模仿真,MATLAB仿真系列:锁相环PLL及分频器建模仿真
exceptionLogs.zip
基于光伏微网的经济性与并网负荷波动率双目标优化调度策略:蓄电池与V2G协同管理策略仿真研究,MATLAB下光储充微网结合电动汽车V2G的多目标协同调度策略研究:经济性与并网负荷波动性的对比分析,MATLAB代码:考虑V2G的光储充一体化微网多目标优化调度策略 关键词:光储充微网 电电汽车V2G 多目标优化 蓄电池优化 调度 参考文档:《光伏微网下考虑V2G补偿蓄电池容量的双目标优化调度策略》,已经投稿EI会议,中文说明文档可联系我咨询 仿真平台:MATLAB 平台 优势:代码注释详实,适合参考学习,相关成果已经采用,程序非常精品,请仔细辨识 主要内容:过建立光伏微网中以经济性和并网负荷波动率为双目标的蓄电池和V2G的协同调度模型。 采用粒子群算法,对电网、微网调度中心和电动汽车用户三方在无、无序、转移和调度V2G电动汽车负荷四种运行模式下的经济和安全影响进行对比。 最后,根据算例分析,求解四种模式下两级负荷曲线及经济收益表。 对比分析得出,引入V2G可以替代部分容量的蓄电池,使光伏微网在负荷峰谷平抑、三方经济和安全等方面进一步优化。 求解采用的是PSO算法(粒子群算法),求解效果极
javascript 动态网页设计期末大作业(自己手写的,高分期末作业),含有代码注释,新手也可看懂,个人手打98分项目,导师非常认可的高分项目,毕业设计、期末大作业和课程设计高分必看,下载下来,简单部署,就可以使用。该项目可以直接作为毕设、期末大作业使用,代码都在里面,系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值,项目都经过严格调试,确保可以运行! javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期
混合智能体系统编队控制:分布式优化与15异构混合阶的挑战,异构混合阶智能体系统编队控制的分布式优化策略研究,15异构混合阶多智能体系统编队控制的分布式优化(无参考文献) ,核心关键词:15异构混合阶; 多智能体系统; 编队控制; 分布式优化; 无参考文献。,15混合阶多智能体系统编队分布式优化控制
javascript 动态网页设计期末大作业(自己手写的,很适合期末作业),含有代码注释,新手也可看懂,个人手打98分项目,导师非常认可的高分项目,毕业设计、期末大作业和课程设计高分必看,下载下来,简单部署,就可以使用。该项目可以直接作为毕设、期末大作业使用,代码都在里面,系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值,项目都经过严格调试,确保可以运行! javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascrip
X光安检OPIXray数据集已经转换为VOC格式,可直接转换为为YOLO
DataX--Web:图形化界面简化大数据任务管理_datax-web