Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division
- import networkx as nx
- import matplotlib.pyplot as plt
- import numpy as np
- from numpy.linalg import inv
- G = nx.Graph()
- pos={1:(2,3),2:(0,0),3:(6,0)}
- G.add_nodes_from(pos.keys())
- nx.set_node_attributes(G, 'coord', pos)
- PE={1:0,2:60,3:40}
- nx.set_node_attributes(G,'PE',PE)
- q={1:100,2:0,3:0}
- nx.set_node_attributes(G,'q',q)
- G.add_edge(1,2)
- G.add_edge(1,3)
- G.add_edge(2,3)
- import math
- lengths={}
- inv_lengths={}
- for edge in G.edges():
- startnode=edge[0]
- endnode=edge[1]
- lengths[edge]=round(math.sqrt(((pos[endnode][1]-pos[startnode][1])**2)+
- ((pos[endnode][0]-pos[startnode][0])**2)),2)
- inv_lengths[edge]=round(1/lengths[edge],3)
- nx.set_edge_attributes(G, 'length', lengths)
- nx.set_edge_attributes(G, 'inv_length', inv_lengths)
- nx.draw(G,pos,node_size=1000,node_color='r',with_labels=True)
- nx.draw_networkx_edge_labels(G,pos,edge_labels=flow)
- plt.show()
- b=[]
- for i,v in enumerate(PE.values()):
- b.append(v)
- res2=np.dot(a,b) #No inverse is required: x=ab
- res2=[round(item,3) for sublist in res2.tolist() for item in sublist]
- print res2
- #res=[-24.62, 19.96, 4.66]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement