# include # include # include # include using namespace std; # include "tsp_display.hpp" int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // tsp_display_test() tests tsp_display(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 13 June 2026 // // Author: // // John Burkardt // { # define N 42 int i; int i2; int n = N; // // Make sure order indices are 0-based! // int order[N] = { 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; string prefix = "dantzig42"; double x[N*2] = { 170.0, 85.0, 166.0, 88.0, 133.0, 73.0, 140.0, 70.0, 142.0, 55.0, 126.0, 53.0, 125.0, 60.0, 119.0, 68.0, 117.0, 74.0, 99.0, 83.0, 73.0, 79.0, 72.0, 91.0, 37.0, 94.0, 6.0, 106.0, 3.0, 97.0, 21.0, 82.0, 33.0, 67.0, 4.0, 66.0, 3.0, 42.0, 27.0, 33.0, 52.0, 41.0, 57.0, 59.0, 58.0, 66.0, 88.0, 65.0, 99.0, 67.0, 95.0, 55.0, 89.0, 55.0, 83.0, 38.0, 85.0, 25.0, 104.0, 35.0, 112.0, 37.0, 112.0, 24.0, 113.0, 13.0, 125.0, 30.0, 135.0, 32.0, 147.0, 18.0, 147.5, 36.0, 154.5, 45.0, 157.0, 54.0, 158.0, 61.0, 172.0, 82.0, 174.0, 87.0 }; double *x2; timestamp ( ); cout << "\n"; cout << "tsp_display_test():\n"; cout << " C++ version.\n"; cout << " Display the cities and route solving a traveling\n"; cout << " salesman problem (TSP).\n"; cout << " Dataset is '" << prefix << "'\n"; // // Create the circuit data with transposition, reordering and wrap-around. // x2 = new double[(n+1)*2]; for ( i2 = 0; i2 < n + 1; i2++ ) { if ( i2 < n ) { i = order[i2]; } else { i = order[0]; } x2[2*i2] = x[2*i]; x2[2*i2+1] = x[2*i+1]; } // // Send the data to the plotter. // tsp_display ( prefix, n + 1, x2 ); delete [] x2; // // Terminate. // cout << "\n"; cout << "tsp_display_test():\n"; cout << " Normal end of execution.\n"; timestamp ( ); return ( 0 ); # undef N } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }