Skip to content

Commit 7bd20dd

Browse files
committed
Refactored all plotting and combined them in Plot_Graph
1 parent 833c6fb commit 7bd20dd

6 files changed

Lines changed: 218 additions & 217 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,6 @@ cython_debug/
161161

162162
**/Solution
163163

164-
*.pdf
164+
*.pdf
165+
166+
*test*.py

Draw_Base_Graph_VRPPDTW.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

Draw_Solution_Raw_VRPPDTW.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

Draw_Solution_VRPPDTW.py

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import csv
12
import networkx as nx
23

34
def get_full_graph(base_directory):
4-
nodes_file = base_directory + "Nodes.txt"
5-
edges_file = base_directory + "Edges.txt"
6-
requests = get_requests(base_directory + "Requests.txt")
5+
nodes_file = base_directory + "Nodes.csv"
6+
edges_file = base_directory + "Edges.csv"
7+
requests = get_requests(base_directory + "Requests.csv")
78
graph = create_graph(nodes_file, edges_file, requests)
89

910
return graph, requests
@@ -27,15 +28,13 @@ def convert_to_minutes(time_str):
2728
def read_nodes(nodes_file, requests):
2829
nodes = {}
2930
with open(nodes_file, 'r') as file:
30-
for line in file:
31-
line = line.strip()
32-
if line.startswith('#') or not line.strip():
33-
continue # Ignore comment lines and empty lines
34-
data = line.split('|')
35-
node_id = int(data[0])
36-
x = float(data[1])
37-
y = float(data[2])
38-
name = data[3] if len(data) > 3 else None
31+
reader = csv.reader(file)
32+
next(reader, None)
33+
for i, line in enumerate(reader):
34+
node_id = int(line[0])
35+
x = float(line[1])
36+
y = float(line[2])
37+
name = line[3] if len(line) > 3 else None
3938
node = {'node_id': node_id, 'x': x, 'y': y, 'name': name, 'node_type' : 'Junction Node'}
4039
nodes[node_id] = node
4140

@@ -49,12 +48,10 @@ def read_nodes(nodes_file, requests):
4948
def read_edges(filename):
5049
edges = {}
5150
with open(filename, 'r') as file:
52-
for line in file:
53-
line = line.strip()
54-
if line.startswith('#') or not line.strip():
55-
continue # Ignore comment lines and empty lines
56-
data = line.split('|')
57-
edge_id, source, target, weight = data
51+
reader = csv.reader(file)
52+
next(reader, None)
53+
for i, line in enumerate(reader):
54+
edge_id, source, target, weight = line
5855
edges[edge_id] = {'edge_id': edge_id, 'origin': int(source),
5956
'destination': int(target), 'travel_time': float(weight)}
6057
return edges
@@ -79,21 +76,19 @@ def create_graph(nodes_file, edges_file, requests):
7976
def get_requests(filename):
8077
requests = {}
8178
with open(filename, 'r') as file:
82-
for line in file:
83-
line = line.strip()
84-
if line.startswith('#') or not line.strip():
85-
continue # Ignore comment lines and empty lines
86-
data = line.split('|')
87-
request_id = int(data[0])
88-
origin = int(data[1])
89-
destination = int(data[2])
90-
count = int(data[3])
91-
earliest_departure_o = convert_to_minutes(data[4])
92-
latest_departure_o = convert_to_minutes(data[5])
93-
service_time_o = convert_to_minutes(data[6])
94-
earliest_departure_d = convert_to_minutes(data[7])
95-
latest_departure_d = convert_to_minutes(data[8])
96-
service_time_d = convert_to_minutes(data[9])
79+
reader = csv.reader(file)
80+
next(reader, None)
81+
for i, line in enumerate(reader):
82+
request_id = int(line[0])
83+
origin = int(line[1])
84+
destination = int(line[2])
85+
count = int(line[3])
86+
earliest_departure_o = convert_to_minutes(line[4])
87+
latest_departure_o = convert_to_minutes(line[5])
88+
service_time_o = convert_to_minutes(line[6])
89+
earliest_departure_d = convert_to_minutes(line[7])
90+
latest_departure_d = convert_to_minutes(line[8])
91+
service_time_d = convert_to_minutes(line[9])
9792
requests[request_id] = (origin, destination, count, earliest_departure_o,
9893
latest_departure_o, service_time_o, earliest_departure_d,
9994
latest_departure_d, service_time_d)
@@ -102,14 +97,12 @@ def get_requests(filename):
10297
def get_vehicles(filename):
10398
buses = {}
10499
with open(filename, 'r') as file:
105-
for line in file:
106-
line = line.strip()
107-
if line.startswith('#') or not line.strip():
108-
continue # Ignore comment lines and empty lines
109-
data = line.split('|')
110-
bus_id = int(data[0])
111-
origin_id = int(data[1])
112-
destination_id = int(data[2])
113-
capacity = int(data[3])
100+
reader = csv.reader(file)
101+
next(reader, None)
102+
for i, line in enumerate(reader):
103+
bus_id = int(line[0])
104+
origin_id = int(line[1])
105+
destination_id = int(line[2])
106+
capacity = int(line[3])
114107
buses[bus_id] = (origin_id, destination_id, capacity)
115108
return buses

0 commit comments

Comments
 (0)