Analysing solution (.sol) file in pyomo

眉间皱痕 提交于 2020-01-21 10:35:28

问题


I have a model in pyomo in say machine 1 and I have the CPLEX solver in machine 2. I convert the pyomo model (ConcreteModel) into a problem.lp file with function model.write("problem.lp") in machine 1. Then I transfer this file to machine 2 and get the solution.sol file from the CPLEX solver. But names of the variables in the solution file is different from the names of the variables of the model.

This is causing a problem in analysis of the solution.

Is there any way to convert or map the names of the variables in solution file to that of the model?

Thanks.

Edit 1: I think it boils down to finding the symbol map when the model is written. The symbol map id is returned by model.write("problem.lp") (see here). Now the question is I have the symbol map id. How do I get the symbol map file and use it to decode the variables in solution.sol file?


回答1:


As given in the Edit 1 the symbol map is returned while writing the model to problem.lp. As given in line numbers 27-29 of this code, a tuple of variable names in the model and its reference variable can be obtained.

Then, the XML file which the CPLEX generates (solution.sol) can be parsed in python using package like xml. Now we have the map and also the values. We just need to compare the reference variables and store its value into the variable with the name as that in the model.



来源:https://stackoverflow.com/questions/52183842/analysing-solution-sol-file-in-pyomo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!