convexengineering / gpkit

Geometric programming for engineers
http://gpkit.readthedocs.org
MIT License
206 stars 40 forks source link

Floating Point Errors? #1483

Closed adishavit closed 4 years ago

adishavit commented 4 years ago

I'm getting correct solutions that fail some of the constraints with very small errors (under 5 decimal points), but still failing some inequalities.
Is there anything I can do about this?

1ozturkbe commented 4 years ago

I am confused about what you are trying to say. You should understand that every inequality constraint is satisfied to a tolerance, which you can set in PosynomialInequality.feastol.

The more info we have about your specific case, the better we can help. Can you please post a minimum working example, or a model that demonstrates the issue, or at least your error message? Thanks.

adishavit commented 4 years ago

I apologize for being unclear.

I have bunch of variables and constrains including for example x <= 70 (among more constraints on x). The solution gives x:70.00009... Obviously over the threshold (though probably within the tolerance).

I did know about feastol. What is the effect of changing this?

I don’t mind inaccuracies within the tolerance but if the break the constraints it makes other things break.

I did notice that my inputs are floats and the result is float64.

Any suggestions?

bqpd commented 4 years ago

Is this with CVXOPT? Unfortunately the way various solvers deal with constraints means that some of their solutions violate them slightly. You can change solver settings by passing arguments to the solver, but the exact way to do that depends on the solver.

What is your application that requires such precision? We generally find that in design applications uncertainty in the input parameters vastly exceeds the solver's variance.

adishavit commented 4 years ago

My usage is MIP with whatever came with the default installation. I guess I’ll have to “snap” my results to any hard constraints.

bqpd commented 4 years ago

You could also create evaluated variables which round to integers!

For the default solver, cvxopt, options are here: https://cvxopt.org/userguide/coneprog.html#algorithm-parameters

You can try calling .solve with different feastol/reltol/abstol and see if that also suits your needs; but in general mathematical programs are not designed to return integers, and cvxopt especially does not snap to even the simplest boundaries.

adishavit commented 4 years ago

I mis-typed. I didn’t mean MIP, I’m doing mostly quadratic GP. Anyway, thanks for the clarification. I will add the tolerance to my thresholds.