Z3
src/api/java/Solver.java
Go to the documentation of this file.
00001 
00018 package com.microsoft.z3;
00019 
00020 import com.microsoft.z3.enumerations.Z3_lbool;
00021 
00025 public class Solver extends Z3Object
00026 {
00030     public String getHelp()
00031     {
00032         return Native.solverGetHelp(getContext().nCtx(), getNativeObject());
00033     }
00034 
00040     public void setParameters(Params value)
00041     {
00042         getContext().checkContextMatch(value);
00043         Native.solverSetParams(getContext().nCtx(), getNativeObject(),
00044                 value.getNativeObject());
00045     }
00046 
00052     public ParamDescrs getParameterDescriptions()
00053     {
00054         return new ParamDescrs(getContext(), Native.solverGetParamDescrs(
00055                 getContext().nCtx(), getNativeObject()));
00056     }
00057 
00063     public int getNumScopes()
00064     {
00065         return Native
00066                 .solverGetNumScopes(getContext().nCtx(), getNativeObject());
00067     }
00068 
00073     public void push()
00074     {
00075         Native.solverPush(getContext().nCtx(), getNativeObject());
00076     }
00077 
00082     public void pop()
00083     {
00084         pop(1);
00085     }
00086 
00094     public void pop(int n)
00095     {
00096         Native.solverPop(getContext().nCtx(), getNativeObject(), n);
00097     }
00098 
00104     public void reset()
00105     {
00106         Native.solverReset(getContext().nCtx(), getNativeObject());
00107     }
00108 
00114     public void add(BoolExpr... constraints)
00115     {
00116         getContext().checkContextMatch(constraints);
00117         for (BoolExpr a : constraints)
00118         {
00119             Native.solverAssert(getContext().nCtx(), getNativeObject(),
00120                     a.getNativeObject());
00121         }
00122     }
00123 
00138     public void assertAndTrack(BoolExpr[] constraints, BoolExpr[] ps)
00139     {
00140         getContext().checkContextMatch(constraints);
00141         getContext().checkContextMatch(ps);
00142         if (constraints.length != ps.length)
00143             throw new Z3Exception("Argument size mismatch");
00144 
00145         for (int i = 0; i < constraints.length; i++)
00146             Native.solverAssertAndTrack(getContext().nCtx(), getNativeObject(),
00147                     constraints[i].getNativeObject(), ps[i].getNativeObject());
00148     }
00149 
00163     public void assertAndTrack(BoolExpr constraint, BoolExpr p)
00164     {
00165         getContext().checkContextMatch(constraint);
00166         getContext().checkContextMatch(p);
00167 
00168         Native.solverAssertAndTrack(getContext().nCtx(), getNativeObject(),
00169                 constraint.getNativeObject(), p.getNativeObject());
00170     }
00171 
00177     public int getNumAssertions()
00178     {
00179         ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(getContext().nCtx(), getNativeObject()));
00180         return assrts.size();
00181     }
00182 
00188     public BoolExpr[] getAssertions()
00189     {
00190         ASTVector assrts = new ASTVector(getContext(), Native.solverGetAssertions(getContext().nCtx(), getNativeObject()));
00191         return assrts.ToBoolExprArray();
00192     }
00193 
00201     public Status check(Expr... assumptions)
00202     {
00203         Z3_lbool r;
00204         if (assumptions == null)
00205             r = Z3_lbool.fromInt(Native.solverCheck(getContext().nCtx(),
00206                     getNativeObject()));
00207         else
00208             r = Z3_lbool.fromInt(Native.solverCheckAssumptions(getContext()
00209                     .nCtx(), getNativeObject(), (int) assumptions.length, AST
00210                     .arrayToNative(assumptions)));
00211         switch (r)
00212         {
00213         case Z3_L_TRUE:
00214             return Status.SATISFIABLE;
00215         case Z3_L_FALSE:
00216             return Status.UNSATISFIABLE;
00217         default:
00218             return Status.UNKNOWN;
00219         }
00220     }
00221 
00229     public Status check()
00230     {
00231         return check((Expr[]) null);
00232     }
00233 
00243     public Model getModel()
00244     {
00245         long x = Native.solverGetModel(getContext().nCtx(), getNativeObject());
00246         if (x == 0)
00247             return null;
00248         else
00249             return new Model(getContext(), x);
00250     }
00251 
00261     public Expr getProof()
00262     {
00263         long x = Native.solverGetProof(getContext().nCtx(), getNativeObject());
00264         if (x == 0)
00265             return null;
00266         else
00267             return Expr.create(getContext(), x);
00268     }
00269 
00279     public BoolExpr[] getUnsatCore()
00280     {
00281 
00282         ASTVector core = new ASTVector(getContext(), Native.solverGetUnsatCore(getContext().nCtx(), getNativeObject()));        
00283         return core.ToBoolExprArray();
00284     }
00285 
00290     public String getReasonUnknown()
00291     {
00292         return Native.solverGetReasonUnknown(getContext().nCtx(),
00293                 getNativeObject());
00294     }
00295 
00301     public Statistics getStatistics()
00302     {
00303         return new Statistics(getContext(), Native.solverGetStatistics(
00304                 getContext().nCtx(), getNativeObject()));
00305     }
00306 
00310     public String toString()
00311     {
00312         try
00313         {
00314             return Native
00315                     .solverToString(getContext().nCtx(), getNativeObject());
00316         } catch (Z3Exception e)
00317         {
00318             return "Z3Exception: " + e.getMessage();
00319         }
00320     }
00321 
00322     Solver(Context ctx, long obj)
00323     {
00324         super(ctx, obj);
00325     }
00326 
00327     void incRef(long o)
00328     {
00329         getContext().getSolverDRQ().incAndClear(getContext(), o);
00330         super.incRef(o);
00331     }
00332 
00333     void decRef(long o)
00334     {
00335         getContext().getSolverDRQ().add(o);
00336         super.decRef(o);
00337     }
00338 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines