cplex_solution_read, an Octave code which extracts solution data from a cplex() result file.
This Octave code currently does not run, because it calls a function "xmlread()" which is available in MATLAB, but not Octave. The fileio() package may have the necessary function, but my version of Octave is too old to use it.
cplex() can be "fed" by an LP file created by polyomino_monohedral_matrix() or polyomino_multihedral_matrix(), and the results can be displayed by polyomino_monohedral_tiling_print() or polyomino_multihedral_tiling_print().
cplex() is a general integer programming package. We use CPLEX to solve a particular set of undetermined integer equations of the form A*x=b, for which the solution x is required to be binary, that is, to contain only 0 and 1 values.
cplex() can compute all possible solutions, and returns them packaged in a single XML file, which also contains other information, and substantial formatting text. It is desired to extract the NUM_VAR by NUM_SOL array of solution vectors X, for treatment by MATLAB.
A program called XML2STRUCT() is employed to convert XML to a MATLAB structure. Then the necessary solution data is carefully extracted and the array X is reconstructed and output.
Although it is not necesary to know this, the particular integer programming problem being solved is related to a polyomino tiling puzzle. cplex() is a powerful and accurate tool for solving the related system. To learn more about the problem being solved, you can refer to the simple MATLAB codes for attempting this solution: POLYOMINO_MONOHEDRAL and POLYOMINO_MULTIHEDRAL.
The information stored in the cplex() file has a number of peculiarities. For one thing, if there are N solutions, and N is more than 1, then, cplex() displays N+1 solutions, since it wishes to specifically display an "optimal" solution. Thus, when gathering solutions from a cplex() file, if the number of solutions is greater than 1, then the first solution should be dropped.
In listing a particular solution, depending on the user options, cplex() might only display the nonzero entries. Since most entries are zero, this keeps the output short; however, this also means that the cplex() file never actually lists the total number of variables. Thus, we prefer that the user specifically ask cplex() to story ALL variable values, including zeros. Otherwise, the returned solution information may be confusingly shortened because trailing zeros may be omitted.
Apparently, during the solution process, cplex() reindexes the variables. The output listing of the variables include the user's original index (or label, actually, such as "x20"), and the cplex() index. Thus, we have to ignore the cplex() index, read the string "x20", drop the "x" and convert the remainder from string to number.
The computer code and data files described and made available on this web page are distributed under the MIT license
cplex_solution_read is available in a MATLAB version and an Octave version.
gurobi_solution_read, an Octave code which reads a file created by the optimization package gurobi(), representing the solution of a polyomino tiling problem, and writes out a simple ASCII file that can be read by load().
polyominoes, an Octave code which defines, solves, and plots a variety of polyomino tiling problems, which are solved by a direct algebraic approach involving the reduced row echelon form (RREF) of a specific matrix, instead of the more typical brute-force or backtracking methods.
scip_solution_read, an Octave code which reads a file created by the integer programming package SCIP, representing the solution of a polyomino tiling problem, and writes out a simple ASCII file that can be read by load().
trinity_solution, an Octave code which prints or plots a solution to the trinity tiling puzzle, after it has been defined by trinity_lp_automatic() and solved by cplex().