19 FILE *fp = fopen(filename,
"r");
21 perror(
"Error while opening the file.\n");
22 printf(
"\nFile: %s\n", filename);
28 bool check_euc_2d =
false;
29 while (getline(&line, &len, fp) != -1 &&
30 strstr(line,
"NODE_COORD_SECTION") == NULL) {
31 if (strstr(line,
"EDGE_WEIGHT_TYPE : EUC_2D") == NULL) {
37 perror(
"The current TSP file is not an euclidean one.\n");
38 printf(
"\nFile: %s\n", filename);
43 Node nodes[MAX_VERTEX_NUM];
46 bool end_of_file =
false;
47 while (getline(&line, &len, fp) != -1 && !end_of_file) {
48 if (strstr(line,
"EOF") == NULL) {
53 int result = sscanf(line,
"%hu %f %f", &
id, &x, &y);
55 perror(
"Error while reading the file.\n");
56 printf(
"\nFile: %s\n", filename);
70 if (fclose(fp) == EOF) {
71 perror(
"Error while closing the file.\n");
72 printf(
"\nFile: %s\n", filename);
80 FILE *fp = fopen(filename,
"r");
82 perror(
"Error while opening the file.\n");
83 printf(
"\nFile: %s\n", filename);
96 while (getline(&line, &len, fp) != -1) {
100 char *token = strtok(line,
";");
101 unsigned short node_num = 0;
102 while (token != NULL && strcmp(token,
"\n") != 0) {
104 int result = sscanf(token,
"(%lf, %lf)", &x, &y);
106 perror(
"Error while reading the file.\n");
107 printf(
"\nFile: %s\n", filename);
111 graph->
nodes[node_num].
x = x;
112 graph->
nodes[node_num].
y = y;
115 token = strtok(NULL,
";");
120 char *token = strtok(line,
";");
121 unsigned short j = 0;
122 while (token != NULL && strcmp(token,
"\n") != 0) {
124 double weight = 0, prob = 0;
126 int result = sscanf(token,
"(%lf, %lf)", &weight, &prob);
128 perror(
"Error while reading the file.\n");
129 printf(
"\nFile: %s\n", filename);
140 graph->
edges[z].
prob = HYBRID ? prob : 0;
155 token = strtok(NULL,
";");
162 if (fclose(fp) == EOF) {
163 perror(
"Error while closing the file.\n");
164 printf(
"\nFile: %s\n", filename);
void create_euclidean_graph(Graph *graph, List *nodes)
Create a new instance of an euclidean graphs only the Nodes are necessary.
@ WEIGHTED_GRAPH
The Graph is weighted.
void add_elem_list_bottom(List *list, void *element)
Adds an DllElem to the bottom of the List.
List * new_list(void)
Create a new instance of a List.
unsigned short dest
ID of the destination vertex.
unsigned short src
ID of the source vertex.
double prob
Probability of the Edge to be in an optimal tour.
double weight
Weight of the Edge, 1 if the data_structures is not weighted.
unsigned short symbol
Symbol of the Edge, i.e. its unique ID.
unsigned short positionInGraph
Position of the Edge in the list of Edges of the Graph.
Edge edges_matrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM]
Adjacency matrix of the Graph.
unsigned short num_edges
Number of Edges in the Graph.
bool orderedEdges
True if the Edges are ordered by weight, false otherwise.
Edge edges[MAX_EDGES_NUM]
Array of Edges.
GraphKind kind
Type of the Graph.
Node nodes[MAX_VERTEX_NUM]
Array of Nodes.
double cost
Sum of the weights of the Edges in the Graph.
unsigned short num_nodes
Number of Nodes in the Graph.
double x
x coordinate of the Node.
double y
y coordinate of the Node.
unsigned short num_neighbours
Number of neighbours of the Node.
unsigned short positionInGraph
Position of the Node in the list of Nodes of the Graph, i.e. its unique ID.
unsigned short neighbours[MAX_VERTEX_NUM - 1]
Array of IDs of the Node's neighbors.
void read_tsp_lib_file(Graph *graph, char *filename)
Reads a .tsp file and stores the data in the Graph.
void read_tsp_csv_file(Graph *graph, char *filename)
Reads a .csv file and stores the data in the Graph.
The declaration of the function to read input files.