当前位置:网站首页>Two terminal network reliability

Two terminal network reliability

2021-05-04 14:53:53 Come to Wanli

In network reliability , A more classic and more commonly used reliability calculation in practice is two terminal reliability , That is, given the network topology and edge reliability ( Assume that the nodes are completely reliable ), Calculate the connectivity reliability between two specified nodes in the network .

Here it is , According to the idea of minimal path set, the author gives the definition of this method python Code implementation , The code can be based on a given input matrix 、 The connection reliability between two nodes can be calculated by setting the number of nodes .

The logic code and test cases are as follows :

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("+")
        
        # Delete the specified order , The path length is not equal to the order of the path 
        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)

In the first part , This paper mainly defines several functions to calculate the minimal path set and to calculate the two terminal reliability by using the inclusion exclusion principle , The final outer function is Matrix_label(data,my_dict,index_start,index_end):

Parameter interpretation :

data: Data in matrix form , Characterizes the topology and edge reliability of the whole network , Each of the matrix elements is either 0, Or preset letters like “A、B、C” etc. , The value of each letter is 0 To 1( It doesn't contain 0 But it includes 1), Element is 0 Indicates that the nodes corresponding to row and column numbers are connected without edges , The elements are letters such as “A” It means that the reliability between nodes corresponding to row number and column number is A The probability of being connected ;
my_dict: Data in dictionary form , Specify the probability value of each letter used , Such as {'A':0.8,'B':0.9,'C':0.9}, In particular, it is pointed out that the connection probability between nodes in the network can be different ;
index_start: 2. Starting point serial number in terminal node ;
index_end: 2. The serial number of the termination point in the terminal node ;

版权声明
本文为[Come to Wanli]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/05/20210504145053930x.html

随机推荐