问题
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