# include # include # include # include # include # include using namespace std; # include "tsp_display.hpp" //****************************************************************************80 void tsp_display ( string prefix, int n, double *x2 ) //****************************************************************************80 // // Purpose: // // tsp_display() plots cities and a tour connecting them. // // Discussion: // // If a "round trip" is desired, then the x2 array must repeat the // first city at the end. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 13 June 2026 // // Author: // // John Burkardt // // Input: // // string prefix: a string that defines the name of // the problem. It is also used to create file names needed for // input to gnuplot. // // int n: the number of cities. // // double x[n*2]: the x and y coordinates of the cities. // { string command_filename; ofstream command; ofstream data; string data_filename; int i; // // Create the data file. // data_filename = prefix + "_data.txt"; data.open ( data_filename.c_str ( ) ); for ( i = 0; i < n; i++ ) { data << x2[2*i] << " " << x2[2*i+1] << "\n"; } data.close ( ); cout << " Created data file '" << data_filename << "'\n"; // // Create the command file. // command_filename = prefix + "_commands.txt"; command.open ( command_filename.c_str ( ) ); command << "# " << command_filename << "\n"; command << "#\n"; command << "# Usage:\n"; command << "# gnuplot < " << command_filename << "\n"; command << "#\n"; command << "set term png\n"; command << "set output '" << prefix << ".png'\n"; command << "set xlabel '<--- X --->'\n"; command << "set ylabel '<--- Y --->'\n"; command << "set title '" << prefix << "'\n"; command << "set grid\n"; command << "unset key\n"; command << "set style data lines\n"; command << "plot '" << data_filename << "' using 1:2 lw 3 linecolor rgb 'blue', \\\n"; command << " '" << data_filename << "' using 1:2 with points pointtype 7 pointsize 3 linecolor rgb 'green'\n"; command << "quit\n"; command.close ( ); cout << " Created command file '" << command_filename << "'\n"; return; }