Skip to content

Instantly share code, notes, and snippets.

@bunelr
Created February 24, 2017 15:20
Show Gist options
  • Save bunelr/0f73190d230e782912af99e2c42029bf to your computer and use it in GitHub Desktop.
Save bunelr/0f73190d230e782912af99e2c42029bf to your computer and use it in GitHub Desktop.
def parse_input_file(in_filename):
with open(in_filename, 'r') as in_file:
first_line = in_file.readline()
nb_vid, nb_end, nb_req, nb_cache, capacity = map(int, first_line.split(' '))
video_weight_line = in_file.readline()
video_weights = np.array(list(map(int, video_weight_line.split(' '))))
datacenter_to_end_latency = np.ndarray(nb_end)
end2cachelatency = []
for end_point_idx in range(nb_end):
dc_lat, nb_conn_cache = map(int, in_file.readline().split(' '))
datacenter_to_end_latency[end_point_idx] = dc_lat
cache_latencies = {}
for _ in range(nb_conn_cache):
line = in_file.readline()
cache_id, cache_end_latency = map(int, line.split(' '))
cache_latencies[cache_id] = cache_end_latency
end2cachelatency.append(cache_latencies)
requests = []
end_and_vid_2_req_id = {}
for req_idx in range(nb_req):
line = in_file.readline()
vid_id, end_id, req_in_end = map(int, line.split(' '))
requests.append((vid_id, end_id, nb_req))
end_and_vid_2_req_id[(end_id, vid_id)] = req_idx
return nb_vid, nb_end, nb_req, nb_cache, capacity, video_weights, datacenter_to_end_latency, end2cachelatency, requests, end_and_vid_2_req_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment