function variomino_lp_write ( filename, label, A, b )

%*****************************************************************************80
%
%% variomino_lp_write() writes an LP file for the variomino problem.
%
%  Discussion:
%
%    A polyomino is a shape formed by connecting unit squares edgewise
%
%    A variomino is a polyomino in which each square has been assigned
%    a value between 1 and v.
%
%    A variomino can be represented by an MxN matrix, whose entries are
%    between 1 and vmax for squares that are part of the variomino, 
%    and 0 otherwise.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 April 2023
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string filename: the output filename.
%
%    string label: the problem title.
%
%    integer A(m,n): the coefficient matrix.
%
%    integer b(m): the right hand sides.
%
  [ m, n ] = size ( A );
%
%  Open the file.
%
  output = fopen ( filename, 'wt' );

  if ( output < 0 ) 
    fprintf ( 1, '\n' );
    fprintf ( 1, 'variomino_lp_write(): Error!\n' );
    fprintf ( 1, '  Could not open the output file "%s".\n', filename );
    error ( 'variomino_lp_write(): Error!' );
  end

  fprintf ( output, '%s\n', label );
  fprintf ( output, '\n' );

  fprintf ( output, 'Maximize\n' );
  fprintf ( output, '  Obj: 0\n' );

  fprintf ( output, 'Subject to\n' );
  line_length = 0;

  for i = 1 : m

    first = true;

    for j = 1 : n

      if ( A(i,j) ~= 0 )

        if ( A(i,j) < 0 )
          byte_num = fprintf ( output, ' -' );
          line_length = line_length + byte_num;
        elseif ( ~ first )
          byte_num = fprintf ( output, ' +' );
          line_length = line_length + byte_num;
        end

        if ( abs ( A(i,j) ) == 1 )
          byte_num = fprintf ( output, ' x%d', j );
          line_length = line_length + byte_num;
        else
          byte_num = fprintf ( output, ' %d x%d', abs ( A(i,j) ), j );
          line_length = line_length + byte_num;
        end

        if ( 70 <= line_length )
          fprintf ( output, '\n' );
          fprintf ( output, '  ' );
          line_length = 2;
        end

        first = false;

      end
    end
    numbytes = fprintf ( output, ' = %d\n', b(i) );
    line_length = 0;
  end

  fprintf ( output, 'Binary\n' );
  line_length = 0;

  byte_num = fprintf ( output, ' ' );
  line_length = line_length + byte_num;

  for j = 1 : n
    byte_num = fprintf ( output, ' x%d', j );
    line_length = line_length + byte_num;
    if ( 73 <= line_length && j < n )
      fprintf ( output, '\n' );
      fprintf ( output, '  ' );
      line_length = 2;
    end
  end
  fprintf ( output, '\n' );

  fprintf ( output, 'End\n' );
%
%  Close the file.
%
  fclose ( output );

  return
end
