使用Python实现二终端网络可靠度
作者:快到皖里来 时间:2021-03-25 17:39:40
在网络可靠性中,一种较为经典且在实践中更为常用的可靠度计算便是二终端可靠度,即给定网络拓扑结构与边可靠度(假定节点完全可靠),计算网络中指定的两个节点之间的连通可靠度。
在此,笔者依据最小路集思想给出此方法的python代码实现,该代码可以依据给定的输入矩阵、节点序号等设定值算出两节点间的连通可靠度。
逻辑代码与测试用例如下:
import itertools
def min_path_sets(init_matrix,index_start,index_end):
import re
num_point = init_matrix.shape[0]
min_path_list = []
for i in range(num_point-1):
temp = init_matrix**(i+1)
item = expand(temp[index_start-1,index_end-1])
list_given = re.sub('[ *123456789]',"",str(item)).split("+")
#删除指定阶数下,路径长度不等于阶数的路
index_to_delete = []
for j in range(len(list_given)):
if len(list_given[j])!=(i+1) or list_given[j]=='0':
index_to_delete.append(j)
for counter, index in enumerate(index_to_delete):
index = index - counter
list_given.pop(index)
min_path_list.extend(list_given)
return min_path_list
def str_de_duplication(pstr):
a = ''
for i in range(len(pstr)):
if pstr[i] not in a:
a+=pstr[i]
return a
def product_symbol(pstr,my_dict):
import numpy as np
value_list = []
for i in pstr:
value_list.append(my_dict[i])
return np.prod(value_list)
def generate_label(path_sets,my_dict):
import numpy as np
all_result = []
for exp_num in range(len(path_sets)):
item_Combination = list(itertools.combinations(path_sets, exp_num+1))
item_list = list(map(lambda x: str_de_duplication("".join(x)),item_Combination))
value_list = list(map(lambda x: product_symbol(x,my_dict),item_list))
all_result.append(np.sum(value_list)*(-1)**(exp_num))
return np.sum(all_result)
def Matrix_label(init_matrix,my_dict,index_start,index_end):
path_sets = min_path_sets(init_matrix,index_start,index_end)
pro_value = generate_label(path_sets,my_dict)
return pro_value
from sympy import *
from sympy.abc import A,B,C,D,E,F
index_start = 2
index_end = 1
data = Matrix([[0,A,B],
[A,0,C],
[B,C,0]])
my_dict = {'A':0.8,
'B':0.9,
'C':0.9}
Matrix_label(data,my_dict,index_start,index_end)
在前部分,主要定义了几个函数以便求出最小路集以及利用容斥原理计算二终端可靠度,最终外层函数为Matrix_label(data,my_dict,index_start,index_end):
参数解释:
data:矩阵形式的数据,表征整个网络的拓扑结构和边可靠度,其中每一个矩阵元素要么为0,要么预设的字母如“A、B、C”等,每个字母取值为0到1(不包含0但包括1),元素为0表示对应行号与列号的节点之间无边相连,元素为字母如“A”表示对应行号与列号的节点之间以可靠度为A的概率相连;
my_dict:字典形式的数据,指定每一个用到的字母所表示的概率值,如{'A':0.8,'B':0.9,'C':0.9},特别指出网络中节点之间的连通概率可以相异;
index_start:二终端节点中的起始点序号;
index_end:二终端节点中的终止点序号;
来源:https://www.cnblogs.com/pythonfl/p/14729454.html
标签:二终端可靠度
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python 生成 -1~1 之间的随机数矩阵方法
2023-08-03 17:35:22
![](https://img.aspxhome.com/file/2023/2/82682_0s.jpg)
6个卓越Web设计细节
2010-03-29 12:56:00
![](https://img.aspxhome.com/file/UploadPic/20103/29/01-23s.jpg)
数据库名词解释
2008-09-12 17:28:00
Python 正则表达式实现计算器功能
2023-09-02 02:01:44
![](https://img.aspxhome.com/file/2023/1/93511_0s.png)
Linux上安装Python的PIL和Pillow库处理图片的实例教程
2021-01-17 15:22:50
Web前端应用十种常用技术
2010-09-01 20:46:00
![](https://img.aspxhome.com/file/UploadPic/20109/1/01-96s.jpg)
初探TensorFLow从文件读取图片的四种方式
2021-08-06 06:04:34
TensorFlow2.0矩阵与向量的加减乘实例
2023-12-30 13:21:00
python Dataframe 合并与去重详情
2022-08-17 02:18:54
客户认同的就是好商品
2009-08-31 16:41:00
如何用 Python 制作一个迷宫游戏
2022-03-29 20:44:07
![](https://img.aspxhome.com/file/2023/5/92065_0s.gif)
Python爬虫天气预报实例详解(小白入门)
2023-03-23 16:05:48
![](https://img.aspxhome.com/file/2023/5/77565_0s.jpg)
python对RabbitMQ的简单入门使用教程
2021-01-13 17:53:44
![](https://img.aspxhome.com/file/2023/4/93734_0s.jpg)
通过Py2exe将自己的python程序打包成.exe/.app的方法
2021-07-05 11:05:55
![](https://img.aspxhome.com/file/2023/6/71306_0s.jpg)
使用python-Jenkins批量创建及修改jobs操作
2023-07-01 01:53:11
![](https://img.aspxhome.com/file/2023/4/82514_0s.jpg)
用 iframe 解决下拉框与层之冲突
2008-04-28 12:24:00
![](https://img.aspxhome.com/file/UploadPic/20071/2007131102430882s.gif)
vscode 远程调试python的方法
2021-09-07 23:00:59
![](https://img.aspxhome.com/file/2023/7/83717_0s.png)
装了 Access 2003 安全更新 (KB981716) 之后 Access 打不开
2010-12-09 19:59:00
从长尾理论和二八定律的比较去看用户体验
2009-07-22 19:11:00
![](https://img.aspxhome.com/file/UploadPic/20097/22/longtail-2-8-15s.jpg)
Python代码实现双链表
2021-12-26 15:55:04
![](https://img.aspxhome.com/file/2023/8/93848_0s.jpg)