Kuifje02 / vrpy

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

Potential Bug with "return self._adjdict[u][v]" #121

Closed mm04926412 closed 2 years ago

mm04926412 commented 2 years ago

Here is my code

AM = pd.read_csv("Sample Data/Adjacency Matrix.csv",index_col=0).astype(int)
DM = pd.read_csv("Sample Data/Distance Matrix.csv",index_col=0).astype(float)
DD = pd.read_csv("Sample Data/Demand Data.csv",index_col=0).astype(float)

ship_slots = 6
speed = 1

G = nx.DiGraph()
G.add_node("Source")
G.add_node("Sink")
for i,name_i in enumerate(AM.columns):
    G.add_node(i)
for i,name_i in enumerate(AM.columns):  
    G.add_edge("Source",i,cost=0)
    G.add_edge(i,"Sink",cost=0) 
    for j,name_j in enumerate(AM.columns):
        if AM.loc[name_i,name_j] !=0:
            G.add_edge(i,j,cost=DM.iloc[i,j])
for i,j in zip(DD.iloc[0,:],range(len(AM.columns))):
    if i < 0:
        G.nodes[j]["demand"] = i
    if i>0:
        G.nodes[j]["request"] = i
print(G)
nx.draw(G,with_labels=True)
plt.savefig("Graph.png")

print(G.edges._adjdict)
prob = VehicleRoutingProblem(G,load_capacity = 50)
prob.pickup_delivery = True
prob.solve(cspy=False)

and I get the following output

DiGraph with 7 nodes and 20 edges
{'Source': {0: {'cost': 0}, 1: {'cost': 0}, 2: {'cost': 0}, 3: {'cost': 0}, 4: {'cost': 0}}, 'Sink': {}, 0: {'Sink': {'cost': 0}, 1: {'cost': 2.236067977}, 2: {'cost': 4.123105626}}, 1: {'Sink': {'cost': 0}, 0: {'cost': 2.236067977}, 2: {'cost': 2.828427125}}, 2: {'Sink': {'cost': 0}, 0: {'cost': 4.123105626}, 1: {'cost': 2.828427125}, 3: {'cost': 6.08276253}}, 3: {'Sink': {'cost': 0}, 2: {'cost': 6.08276253}, 4: {'cost': 3.16227766}}, 4: {'Sink': {'cost': 0}, 3: {'cost': 3.16227766}}}
WARNING:vrpy.checks:Pricing_strategy changed to 'Exact'.
Traceback (most recent call last):
  File "Route_Solver.py", line 38, in <module>
    prob.solve(cspy=False)
  File "/home/michael/anaconda3/envs/vrpy/lib/python3.8/site-packages/vrpy/vrp.py", line 252, in solve
    self._initialize(solver)
  File "/home/michael/anaconda3/envs/vrpy/lib/python3.8/site-packages/vrpy/vrp.py", line 478, in _initialize
    self._convert_initial_routes_to_digraphs()
  File "/home/michael/anaconda3/envs/vrpy/lib/python3.8/site-packages/vrpy/vrp.py", line 945, in _convert_initial_routes_to_digraphs
    edge_cost = self.G.edges[i, j]["cost"][0]
  File "/home/michael/anaconda3/envs/vrpy/lib/python3.8/site-packages/networkx/classes/reportviews.py", line 1032, in __getitem__
    return self._adjdict[u][v]
KeyError: 10.0

I am using version 0.5.1 on python 3.8 alongside networkx 2.6.3

ErikUGent commented 1 year ago

Dear,

I get the same issue with my examples. I find a solution for 8,16,32 and 40 nodes, but not for the example with 24 nodes.

I get the same error as you above.

Thanks for your feedback! Erik