########################################################### # # # Exercise 4.14: # # # # Construct an ROBDD for a given k-out-of-n # # system and evaluate its reliability # # # ########################################################### from c_robdd import ROBDDSystem from c_threshold import ROBDDThreshold import matplotlib.pyplot as plt import numpy as np save_plots = True # Component reliabilities p = 0.5 k = 13 n = 25 # Number of plot points points = 100 # Component weights a = [] for _ in range(n): a.append(1) sys = ROBDDSystem(ROBDDThreshold(a, n, k)) result = sys.calculateReliability0(p) sys.printSystem() print("") print("System unreliability = ", result[0]) print("System reliability = ", result[1]) pp = np.linspace(0.0, 1.0, points) uu = np.zeros(points) hh = np.zeros(points) for i in range(points): result = sys.calculateReliability0(pp[i]) uu[i] = result[0] hh[i] = result[1] fig = plt.figure(figsize = (7, 4)) plt.plot(pp, uu, label='u(p)') plt.plot(pp, hh, label='h(p)') plt.xlabel('p') # plt.ylabel('h and u') plt.title("Reliability / unreliability vs. p") plt.legend() if save_plots: plt.savefig("k_out_of_n/relplot_" + str(k) + "_" + str(n) + ".pdf") plt.show()