I got this error. "TypeError: float argument required, not str"
Yes, the script that I attached has no problem itself. I believe that the data imported from CSV used in a linear programming calculation could cause the issue. And I also wonder your csvfile has texts...
I upload all the entire script just for clarifying my issue.
import csv
from pulp import *
supplyData = {}
with open('C:\\scripts\\oil_sd.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
supplyData[row['originid']] = [row['oilseed'], 0]
demandData = {}
with open('C:\\scripts\\fu_stn.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
demandData[row['destinationid'])] = [0, row['oilseed']]
nodeData = {}
nodeData = dict(supplyData.items() + demandData.items())
Nodes = [(b) for b in nodeData.keys()]
arcData = {}
with open('C:\\scripts\\route.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
arcData[row["originid"], row["destinationid"]]=[row['cost'], row['min'], row['max']]
Arcs =[(k) for k in arcData.keys()]
(supply, demand) = splitDict(nodeData)
(costs, mins, maxs) = splitDict(arcData)
vars = LpVariable.dicts("Route",Arcs,None,None,LpInteger)
for a in Arcs:
vars.bounds(mins, maxs)
prob = LpProblem("Supply Chain Problem",LpMinimize)
prob += lpSum([vars* int(costs) for a in Arcs]), "Total Cost of Transport"
prob.writeLP("OilseedSupplyChain.lp")
prob.solve()
print("Status:", LPStatus[prob.status])
for v in prob.variables():
print(v.name, "=", v.varValue)
print("Total Cost of Transportation = ", value(prob.objective))