在pyomo中分析解决方案(.sol)文件 [英] Analysing solution (.sol) file in pyomo

查看:190
本文介绍了在pyomo中分析解决方案(.sol)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说pyomo在1号机器中有一个模型,而我在2号机器中有CPLEX求解器.我在1号机器中将pyomo模型(ConcreteModel)转换为功能为model.write("problem.lp")problem.lp文件.将此文件传输到计算机2并从CPLEX求解器获取solution.sol文件.但是解决方案文件中变量的名称与模型变量的名称不同.

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?

谢谢.

我认为归结为在编写模型时可以找到符号图.符号映射ID由model.write("problem.lp")返回(请参见此处).现在的问题是我有符号映射ID.如何获取符号映射文件并将其用于解码solution.sol文件中的变量?

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?

推荐答案

如Edit 1中所述,在将模型写入problem.lp时会返回符号映射. 如此代码的第27-29行所给出的,可以获得模型中变量名称的元组及其参考变量.

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.

然后,可以使用xml之类的包在python中解析CPLEX生成的XML文件(solution.sol).现在我们有了地图以及值.我们只需要比较参考变量并将其值存储到变量中,变量的名称与模型中的名称相同.

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.

这篇关于在pyomo中分析解决方案(.sol)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆