
有6个节点具有负需求和正需求。我需要计算出最好的变体,以满足尽可能多的消费者。我正在尝试使用networkx python库来解决这个问题:
import networkx as nx
G = nx.DiGraph()
G.add_node("1", demand=15)
G.add_node("2", demand=25)
G.add_node("3", demand=60)
G.add_node("4", demand=-55)
G.add_node("5", demand=-35)
G.add_node("6", demand=-40)
G.add_edge("1", "2", weight=2)
G.add_edge("1", "3", weight=1)
G.add_edge("1", "6", weight=3)
G.add_edge("2", "6", weight=4)
G.add_edge("2", "3", weight=5)
G.add_edge("3", "4", weight=3)
G.add_edge("4", "5", weight=6)
G.add_edge("5", "6", weight=2)
flowCost = nx.min_cost_flow_cost(G)
print(flowCost)但据我所知,问题是我的消极和积极需求的总结不是零,我得到了错误:
networkx.exception.NetworkXUnfeasible: total node demand is not zero那么这个问题有什么解决方案吗?也许使用不同的库会更好?
发布于 2021-05-07 03:26:26
尝试添加以下代码:
G.add_node("7", demand = 30)
G.add_edge("4", "7", weight = 7)
G.add_edge("5", "7", weight = 7)
G.add_edge("6", "7", weight = 7)https://stackoverflow.com/questions/67423381
复制相似问题