I'm trying to solve a transportation problem using the networkX library. As my demand and supply values are floats my problem seems to be unsolvable by the networkX package? see documentation on Page 377. https://networkx.org/documentation/stable/_downloads/networkx_reference.pdf
Is there any workaround? My problem results from rounding errors as my floats are really small.
are there any other libraries that support floating point numbers for solving minimum cost flow problems in python?
import networkx as nx
#inputdata
producerDict = {'p1': 3.88, 'p2': 4.3225, 'p3': 24.41575}
consumerDict = {'c1':46.63775, 'c2': 85.44925, 'c3': 71.92425, 'c4':
84.1755}
totalDemand = sum(consumerDict.values())
totalSupply = sum(producerDict.values())
#graph
G = nx.DiGraph()
G.add_edge("C1", "P1", weight=3)
G.add_edge("C1", "P2", weight=1)
G.add_edge("C1", "P3", weight=4)
G.add_edge("C2", "P1", weight=2)
G.add_edge("C2", "P2", weight=4)
G.add_edge("C2", "P3", weight=5)
G.add_edge("C3", "P1", weight=6)
G.add_edge("C3", "P2", weight=2)
G.add_edge("C3", "P3", weight=2)
G.add_edge("C4", "P1", weight=1)
G.add_edge("C4", "P2", weight=6)
G.add_edge("C5", "P3", weight=3)
#balancing the problem as demand > supply
newConsumerDict = {}
for consumer, demand in consumerDict.items():
newDemand = (demand / totalDemand) * totalSupply
newConsumerDict[consumer] = newDemand
# this sum has to be equal to total supply which
# is not the case due to rounding errors
print(sum(newConsumerDict.values()))
flowCost, flowDict = nx.network_simplex(G)
cheers