-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadfile.py
More file actions
29 lines (24 loc) · 731 Bytes
/
readfile.py
File metadata and controls
29 lines (24 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import sys
import time
# there are two types of input file to be dealt with
# 1. tsp; 2. GEO
def read_data(input_name):
'''
e.g: data = read_data(input data file)
args: input data file
Return: Nx3 matrix:
N is the number of node
each row: [node_id, x, y]
'''
data = []
with open(input_name, "r") as file:
lines = file.readlines()
for i in range(len(lines)):
# deal with different input
if lines[i][0].isdigit():
node_id, x, y = lines[i].split(" ")
data.append([int(node_id),
float(x),
float(y)])
return data