OSeMOSYS / otoole

OSeMOSYS Tools for Energy
https://otoole.readthedocs.io
MIT License
23 stars 17 forks source link

Programmatically process GLPK solution file #19

Closed willu47 closed 1 year ago

willu47 commented 5 years ago

To programmatically process the results from OSeMOSYS using GLPK (as an alternative to manually writing out tabular files my modifying the model files), I would prefer to use the solution file generated by GLPK as we are doing with the CBC and CPLEX solvers. Apparently, using the --wglp option to write a model file in GLPK format and the solution with the --write (instead of --output) generates a machine readable text file which can be more easily processed, and the variable names can be extracted from the glpk model file as the identifiers match.

From https://en.wikibooks.org/wiki/GLPK/Interoperability :

"To access the solution found by GLPSOL from a computer program, one could write the model with the --wglp option and the solution with the --write option. The ordering of rows and columns is the same in both files. It is enough to obtain all necessary information. (The only improvements I would like to make here is to use a DIMACS-like format for solution files.)" Source: help-glpk, 19 Jan 2011, grammar corrected, emphasis added.

The following command can be used to generate the solution and model file which can be parsed programmatically:

glpsol --wglp model.lp -m src/osemosys.txt -d tests/utopia.txt --write results.sol
willu47 commented 5 years ago

Names in the model file

In the model file, the names of the problem, objective function, variables and constraints are listed in the lines beginning with n where:

n p NAME # p = problem instance
n z NAME # z = objective function
n i ROW NAME # i = constraint name, ROW is the row ordinal number
n j COL NAME # j = variable name, COL is the column ordinal number

Rows in the solution file

In the solution file, the rows take on the following format:

i ROW ST PRIM DUAL

where:

Columns in the solution file

Columns take on the following format:

j COL ST PRIM DUAL

where: