Skip to content

Commit fd1406b

Browse files
committed
Changed Cost Implementation - Added Utils
1 parent bb61656 commit fd1406b

8 files changed

Lines changed: 525 additions & 71 deletions

File tree

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,3 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161-
162-
**/Solution
163-
164-
*.pdf
165-
*.docx
166-
167-
*test*.py

Parsing.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import networkx as nx
33

44
def get_full_graph(base_directory):
5+
# Read input data including vehicles, request, nodes and edges
56
nodes_file = base_directory + "Nodes.csv"
67
edges_file = base_directory + "Edges.csv"
78
requests = get_requests(base_directory + "Requests.csv")
89
vehicles = get_vehicles(base_directory + "Vehicles.csv")
910
graph = create_graph(nodes_file, edges_file, requests, vehicles)
1011

11-
return graph, requests
12+
return graph, requests, vehicles
1213

1314
def convert_to_minutes(time_str):
1415
# Split the string into hours and minutes
@@ -57,9 +58,10 @@ def read_edges(filename):
5758
reader = csv.reader(file)
5859
next(reader, None)
5960
for i, line in enumerate(reader):
60-
edge_id, source, target, weight = line
61+
edge_id, source, target, travel_time, distance = line
6162
edges[edge_id] = {'edge_id': edge_id, 'origin': int(source),
62-
'destination': int(target), 'travel_time': float(weight)}
63+
'destination': int(target), 'travel_time': float(travel_time),
64+
'distance' : float(distance)}
6365
return edges
6466

6567
def create_graph(nodes_file, edges_file, requests, vehicles):
@@ -72,10 +74,10 @@ def create_graph(nodes_file, edges_file, requests, vehicles):
7274
G.add_node(index, **value)
7375

7476
for index, (key, edge) in enumerate(edges.items(), start=0):
75-
G.add_edge(edge['origin'], edge['destination'],
76-
weight=edge['travel_time'], id=edge['edge_id'])
77-
G.add_edge(edge['destination'], edge['origin'],
78-
weight=edge['travel_time'], id=edge['edge_id'])
77+
G.add_edge(edge['origin'], edge['destination'], travel_time=edge['travel_time'],
78+
distance=edge['distance'], id=edge['edge_id'])
79+
G.add_edge(edge['destination'], edge['origin'], travel_time=edge['travel_time'],
80+
distance=edge['distance'], id=edge['edge_id'])
7981

8082
return G
8183

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
{
2+
"0": [
3+
{
4+
"origin_dest_ids": [
5+
10,
6+
1
7+
],
8+
"start_time": "0:0",
9+
"finish_time": "6:0",
10+
"start_load": 0,
11+
"finish_load": 1,
12+
"path": [
13+
10,
14+
11,
15+
12,
16+
2,
17+
3
18+
],
19+
"path_cost": 19.75,
20+
"travel_time": 16.0,
21+
"travel_distance": 10.3,
22+
"status": "Picking Up Request 1 at Node 3"
23+
},
24+
{
25+
"origin_dest_ids": [
26+
1,
27+
4
28+
],
29+
"start_time": "6:0",
30+
"finish_time": "7:40",
31+
"start_load": 1,
32+
"finish_load": 3,
33+
"path": [
34+
3,
35+
13,
36+
14,
37+
6
38+
],
39+
"path_cost": 12.95,
40+
"travel_time": 9.5,
41+
"travel_distance": 4.5,
42+
"status": "Picking Up Request 4 at Node 6",
43+
"Total_Cost": 106.35000000000001,
44+
"Total_Travel_time": 69.0,
45+
"Total_Distance": 39.900000000000006
46+
},
47+
{
48+
"origin_dest_ids": [
49+
4,
50+
3
51+
],
52+
"start_time": "7:40",
53+
"finish_time": "7:52",
54+
"start_load": 3,
55+
"finish_load": 5,
56+
"path": [
57+
6,
58+
7,
59+
4
60+
],
61+
"path_cost": 10.65,
62+
"travel_time": 6.5,
63+
"travel_distance": 3.5,
64+
"status": "Picking Up Request 3 at Node 4"
65+
},
66+
{
67+
"origin_dest_ids": [
68+
3,
69+
9
70+
],
71+
"start_time": "7:52",
72+
"finish_time": "8:10",
73+
"start_load": 5,
74+
"finish_load": 3,
75+
"path": [
76+
4,
77+
5,
78+
8,
79+
11,
80+
9
81+
],
82+
"path_cost": 15.9,
83+
"travel_time": 12.5,
84+
"travel_distance": 6.8,
85+
"status": "Delivering Request 4 at Node 9"
86+
},
87+
{
88+
"origin_dest_ids": [
89+
9,
90+
8
91+
],
92+
"start_time": "8:10",
93+
"finish_time": "8:28",
94+
"start_load": 3,
95+
"finish_load": 1,
96+
"path": [
97+
9,
98+
11,
99+
12
100+
],
101+
"path_cost": 14.25,
102+
"travel_time": 10.0,
103+
"travel_distance": 6.5,
104+
"status": "Delivering Request 3 at Node 12"
105+
},
106+
{
107+
"origin_dest_ids": [
108+
8,
109+
2
110+
],
111+
"start_time": "8:28",
112+
"finish_time": "8:40",
113+
"start_load": 1,
114+
"finish_load": 5,
115+
"path": [
116+
12,
117+
2,
118+
15
119+
],
120+
"path_cost": 8.4,
121+
"travel_time": 4.0,
122+
"travel_distance": 2.0,
123+
"status": "Picking Up Request 2 at Node 15"
124+
},
125+
{
126+
"origin_dest_ids": [
127+
2,
128+
7
129+
],
130+
"start_time": "8:40",
131+
"finish_time": "12:0",
132+
"start_load": 5,
133+
"finish_load": 1,
134+
"path": [
135+
15,
136+
2
137+
],
138+
"path_cost": 7.25,
139+
"travel_time": 2.5,
140+
"travel_distance": 1.5,
141+
"status": "Delivering Request 2 at Node 2"
142+
},
143+
{
144+
"origin_dest_ids": [
145+
7,
146+
6
147+
],
148+
"start_time": "12:0",
149+
"finish_time": "12:17",
150+
"start_load": 1,
151+
"finish_load": 0,
152+
"path": [
153+
2,
154+
3,
155+
13,
156+
14
157+
],
158+
"path_cost": 11.35,
159+
"travel_time": 7.0,
160+
"travel_distance": 4.3,
161+
"status": "Delivering Request 1 at Node 14"
162+
},
163+
{
164+
"origin_dest_ids": [
165+
6,
166+
11
167+
],
168+
"start_time": "12:17",
169+
"finish_time": "24:0",
170+
"start_load": 0,
171+
"finish_load": 0,
172+
"path": [
173+
14,
174+
13
175+
],
176+
"path_cost": 5.85,
177+
"travel_time": 1.0,
178+
"travel_distance": 0.5,
179+
"status": "Going to Destination Depot 13"
180+
}
181+
],
182+
"1": [
183+
{
184+
"origin_dest_ids": [
185+
10,
186+
0
187+
],
188+
"start_time": "0:0",
189+
"finish_time": "6:0",
190+
"start_load": 0,
191+
"finish_load": 3,
192+
"path": [
193+
7,
194+
4,
195+
5,
196+
8,
197+
11,
198+
10,
199+
0
200+
],
201+
"path_cost": 18.7,
202+
"travel_time": 15.5,
203+
"travel_distance": 8.8,
204+
"status": "Picking Up Request 0 at Node 0"
205+
},
206+
{
207+
"origin_dest_ids": [
208+
0,
209+
5
210+
],
211+
"start_time": "6:0",
212+
"finish_time": "11:0",
213+
"start_load": 3,
214+
"finish_load": 0,
215+
"path": [
216+
0,
217+
9
218+
],
219+
"path_cost": 7.8,
220+
"travel_time": 3.0,
221+
"travel_distance": 2.0,
222+
"status": "Delivering Request 0 at Node 9",
223+
"Total_Cost": 34.05,
224+
"Total_Travel_time": 21.5,
225+
"Total_Distance": 12.3
226+
},
227+
{
228+
"origin_dest_ids": [
229+
5,
230+
11
231+
],
232+
"start_time": "11:0",
233+
"finish_time": "24:0",
234+
"start_load": 0,
235+
"finish_load": 0,
236+
"path": [
237+
9,
238+
11,
239+
10
240+
],
241+
"path_cost": 7.55,
242+
"travel_time": 3.0,
243+
"travel_distance": 1.5,
244+
"status": "Going to Destination Depot 10"
245+
}
246+
]
247+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"0": [
3+
3,
4+
1,
5+
5,
6+
5,
7+
3,
8+
0,
9+
0,
10+
1,
11+
1,
12+
3,
13+
0,
14+
0
15+
],
16+
"1": [
17+
3,
18+
1,
19+
4,
20+
2,
21+
2,
22+
0,
23+
0,
24+
0,
25+
4,
26+
4,
27+
0,
28+
0
29+
]
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"0": [
3+
"6:0",
4+
"6:0",
5+
"8:40",
6+
"7:52",
7+
"7:40",
8+
"11:0",
9+
"12:17",
10+
"12:0",
11+
"8:28",
12+
"8:10",
13+
"0:0",
14+
"24:0"
15+
],
16+
"1": [
17+
"6:0",
18+
"6:0",
19+
"7:0",
20+
"7:30",
21+
"7:40",
22+
"11:0",
23+
"10:36",
24+
"12:0",
25+
"7:45",
26+
"8:10",
27+
"0:0",
28+
"24:0"
29+
]
30+
}

0 commit comments

Comments
 (0)