📄 data_input.c
字号:
/*
ANT-CYCLE ALGORITHM FOR TSP
File: data_input.c
Author: ehui928
Purpose: implementation of data_input.h
Date: 2007-01-18
*/
#include <stdio.h>
#include <stdlib.h>
#include "data_input.h"
#include "tsp.h"
void read_data(char *filename, Point *p)
{
/*
read city corordinates
i,x, y refers to each record in
input file----(city_num, coordinate1,coordinate2)
*/
int i;
double x, y;
int n;
FILE *fp;
if ( (fp = fopen(filename, "r")) == NULL)
{
fprintf(stderr, "can not open file %s\n", filename);
exit(1);
}
n = 1;
while (n < CITY_NUM+1)
{
/*
since x, y all double numbers, so here the
format must be %lf , not %f, otherwise data reading will be error
*/
fscanf(fp, "%d %lf %lf", &i, &x, &y);
p[i].x = x;
p[i].y = y;
n++;
}
fclose(fp);
}
/* function to test if data has been read correctly */
void print_coordinates(Point *p)
{
int i;
printf("Cities Coordinates:\n");
for (i = 1; i < CITY_NUM+1; i++)
printf("%d %f %f\n", i, p[i].x, p[i].y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -