# include # include # include # include # include using namespace std; # include "polyomino_lp_write.hpp" //****************************************************************************80 void polyomino_lp_write ( string filename, string label, int m, int n, int a[], int b[] ) //****************************************************************************80 // // Purpose: // // POLYOMINO_LP_WRITE writes an LP file for the polyomino problem. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 17 May 2018 // // Author: // // John Burkardt // // Parameters: // // Input, string FILENAME, the output filename. // // Input, string LABEL, the problem title. // // Input, int M, the number of equations // // Input, int N, the number of variables. // // Input, int A[M*N], the coefficients. // // Input, int B[M], the right hand sides. // { bool first; int i; int j; ofstream output; // // Open the file. // output.open ( filename.c_str ( ) ); if ( ! output ) { cerr << "\n"; cerr << "POLYOMINO_LP_WRITE - Error!\n"; cerr << " Could not open the output file.\n"; exit ( 1 ); } output << label << "\n"; output << "\n"; output << "Maximize\n"; output << " Obj: 0\n"; output << "Subject to\n"; for ( i = 0; i < m; i++ ) { first = true; for ( j = 0; j< n; j++ ) { if ( a[i+j*m] != 0 ) { if ( a[i+j*m] < 0 ) { output << " -"; } else if ( ! first ) { output << " +"; } if ( abs ( a[i+j*m] ) == 1 ) { output << " x" << j + 1; } else { output << " " << abs ( a[i+j*m] ) << " x" << j + 1; } first = false; } } output << " = " << b[i] << "\n"; } output << "Binary\n"; output << " "; for ( j = 0; j < n; j++ ) { output << " x" << j + 1; } output << "\n"; output << "End\n"; // // Close the file. // output.close ( ); return; } //****************************************************************************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 GNU LGPL license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // // Parameters: // // None // { # 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 }