使用 Solver、EXCEL 时保存目标函数值
我在 Excel 中设置了一个优化问题。当我优化(使用 GUI)时,我得到目标函数的最终(最佳)值。我可以看到 Excel 计算了很多点的目标函数值并确定了最佳点。有没有办法将所有目标函数值保存到 Excel 工作表中的某个范围。如果我可以使用求解器 GUI 来完成它,那就太好了。如果没有,基于 VBA 的解决方案也可以。
谢谢。
I have an optimization problem set up in Excel. When I optimize (using the gui), I get the final (optimum) value of the objective function. I can see that excel calculates the objective function values for a lot of points and settles on the optimum one. Is there a way to save all the objective function values to some range in the excel sheet. It would be great if I can do it using the solver GUI. If not, a VBA based solution would do too.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可以做到的,但手动操作很乏味。在 Excel/Solver 中时,在“求解器参数”对话框中选择“选项”。(在 Excel 中为数据->求解器->选项)选择显示迭代结果复选框。当您执行此操作时,Excel 的求解器将在每次迭代后暂停,并使用当前变量值更新单元格。
现在,当您通过单击“求解”运行模型时,Excel 将在每次中间迭代时暂停。求解器将每个中间步骤视为一个“场景”。您可以通过在每次迭代后弹出的场景对话框中为其命名来保存每个场景。 (在文本框中输入逻辑值,如 i1、i2、i3...)
求解器完成后,您可以访问“场景管理器”Excel->选项->场景 。
您将看到您保存的所有场景都列在那里。要将它们全部放入您想要的命名范围中,请按“摘要”按钮,然后在对话框中选择“方案数据透视表报告”。这将在一个漂亮的数据透视表中显示所有中间目标函数值供您分析。
需要记住的几个限制:
1.启用“显示迭代结果”选项会严重减慢解决方案的速度
2. 如果你的 LP 即使是中等规模,你也会有大量的迭代。手动记录场景实际上是不可行的。但是,您可以通过按 ESC 按钮“采样”几次迭代,存储场景并继续。
This is possible to do, but is manually tedious. When in Excel/Solver, select Options in the Solver Parameters Dialog. (Data->Solver->Options in Excel) Select the Show Iterations Results check box. When you do this, Excel's Solver will pause after each iteration, and update the cells with the current variable values.
Now, when you run the model by clicking "Solve," Excel will pause at each intermediate iteration. Solver considers each intermediate step to be a "Scenario." You can save each one by giving it a name in the Scenario dialog box that pops up after each iteration. (In the text box, enter something logical, like i1,i2, i3...)
Once the Solver is done, you can access the 'Scenario Manager" Excel->Options->Scenarios.
You will see all the scenarios that you saved listed there. To get them all into a named range like you desire, press the "Summary" button, and in the dialog box choose "Scenario Pivot Table Report." This will display all the intermediate Objective function values in a nice Pivot Table for you to analyze.
A couple of limitations to keep in mind:
1. Enabling the "Show Iteration Results" option severely slows down the solution
2. If your LP is even mid-sized, you will have a huge number of iterations. Manually recording the scenarios will not be realistically feasible. However, you can "sample" a few iterations by pressing the ESC button, storing the Scenario and continuing.