Created
January 21, 2017 11:42
-
-
Save li-ch/80f59d87f1da2bdd8cb80209c07e257b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import random | |
import numpy as np | |
for k in range(5,64,10): | |
for m in range(1000,10001,2000): | |
mean_time_between_failure = m # unit is hour | |
failRate = 1/mean_time_between_failure | |
time_quantum = 1 # hour | |
btree = nx.balanced_tree(k-1,h) | |
nodelist = btree.nodes() | |
# del nodelist[0] | |
record = list() | |
for t in range(365): | |
temp = btree.copy() | |
fails = sum(np.random.poisson(failRate,24)) | |
RandomSample = random.sample(nodelist, fails) | |
if 0 in RandomSample: | |
record.append(0) | |
continue | |
temp.remove_nodes_from(RandomSample) | |
dtree = nx.dfs_tree(temp,0) | |
record.append(dtree.number_of_nodes()/btree.number_of_nodes()) | |
print("{},{},{},{}".format( | |
h,k,mean_time_between_failure,np.average(record))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment