Kuifje02 / vrpy

A python framework for solving the VRP and its variants with column generation.
MIT License
179 stars 43 forks source link

Key Error when calling solve() #74

Closed caitriggs closed 3 years ago

caitriggs commented 3 years ago

Getting a key error that references an internal created dict key being called by master_solv_pulp.py. I'm trying to see where the constr_name would've been created from my graph's node name earlier in the call ("visit_node_%s" % node).

DiGraph() was created from nx.from_pandas_edgelist() using cost and demand attributes. Source and Sink nodes were created using cost=0 to simulate OVRP problem:

G = nx.from_pandas_edgelist(df, 'org.cityst', 'dest.cityst', ['demand', 'cost'], create_using=nx.DiGraph())

# Add required Source and Sink nodes
nodes = list(G.nodes)
for node in nodes:
    G.add_edge("Source", node, cost=0)
    G.add_edge(node, "Sink", cost=0)

prob = VehicleRoutingProblem(G, load_capacity=40000)
prob.solve()

Error:

~\Anaconda3\lib\site-packages\vrpy\master_solve_pulp.py in get_duals(self, relax)
     91                 constr_name = "visit_node_%s" % node
     92                 if not relax:
---> 93                     duals[node] = self.prob.constraints[constr_name].pi
     94                 else:
     95                     duals[node] = relax.constraints[constr_name].pi

KeyError: 'visit_node_AUBURNDALE, FL'
Kuifje02 commented 3 years ago

I wonder if the fact that you have a comma in your node name is causing the problem. The node is AUBURNDALE, FL right ?

Maybe give it a try with something like AUBURNDALE_FL

caitriggs commented 3 years ago

I wouldn't think this would matter since it's captured in quotes as a string for the key

testDict = {'HIGH SPRINGS, FL': 'testing spaces in key names'}
testDict['HIGH SPRINGS, FL']

returns 'testing space in key names' as expected

But I'll try it out

caitriggs commented 3 years ago

Yup! Replacing spaces and commas allows the key lookup to work. So must be a python dict instead of dataframe. Thanks!