n_sizes = []
    for i in G.nodes():
        new_size = 100.0 * G.node[i]['state'][0]
        if new_size < 1.0: new_size = 1
        n_sizes.append(new_size)
    e_sizes = []
    for i in G.edges():
        e_sizes.append(G.edge[i[0]][i[1]]['state'])
    nx.draw(G, pos, node_size=n_sizes, node_color='#A0CBE2', 
            edge_color=e_sizes, edge_vmin=0.0, edge_vmax=1.0, width=4,
            edge_cmap=plt.cm.Blues, with_labels=False)
    pylab.draw()
    # Save version during the evolution
    if t > 0.3 and t < 0.31:
        plt.savefig('control_sync_adaptive_edges-middle_state.png')

#=========================================
# SIMULATE THE DYNAMICS
#=========================================

# Save initial topology
visual_reporter(G, 0.0) 
plt.savefig('control_sync_adaptive_edges-start_state.png')

# Simulate the network dynamics
netevo.simulate_rk45(G, 2.0, visual_reporter)

# Save and then close the visualization
plt.savefig('control_sync_adaptive_edges-end_state.png')
plt.close()
# Create the figure to display the visualization
fig = plt.figure(figsize=(6.5,6.5))
# Node positions to use for the visualization
pos = nx.circular_layout(G)
# Function to generate the visualisation of the network
def visual_reporter (G, t):
    plt.clf()
    n_sizes = []
    for i in G.nodes():
        new_size = 100.0 * G.node[i]['state'][0]
        if new_size < 1.0: new_size = 1
        n_sizes.append(new_size)
    e_sizes = []
    for i in G.edges():
        e_sizes.append(G.edge[i[0]][i[1]]['state'])
    nx.draw(G, pos, node_size=n_sizes, node_color='#A0CBE2', 
            edge_color=e_sizes, edge_vmin=0.0, edge_vmax=1.0, width=4,
            edge_cmap=plt.cm.Blues, with_labels=False)
    fig.canvas.draw()

#=========================================
# SIMULATE THE DYNAMICS
#=========================================
    
# Simulate the network dynamics
netevo.simulate_rk45(G, 1.7, visual_reporter)

# Save and then close the visualization
plt.savefig('control_sync_adaptive_edges-final_state.png')
plt.close()
Пример #3
0
    return np.array([v1, v2, v3])

#=========================================
# CREATE THE DYNAMICAL NETWORK
#=========================================

# Create an empty graph (undirected)
G1 = nx.Graph()

# We only need node dynamics
G1.graph['node_dyn'] = True
G1.graph['edge_dyn'] = False

# Create a pair of identical nodes with different initial states
G1.add_node(0)
G1.node[0]['state'] = np.array([2.6, 0.8, 0.9])
G1.node[0]['dyn'] = lorenz_node_dyn
G1.add_node(1)
G1.node[1]['state'] = np.array([1.2, 2.3, 0.2])
G1.node[1]['dyn'] = lorenz_node_dyn

# Connect the nodes with an edge
G1.add_edge(0,1)

#=========================================
# SIMULATE THE NETWORK DYNAMICS
#=========================================

# Simulate the dynamics and print the state to the screen
netevo.simulate_rk45 (G1, 20.0, netevo.state_reporter)