def examples(): network_file_name = "rts.net" # read in the list of components and their probability of failure components = read(open(network_file_name)) N1 = list(uniqueCombinations(components.keys(), 1)) N2 = list(uniqueCombinations(components.keys(), 2)) def comb(n, k): return factorial(n) / (factorial(n - k) * factorial(k)) print "length of components", len(components) print "length of N-1", len(N1) print print "length of N-2", len(N2) assert (len(N1) == len(components)) assert (len(N2) == comb(len(components), 2))
def examples(): network_file_name = "rts.net" # read in the list of components and their probability of failure components = read(open(network_file_name)) N1 = list(uniqueCombinations(components.keys(), 1)) N2 = list(uniqueCombinations(components.keys(), 2)) def comb(n, k): return factorial(n) / (factorial(n - k) * factorial(k)) print "length of components", len(components) print "length of N-1", len(N1) print print "length of N-2", len(N2) assert(len(N1) == len(components)) assert(len(N2) == comb(len(components), 2))
def solveN1(network_file_name="rts.net"): print print("# processing N-1") network_file_name = "rts.net" # read in the list of components and their probability of failure components = read(open(network_file_name)) # prepare the simulator simulate = make_sample_simulator() # grab the samples n_samples = list(uniqueCombinations(components.keys(), 1)) # simulate each sample results = map(simulate, n_samples) for result, fails in zip(results, n_samples): infoline = [1] + list(result) + [len(fails)] + list(fails) csv_print(infoline)
def n_minus_x_generator(x, net_file): for kill_list in uniqueCombinations(sampler.read(net_file).keys(), x): yield 1, Scenario("n-x", 1.0, [1 for _ in range(windlevel.num_wind)], kill_list)