简体   繁体   English

计算精度c ++ Cplex

[英]Precision in computations c++ Cplex

I implemented my mathematical model using Ilog Cplex with c++. 我使用Ilog Cplex和c ++实现了数学模型。 Most of my decision variables have fractional values in the optimal solutions. 我的大多数决策变量在最优解中都具有分数。 Some of them are very small that cplex outputs them as 0. Is there a way to increase the precision so that I can still see the values of such variables? 其中一些很小,cplex将它们输出为0。是否有一种方法可以提高精度,以便我仍然可以看到这些变量的值?

Also, when I use cplex.getBestObjValue() , it gives me "-Inf". 另外,当我使用cplex.getBestObjValue() ,它给了我“ -Inf”。 (This is a maximization problem.) (这是一个最大化的问题。)

Having values for integer variables that are close to (but not exactly) integer values is quite normal. 具有接近(但不完全)整数值的整数变量值是很正常的。 CPLEX has an integrality tolerance so that these values are accepted as close enough to the correct integer values. CPLEX具有完整性容限,因此可以接受这些值,使其足够接近正确的整数值。 Just use standard C++ output functions to output these values to whatever precision you want. 只需使用标准C ++输出函数将这些值输出到所需的精度即可。

Mostly this is not a problem, but you can set the integrality tolerance to a smaller value if necessary. 通常这不是问题,但是可以根据需要将完整性公差设置为较小的值。 I normally round these values to the nearest integer value and use that as my solution. 我通常将这些值四舍五入为最接近的整数值并将其用作我的解决方案。 You can also try re-solving your model with those decision variables fixed to their rounded integer values to be sure the solution really is valid. 您也可以尝试将那些决策变量固定为四舍五入的整数值来重新求解模型,以确保解决方案确实有效。 If you are not sure that is sufficient, try Alex's suggestion for numerical precision emphasis too. 如果您不确定是否足够,请尝试Alex的建议,以强调数值精度。

you could try to use the setting IloCplex::Param::Emphasis::Numerical 您可以尝试使用设置IloCplex :: Param :: Emphasis :: Numerical

Emphasizes precision in numerically unstable or difficult problems. 强调数值不稳定或难题中的精度。 This parameter lets you specify to CPLEX that it should emphasize precision in numerically difficult or unstable problems, with consequent performance trade-offs in time and memory. 此参数使您可以向CPLEX指定应强调数值困难或不稳定问题的精度,从而在时间和内存上进行性能折衷。

About your second question, is your model a LP ? 关于第二个问题,您的模型是LP吗?

regards 问候

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

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