def read_graph(filename):
file = open(filename, '<STR_LIT:r>');<EOL>comments = "<STR_LIT>";<EOL>space_descr = [];<EOL>data = [];<EOL>data_type = None;<EOL>map_data_repr = dict();   <EOL>for line in file:<EOL><INDENT>if (line[<NUM_LIT:0>] == '<STR_LIT:c>' or line[<NUM_LIT:0>] == '<STR_LIT:p>'): <EOL><INDENT>comments += line[<NUM_LIT:1>:]; <EOL><DEDENT>elif (line[<NUM_LIT:0>] == '<STR_LIT:r>'): <EOL><INDENT>node_coordinates = [float(val) for val in line[<NUM_LIT:1>:].split()];<EOL>if (len(node_coordinates) != <NUM_LIT:2>):<EOL><INDENT>raise NameError('<STR_LIT>');<EOL><DEDENT>space_descr.append( [float(val) for val in line[<NUM_LIT:1>:].split()] );<EOL><DEDENT>elif (line[<NUM_LIT:0>] == '<STR_LIT:m>'):<EOL><INDENT>if ( (data_type is not None) and (data_type != '<STR_LIT:m>') ):<EOL><INDENT>raise NameError('<STR_LIT>');<EOL><DEDENT>data_type = '<STR_LIT:m>';<EOL>data.append( [float(val) for val in line[<NUM_LIT:1>:].split()] );<EOL><DEDENT>elif (line[<NUM_LIT:0>] == '<STR_LIT:v>'):<EOL><INDENT>if ( (data_type is not None) and (data_type != '<STR_LIT:v>') ):<EOL><INDENT>raise NameError('<STR_LIT>');<EOL><DEDENT>data_type = '<STR_LIT:v>';<EOL>data.append( [float(val) for val in line[<NUM_LIT:1>:].split()] );<EOL><DEDENT>elif (line[<NUM_LIT:0>] == '<STR_LIT:e>'):<EOL><INDENT>if ( (data_type is not None) and (data_type != '<STR_LIT:e>') ):<EOL><INDENT>raise NameError('<STR_LIT>');<EOL><DEDENT>data_type = '<STR_LIT:e>';<EOL>vertices = [int(val) for val in line[<NUM_LIT:1>:].split()];<EOL>if (vertices[<NUM_LIT:0>] not in map_data_repr):<EOL><INDENT>map_data_repr[ vertices[<NUM_LIT:0>] ] = [ vertices[<NUM_LIT:1>] ];<EOL><DEDENT>else:<EOL><INDENT>map_data_repr[ vertices[<NUM_LIT:0>] ].append(vertices[<NUM_LIT:1>])<EOL><DEDENT>if (vertices[<NUM_LIT:1>] not in map_data_repr):<EOL><INDENT>map_data_repr[ vertices[<NUM_LIT:1>] ] = [ vertices[<NUM_LIT:0>] ];<EOL><DEDENT>else:<EOL><INDENT>map_data_repr[ vertices[<NUM_LIT:1>] ].append(vertices[<NUM_LIT:0>]);<EOL><DEDENT><DEDENT>elif (len(line.strip()) == <NUM_LIT:0>): continue;<EOL>else: <EOL><INDENT>print(line);<EOL>raise NameError('<STR_LIT>');<EOL><DEDENT><DEDENT>if (data_type == '<STR_LIT:e>'):<EOL><INDENT>for index in range(len(map_data_repr)):<EOL><INDENT>data.append([<NUM_LIT:0>] * len(map_data_repr));<EOL>for index_neighbour in map_data_repr[index + <NUM_LIT:1>]:<EOL><INDENT>data[index][index_neighbour - <NUM_LIT:1>] = <NUM_LIT:1>;<EOL><DEDENT><DEDENT><DEDENT>file.close();<EOL>graph_descr = None;<EOL>if (data_type == '<STR_LIT:m>'): graph_descr = type_graph_descr.GRAPH_MATRIX_DESCR;<EOL>elif (data_type == '<STR_LIT:v>'): graph_descr = type_graph_descr.GRAPH_VECTOR_DESCR;<EOL>elif (data_type == '<STR_LIT:e>'): graph_descr = type_graph_descr.GRAPH_MATRIX_DESCR;<EOL>else:<EOL><INDENT>raise NameError('<STR_LIT>');<EOL><DEDENT>if (space_descr != []):<EOL><INDENT>if (len(data) != len(space_descr)):<EOL><INDENT>raise NameError("<STR_LIT>");<EOL><DEDENT><DEDENT>return graph(data, graph_descr, space_descr, comments)<EOL>
!
    @brief Read graph from file in GRPR format.

    @param[in] filename (string): Path to file with graph in GRPR format.

    @return (graph) Graph that is read from file.