微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用networkx将数量值填充到python中的网络中?

如何解决如何使用networkx将数量值填充到python中的网络中?

主要问题是,是否有可能在满足每个节点的节点方程的网络中分配一个确定的量?

例如:adding quantity values in a network(mesh) {GIF}

**节点方程:每个节点的流入流量(数量)=流出流量(数量)。

import networkx as nx

inputName = [('D','H'),('G','E'),('B','F'),('H','C'),('E','B'),('C','G'),'A'),('A',('D',('F','D')]
quantity = [0,0]
resistance = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1]
fan = [0,2000,0]
def createDirectedGraph(inputName):
    ventilationNetwork = nx.DiGraph()
    i = 0
    for edge in inputName:
        node_from = edge[0]
        node_to = edge[1]
        ventilationNetwork.add_edge(node_from,node_to)
        ventilationNetwork.edges[node_from,node_to]['quantity'] = quantity[i]
        ventilationNetwork.edges[node_from,node_to]['resistance'] = resistance[i]
        ventilationNetwork.edges[node_from,node_to]['fan'] = fan[i]
        i += 1
    return ventilationNetwork

我正在尝试以下操作:

count = 1
for node in ventilationNetwork.nodes:
    if count == 1:
        quantity = 100 # Any quantity != 0
        for node_from in ventilationNetwork.predecessors(node):
            ventilationNetwork.edges[node_from,node]['quantity'] = quantity/(len(list(ventilationNetwork.predecessors(node))))
        for node_to in ventilationNetwork.successors(node):
            ventilationNetwork.edges[node,node_to]['quantity'] = quantity/(len(list(ventilationNetwork.successors(node))))
    else:
        sumQ = 0
        for node_from in ventilationNetwork.predecessors(node):
            sumQ += ventilationNetwork.edges[node_from,node]['quantity']
        ventilationNetwork.edges[node_from,node]['quantity'] = sumQ/(len(list(ventilationNetwork.predecessors(node))))
        for node_to in ventilationNetwork.successors(node):
            sumQ += ventilationNetwork.edges[node,node_to]['quantity']
        ventilationNetwork.edges[node,node_to]['quantity'] = sumQ/(len(list(ventilationNetwork.successors(node))))
    count += 1

但它不起作用。它不满足节点方程。

知道如何解决这个问题吗?使用 NetworkX 或不使用 NetworkX。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。