Ejemplo n.º 1
0
import pandas as pd

time = 300
noise = 5
number_of_clusters = 1
N = 30
K = 2
graphs = [rn.Random_Network(N, 2) for i in range(number_of_clusters)]
single_cluster_control_nodes = [
    rn.find_control_nodes(graphs[i], N) for i in range(number_of_clusters)
]
control_nodes = [
    single_cluster_control_nodes[i] + i * N for i in range(number_of_clusters)
]
tot = rn.create_clusters(graphs, control_nodes, N, number_of_clusters)
Net = rn.Network(tot)
############# INITIAL CONDITIONS ########################
# for i in range(number_of_clusters):
#     Net.nodes[control_nodes[i]] = 1
#     Net.nodes[np.random.randint(N*i,N*(i+1))] = 1

Net.nodes = np.ones((N * number_of_clusters, 1))

for i in range(noise):
    activities = []
    Net = rn.Random_Network(N, K)
    Net.nodes = np.ones((N * number_of_clusters, 1))
    for j in range(time):

        #for i in control_nodes:
        ##### PROBABILITÀ DI AZZERARE IL CONTROL NODE AD OGNI STEP
Ejemplo n.º 2
0
    a = True
    while a:
        try:
            graphs = [rn.Random_Network(N, K)]
            graphs.append(rn.Random_Network(M, K1))
            control_nodes.append([
                graphs[i].control_nodes[0] + i * N
                for i in range(number_of_clusters)
            ])
            env_control_nodes.append([
                graphs[i].control_nodes[1] + i * N
                for i in range(number_of_clusters)
            ])
            tot = rn.create_net(graphs, control_nodes[i], env_control_nodes[i],
                                N, M)
            net = rn.Network(tot, number_of_clusters)
            qx.append(net)
            a = False
        except:
            pass

######################### INITIAL CONDITIONS ################################
# for i in range(realizations):
#     #qx[i].nodes[np.random.randint(N+M)] = 1
    for j in range(N, N + M):
        qx[i].nodes[j] = 1
#############################################################################
act = np.zeros(realizations)
t = np.zeros(realizations)

times = []
Ejemplo n.º 3
0
number_of_clusters = 3

#creation of the subnetworks
gr = [rn.Random_Network(N, K) for i in range(number_of_clusters)]

single_cluster_control_nodes = [
    rn.find_control_nodes(gr[i], N) for i in range(number_of_clusters)
]
control_nodes = [
    single_cluster_control_nodes[i] + i * N for i in range(number_of_clusters)
]
tot = rn.create_clusters(gr, control_nodes, N, number_of_clusters)
negedges = list(zip(list(np.where(tot.T < 0)[0]),
                    list(np.where(tot.T < 0)[1])))

Net = rn.Network(tot)
graph = nx.from_numpy_matrix(tot.T, create_using=nx.DiGraph)
npos = nx.spring_layout(graph)
cycles = nx.cycle_basis(graph.to_undirected())

################## ONLY FOR VISUALIZATION #######################
abs_tot = abs(tot)
graph1 = nx.from_numpy_matrix(abs_tot.T, create_using=nx.DiGraph)
npos = nx.kamada_kawai_layout(graph1)
#################################################################

##########################################################################################################
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)

f0 = 1