Z3
Solver.java
Go to the documentation of this file.
1 
18 package com.microsoft.z3;
19 
21 
25 public class Solver extends Z3Object
26 {
30  public String getHelp()
31  {
32  return Native.solverGetHelp(getContext().nCtx(), getNativeObject());
33  }
34 
40  public void setParameters(Params value)
41  {
42  getContext().checkContextMatch(value);
43  Native.solverSetParams(getContext().nCtx(), getNativeObject(),
44  value.getNativeObject());
45  }
46 
53  {
54  return new ParamDescrs(getContext(), Native.solverGetParamDescrs(
55  getContext().nCtx(), getNativeObject()));
56  }
57 
63  public int getNumScopes()
64  {
65  return Native
66  .solverGetNumScopes(getContext().nCtx(), getNativeObject());
67  }
68 
73  public void push()
74  {
75  Native.solverPush(getContext().nCtx(), getNativeObject());
76  }
77 
82  public void pop()
83  {
84  pop(1);
85  }
86 
94  public void pop(int n)
95  {
96  Native.solverPop(getContext().nCtx(), getNativeObject(), n);
97  }
98 
104  public void reset()
105  {
106  Native.solverReset(getContext().nCtx(), getNativeObject());
107  }
108 
114  public void add(BoolExpr... constraints)
115  {
116  getContext().checkContextMatch(constraints);
117  for (BoolExpr a : constraints)
118  {
119  Native.solverAssert(getContext().nCtx(), getNativeObject(),
120  a.getNativeObject());
121  }
122  }
123 
138  public void assertAndTrack(BoolExpr[] constraints, BoolExpr[] ps)
139  {
140  getContext().checkContextMatch(constraints);
141  getContext().checkContextMatch(ps);
142  if (constraints.length != ps.length)
143  throw new Z3Exception("Argument size mismatch");
144 
145  for (int i = 0; i < constraints.length; i++)
146  Native.solverAssertAndTrack(getContext().nCtx(), getNativeObject(),
147  constraints[i].getNativeObject(), ps[i].getNativeObject());
148  }
149 
163  public void assertAndTrack(BoolExpr constraint, BoolExpr p)
164  {
165  getContext().checkContextMatch(constraint);
166  getContext().checkContextMatch(p);
167 
168  Native.solverAssertAndTrack(getContext().nCtx(), getNativeObject(),
169  constraint.getNativeObject(), p.getNativeObject());
170  }
171 
177  public int getNumAssertions()
178  {
179  ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(getContext().nCtx(), getNativeObject()));
180  return assrts.size();
181  }
182 
189  {
190  ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(getContext().nCtx(), getNativeObject()));
191  return assrts.ToBoolExprArray();
192  }
193 
201  public Status check(Expr... assumptions)
202  {
203  Z3_lbool r;
204  if (assumptions == null)
205  r = Z3_lbool.fromInt(Native.solverCheck(getContext().nCtx(),
206  getNativeObject()));
207  else
209  .nCtx(), getNativeObject(), (int) assumptions.length, AST
210  .arrayToNative(assumptions)));
211  switch (r)
212  {
213  case Z3_L_TRUE:
214  return Status.SATISFIABLE;
215  case Z3_L_FALSE:
216  return Status.UNSATISFIABLE;
217  default:
218  return Status.UNKNOWN;
219  }
220  }
221 
229  public Status check()
230  {
231  return check((Expr[]) null);
232  }
233 
243  public Model getModel()
244  {
245  long x = Native.solverGetModel(getContext().nCtx(), getNativeObject());
246  if (x == 0)
247  return null;
248  else
249  return new Model(getContext(), x);
250  }
251 
261  public Expr getProof()
262  {
263  long x = Native.solverGetProof(getContext().nCtx(), getNativeObject());
264  if (x == 0)
265  return null;
266  else
267  return Expr.create(getContext(), x);
268  }
269 
280  {
281 
282  ASTVector core = new ASTVector(getContext(), Native.solverGetUnsatCore(getContext().nCtx(), getNativeObject()));
283  return core.ToBoolExprArray();
284  }
285 
290  public String getReasonUnknown()
291  {
292  return Native.solverGetReasonUnknown(getContext().nCtx(),
293  getNativeObject());
294  }
295 
302  {
303  return new Statistics(getContext(), Native.solverGetStatistics(
304  getContext().nCtx(), getNativeObject()));
305  }
306 
310  public String toString()
311  {
312  try
313  {
314  return Native
315  .solverToString(getContext().nCtx(), getNativeObject());
316  } catch (Z3Exception e)
317  {
318  return "Z3Exception: " + e.getMessage();
319  }
320  }
321 
322  Solver(Context ctx, long obj)
323  {
324  super(ctx, obj);
325  }
326 
327  void incRef(long o)
328  {
329  getContext().getSolverDRQ().incAndClear(getContext(), o);
330  super.incRef(o);
331  }
332 
333  void decRef(long o)
334  {
335  getContext().getSolverDRQ().add(o);
336  super.decRef(o);
337  }
338 }
ParamDescrs getParameterDescriptions()
Definition: Solver.java:52
static String solverGetReasonUnknown(long a0, long a1)
Definition: Native.java:4621
void assertAndTrack(BoolExpr[] constraints, BoolExpr[] ps)
Definition: Solver.java:138
static long solverGetParamDescrs(long a0, long a1)
Definition: Native.java:4485
static long solverGetStatistics(long a0, long a1)
Definition: Native.java:4630
static void solverReset(long a0, long a1)
Definition: Native.java:4534
void setParameters(Params value)
Definition: Solver.java:40
Status check(Expr...assumptions)
Definition: Solver.java:201
void assertAndTrack(BoolExpr constraint, BoolExpr p)
Definition: Solver.java:163
static long solverGetProof(long a0, long a1)
Definition: Native.java:4603
void add(BoolExpr...constraints)
Definition: Solver.java:114
BoolExpr[] ToBoolExprArray()
Definition: ASTVector.java:149
String getReasonUnknown()
Definition: Solver.java:290
static int solverGetNumScopes(long a0, long a1)
Definition: Native.java:4542
void incAndClear(Context ctx, long o)
static void solverPush(long a0, long a1)
Definition: Native.java:4518
static void solverAssert(long a0, long a1, long a2)
Definition: Native.java:4551
static String solverGetHelp(long a0, long a1)
Definition: Native.java:4476
static String solverToString(long a0, long a1)
Definition: Native.java:4639
static int solverCheckAssumptions(long a0, long a1, int a2, long[] a3)
Definition: Native.java:4585
static void solverSetParams(long a0, long a1, long a2)
Definition: Native.java:4494
static void solverAssertAndTrack(long a0, long a1, long a2, long a3)
Definition: Native.java:4559
BoolExpr[] getUnsatCore()
Definition: Solver.java:279
IDecRefQueue getSolverDRQ()
Definition: Context.java:3739
static long solverGetModel(long a0, long a1)
Definition: Native.java:4594
Statistics getStatistics()
Definition: Solver.java:301
static long solverGetAssertions(long a0, long a1)
Definition: Native.java:4567
static long solverGetUnsatCore(long a0, long a1)
Definition: Native.java:4612
static int solverCheck(long a0, long a1)
Definition: Native.java:4576
static void solverPop(long a0, long a1, int a2)
Definition: Native.java:4526
static final Z3_lbool fromInt(int v)
Definition: Z3_lbool.java:21
BoolExpr[] getAssertions()
Definition: Solver.java:188