# Two terminal network reliability

2021-05-04 14:53:53

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
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 ：

##### index_end： 2. The serial number of the termination point in the terminal node ;

https://chowdera.com/2021/05/20210504145053930x.html