################################################################### # # # This program plots h(p(t)) as a function of t for a system # # with given minimal path sets using Monte Carlo simulations of # # the component lifetimes and calculating the resulting system # # lifetime. # # # ################################################################### from math import * from random import * import matplotlib.pyplot as plt import numpy as np # Number of simulations num_sims = 100000 # Weibull-parameters for the components alpha = [2.0, 2.5, 3.0, 1.0, 1.5] beta = [50.0, 60.0, 70.0, 40.0, 50.0] # Number of components and minimal paths num_comps = 5 num_paths = 4 # Minimal path sets paths = [{1,4}, {1,3,5}, {2,3,4}, {2,5}] # Calculate the system lifetime given the component lifetimes def sys_lifetime(tt): sys_life = 0.0 for j in range(num_paths): path_life = np.inf for i in paths[j]: if tt[i-1] < path_life: path_life = tt[i-1] if path_life > sys_life: sys_life = path_life return sys_life # The upper percentile levels q = np.zeros(num_sims) # The simulated system lifetimes s = np.zeros(num_sims) # The simulated lifetimes of the components t = np.zeros(num_comps) for k in range(num_sims): q[k] = 1.0 - k / num_sims for i in range(num_comps): t[i] = weibullvariate(beta[i], alpha[i]) s[k] = sys_lifetime(t) s.sort() fig = plt.figure(figsize = (7, 4)) plt.plot(s, q, label='h(p(t))') plt.xlabel('Time') plt.ylabel('Reliability') plt.title("System reliability as a function of time") plt.legend() plt.show()