Skip to content

Commit

Permalink
Fix handling of Z3 result in optimize due to nondeterministic output …
Browse files Browse the repository at this point in the history
…ordering (#226) (#227)
  • Loading branch information
Tim Deeb-Swihart authored and feliam committed May 5, 2017
1 parent d9baede commit aafc0e7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions manticore/core/smtlib/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,19 @@ def optimize(self, constraints, x, goal, M=10000):
try:
self._assert( operation(X, aux) )
self._send('(%s %s)' % (goal, aux.name) )
self._send('(check-sat)' )
if self._recv() == 'sat': #first line
self._send('(check-sat)')
_status = self._recv()
if _status not in ('sat', 'unsat', 'unknown'):
# Minimize (or Maximize) sometimes prints the objective before the status
# This will be a line like NAME |-> VALUE
maybe_sat = self._recv()
if maybe_sat == 'sat':
pattern = re.compile('(?P<expr>.*?)\s+\|->\s+(?P<value>.*)', re.DOTALL)
m = pattern.match(_status)
expr, value = m.group('expr'), m.group('value')
assert expr == aux.name
return int(value)
elif _status == 'sat':
ret = self._recv()
if not (ret.startswith('(') and ret.endswith(')')):
raise SolverException('bad output on max, z3 may have been killed')
Expand Down

0 comments on commit aafc0e7

Please sign in to comment.