I'm having a problem which was referred to before where I do not quite get the solution (combining substitute with simplify). In my encoding, I have strict inequalities and I would need to set the epsilon either to 0 or to a very small value. For instance, I have the following simplified Python code:
from z3 import *
p = Real('p')
q = Real('q')
s = Optimize()
s.add(p > 0, p < 1)
s.add(q > 0, q < 1)
h = s.maximize(p)
print s.check()
print s.upper(h)
print s.model()
How can I get p to be assigned the maximal value 1? (Right now it is assigned 1/2.) Thanks a lot!
Premise:
I assume that you simply want a model in which
papproaches 1 with a fixed precision.In this answer N.B. states (emphasis is mine)
Given that..
I could not find any option to set
epsilonneither in the Python API nor among smt2 optionsBy changing the size of the interval of
x, the value ofxin the returned model is at a different distance from the optimal value (e.g. interval0, 10givesx=9, whereas0, 1givesx=0.5)..my take of the previous quote is that z3 picks some random satisfiable value, and that's it.
Therefore:
I would do it in the following way:
Where
instantiate(str, eps)is a custom-made function that parses strings in the shape ofToReal(1) + ToReal(-1)*epsilonand returns the result of the obvious interpretation of such string.----
I'd like to mention that an alternative approach is to encode the problem as an smt2 formula and give it as input to OptiMathSAT:
OptiMathSAT has a command-line option
-optimization.theory.la.epsilon=Nto control the value ofepsilonwithin the returned model of the formula. By defaultN=6andepsilonis10^-6. Here is the output: