简体   繁体   English

Excel解算器和VBA:约束中的浮点数/十进制数被错误地转换为整数?

[英]Excel Solver and VBA: Floating point/decimal numbers in constraints get incorrectly converted to integers?

I'm running VBA scripts under both Excel 2007 and 2010 which involve a lot of optimization using the built-in Solver of Excel. 我在Excel 2007和2010下运行VBA脚本,其中涉及使用内置的Excel解算器进行大量优化。

What is the correct way to specify decimal constraints like X>=0.0001 where X would be the decision variable of the problem. 指定小数约束的正确方法是什么,例如X> = 0.0001,其中X将是问题的决策变量。

SolverAdd CellRef:=cells(5,5), Relation:=3, FormulaText:="0.0001"

Or do I have to remove the quotes " " ? 或者我是否必须删除引号“”? And does the VBA interface of Solver allow for decimal (non-integer) constraints anyway? 并且Solver的VBA接口是否允许十进制(非整数)约束?

I'm asking, because sometimes I get the (unconfirmed) feeling that a constraint of >=0.0001 is incorrectly interpreted as >=1, which of course renders wrong results. 我问,因为有时我得到(未经证实)的感觉,> = 0.0001的约束被错误地解释为> = 1,这当然会导致错误的结果。

It would be great if somebody could clarify these issues for me. 如果有人能为我澄清这些问题,那就太好了。

Steve 史蒂夫

We've found that FormulaText can really effect the final solution. 我们发现FormulaText可以真正影响最终的解决方案。 We've always just used straight numbers there, no quotes: 我们总是在那里使用直号,没有引号:

SolverAdd CellRef:=cells(5,5), Relation:=3, FormulaText:=0.0001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM