City Distance Tools

**CITIES**
is a MATLAB library which
works with problems involving intercity distances.

Such problems include:

- traveling salesman problems (connected path through every city);
- K-means calculations (find M spots that minimize total of the distance from each city to its nearest spot);
- K-medians calculations (make M of the cities "special", to minimize the total distance from each city to its nearest special city);
- Weighted K-means or K-medians (let the population of each city be used as a weight, which makes some cities more important);
- Minimal spanning trees (construct the shortest highway system that connects all the cities, using only straight paths from one city to another (ignore the possibility that two roads could cross, or that a Y-shaped connector between three cities might be cheaper);
- Voronoi diagrams (assign each spot of land to the nearest city, making "provinces");

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

**CITIES** is available in
a C++ version and
a FORTRAN90 version and
a MATLAB version.

ASA058, a MATLAB library which contains the original text of the Sparks clustering algorithm.

ASA136, a MATLAB library which implements the K-Means algorithm.

CITIES, a dataset directory which contains a number of city distance datasets.

DISTANCE_TO_POSITION, a MATLAB program which estimates the positions of cities based on a city-to-city distance table.

DISTANCE_TO_POSITION_SPHERE, a MATLAB program which estimates the positions of cities on a sphere (such as the earth) based on a city-to-city distance table.

FLOYD, a MATLAB library which implements Floyd's algorithm for finding the shortest distance between pairs of nodes on a directed graph.

TSP, a dataset directory which contains test data for the traveling salesperson problem;

- ch_cap.m returns the capitalized version of a character;
- degrees_to_radians.m, converts degrees to radians.
- dist_table_check.m, checks a distance table.
- dist_table_check_test.m
- dms_print.m, prints the latitude and longitude in degrees/minutes/seconds.
- dms_to_distance_earth.m, finds the distance between two points on the earth.
- dms_to_radians.m, converts degrees, minutes, seconds to radians.
- dms_to_xy.m, converts Latitude/Longitude in DMS to XY coordinates.
- file_column_count.m, counts the number of columns in the first line of a file.
- file_exist.m, reports whether a file exists.
- file_row_count.m, counts the number of row records in a file.
- i4_sign.m, returns the sign of an I4.
- i4_to_a.m, returns the I-th alphabetic character;
- lat_char.m, returns a character for negative or positive latitude.
- ll_degrees_to_distance.m, creates a distance table from latitudes and longitudes.
- ll_degrees_to_distance_earth.m, distance between two points on the earth.
- ll_degrees_to_xy.m, convert Latitude/Longitude in degrees to XY coordinates on an unrolled cylinder.
- ll_degrees_to_xyz.m, convert Latitude/Longitude in degrees to XYZ coordinates on a sphere.
- ll_rad_dist_sphere.m, computes the great circle distance between two points on a sphere of given radius, where the positions are given as latitude and longitude in radians.
- lon_char.m, returns a character for negative or positive longitude.
- main_read_size.m, reads the problem size N from the main file.
- point_to_dist_table.m, returns a distance table given a set of point coordinates.
- r8mat_data_read.m, reads a table from an R8MAT file.
- r8mat_header_read.m, reads a table header from an R8MAT file.
- r8mat_print.m, prints an R8MAT.
- r8mat_print_some.m, prints some of an R8MAT.
- r8mat_transpose_print.m, prints the transpose of an R8MAT.
- r8mat_transpose_print_some.m, prints the transpose of some of an R8MAT.
- r8mat_write.m, writes an R8MAT file.
- r8vec_print.m, prints an R8VEC;
- s_eqi.m, is TRUE if two strings are equal, ignoring case and trailing blanks;
- s_len_trim.m returns the length of a string to the last nonblank;
- s_word_count.m, counts the number of words in a string.
- timestamp.m, prints the current YMDHMS date as a timestamp.

- cities_test.m, calls all the tests.
- cities_test01.m, tests XY_TO_DIST.
- cities_test02.m, tests MAIN_READ_SIZE, DMS_READ, DMS_TO_DIST.
- spaeth2_09_dist.txt, a distance table.
- usca312_main.txt, is the main file for 312 city locations in the US and Canada.
- usca312_dms.txt, the latitude and longitude of each city.
- uscap_ll.txt, the latitude and longitude of each capital.
- uscap_xy.txt, the (X,Y) coordinates of each capital using a cylindrical projection.
- wg22_dist.txt, a distance table.
- wg22_xy.txt, the (X,Y) coordinates of each city.
- cities_test_output.txt, the output file.

You can go up one level to the MATLAB source codes.