#define _GNU_SOURCE #include #include #include #include #include #include // SEE THIS FILE FOR DECLARATIONS AND DOCUMENTATION OF SUGGESTED FUNCTIONS #include "tsp.h" #include "location.h" int main(int argc, char **argv) { // the index on the command line of the origin city // TO DO: this is hard-coded as if there is always one method // after the filename; fix that to account for more than one size_t origin = 3; // the number of cities on the command line size_t num_cities = argc - origin; // TO DO: maybe add some more error checking here // initialize names and indices of cities in the tour // TO DO: read coordinates from the file and make this work for any // cities on the command line (this assumes they are HVN ALB MHT BDL ORH PVD) city cities[] = { {"HVN", {41.26388889, -72.88694444}, 0}, {"ALB", {42.74916667, -73.80194444}, 1}, {"MHT", {42.93277778, -71.43583333}, 2}, {"BDL", {41.93916667, -72.68333333}, 3}, {"ORH", {42.26722222, -71.87555556}, 4}, {"PVD", {41.72388889, -71.42833333}, 5}, }; // iterate over methods requested on command line for (size_t a = 2; a < origin; a++) { if (strcmp(argv[a], "-insert") == 0) { route_insert(num_cities, cities); } else if (strcmp(argv[a], "-nearest") == 0) { route_nearest(num_cities, cities); } else if (strcmp(argv[a], "-given") == 0) { } normalize_start(num_cities, cities); normalize_direction(num_cities, cities); double total = calculate_total(num_cities, cities); printf("%-10s: %12.2f", argv[a], total); for (size_t i = 0; i < num_cities; i++) { printf(" %s", argv[origin + cities[i].index]); } printf(" %s\n", argv[origin + cities[0].index]); } // TO DO: there may be other opportunities for error checking! return 0; } void route_insert(size_t n, city tour[]) { } void find_closest_pair(size_t n, city tour[], size_t *best_orig, size_t *best_dest) { } size_t find_closest_to_tour(size_t n, city tour[], size_t tour_len) { return 0; } size_t find_insertion_point(size_t n, city tour[], size_t subtour_len, size_t next) { return 0; } void route_nearest(size_t n, city tour[]) { } size_t find_closest_city(city tour[], size_t c, size_t from, size_t to) { return 0; } double calculate_total(size_t n, city tour[]) { double tot = 0.0; return tot; } void swap(city arr[], size_t i, size_t j) { if (i != j) { city temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } void normalize_start(size_t n, city tour[]) { } void normalize_direction(size_t n, city tour[]) { } int read_file(FILE *in, size_t n, city cities[]) { return 0; }