Forum Discussion

FICO's avatar
FICO
Community Manager
6 years ago

How to increase floating point precision in Python interface

Hello, I am working on some variables that take very small values (to the order of E-8). Default settings of Xpress Python interface seems to be assuming certain values (the cutoff appears to be numbers <1E-6) as zero. Is there a way to increase the floating point precision to overcome this issue?

10 Replies

  • FICO's avatar
    FICO
    Community Manager

    Hello,

    in Xpress, continuous variables can have any value, even below 1e-8. The floating point precision of all variables in the Optimizer is 64 bit (i.e. double precision). However, the tolerance on feasibility and/or integrality can be tightened so that, for example, variables lower and upper bounds are satisfied more precisely. The two controls feastol and mipsol determine by how much feasibility and integrality can be violated before a solution is deemed infeasible (or integer infeasible). These can be checked with

    p.controls.feastol

    p.controls.miptol

    In general though, I believe your problem is of a numerical nature and it would be much better, in my opinion, to reformulate the problem so that variables can take larger values.

    I hope this helps. Regards,

    Pietro

  • FICO's avatar
    FICO
    Community Manager

    Thanks! I was able to overcome this by scaling the problem so that I no longer dealt with very small number. However, I still think there's a parameter other than feastol and miptol that limits the values variables can attain. I see no reason why a variable takes 1.9234235E-6 with no lose in precision, while the other one, which I expect to take 1.12457645E-7, goes to zero.

  • FICO's avatar
    FICO
    Community Manager

    This might depend on the type of problem you're dealing with. Is this a MIP, an LP, or a nonlinear problem, and if a NLP, can you say more about the type of problem?

    Thanks

  • FICO's avatar
    FICO
    Community Manager

    By the way, if this is an LP or a MIP, with feastol at its default value of 1e-6, the variable you expect to be 1.12e-7 never gets into the basis and instead it is set to zero.

  • FICO's avatar
    FICO
    Community Manager

    Hi Pietro, thanks for your responses. The problem is indeed an NLP. Can you elaborate what do you mean by the type of the problem, if the following explanation is not enough? I have the following constraints involving these small variables "varx == smallvar1 + smallvar2*var1 + smallvar3*var1*var2 + ...", where smallvarn are the small variables I am referring to. In addition, I have the following constraints on these small variables: "smallvar1 == xp.Sum(coeff * bin_array for i in range(10))" where coeff are Python floats and each bin_array is binary variable.

    To clarify my previous point, I still get my variable equal to zero instead of 1.13E-7 with feastol=1E-10.

  • FICO's avatar
    FICO
    Community Manager

    Hi, the problem is indeed an NLP. In this case feastol and miptol have no influence. Similar to your other question on the forum, what is the xslp_nlpstatus for this problem? If the problem is the same as for the other thread, then given local infeasibility the solution itself is unreliable. In any case there is no threshold under which a small variable is set to zero. If the problem is different, feel free to send the model and I'll have a look.

  • FICO's avatar
    FICO
    Community Manager

    The problems in these 2 posts are indeed very similar. However, I am able to get a feasible solution for a simpler objective if I solve for the scaled up version of the problem. I continue having this rounding issue even with this simpler objective if I don't scale up the problem. I will send you my models shortly to better describe what's going on.

  • FICO's avatar
    FICO
    Community Manager

    Could you let me know how I can share my files privately? I am using some coefficients that I am not comfortable sharing publicly.

  • FICO's avatar
    FICO
    Community Manager

    About the previous message, solving with a different objective may indeed yield a different solution and a different optimization status (as you report, a feasible solution instead of nlp_locally_infeasible). Looking forward to the models.