Z3
src/api/java/Optimize.java
Go to the documentation of this file.
00001 
00020 package com.microsoft.z3;
00021 
00022 import com.microsoft.z3.enumerations.Z3_lbool;
00023 
00024 
00028 public class Optimize extends Z3Object
00029 {
00033     public String getHelp()
00034     {
00035         return Native.optimizeGetHelp(getContext().nCtx(), getNativeObject());
00036     }
00037 
00043     public void setParameters(Params value)
00044     {
00045         Native.optimizeSetParams(getContext().nCtx(), getNativeObject(), value.getNativeObject());
00046     }
00047 
00051     public ParamDescrs getParameterDescriptions()
00052     {
00053         return new ParamDescrs(getContext(), Native.optimizeGetParamDescrs(getContext().nCtx(), getNativeObject())); 
00054     }
00055 
00059     public void Assert(BoolExpr ... constraints)
00060     {
00061         getContext().checkContextMatch(constraints);
00062         for (BoolExpr a : constraints)
00063         {
00064             Native.optimizeAssert(getContext().nCtx(), getNativeObject(), a.getNativeObject());
00065         }
00066     }
00067 
00071     public void Add(BoolExpr ... constraints)
00072     {
00073         Assert(constraints);
00074     }
00075     
00079     public class Handle
00080     {
00081         Optimize opt;
00082         int handle;
00083         Handle(Optimize opt, int h)
00084         {
00085             this.opt = opt;
00086             this.handle = h;
00087         }
00088         
00092         public ArithExpr getLower()
00093         {
00094             return opt.GetLower(handle); 
00095         }
00096         
00100         public ArithExpr getUpper()
00101         {
00102             return opt.GetUpper(handle); 
00103         }
00104         
00108         public ArithExpr getValue()
00109         {
00110             return getLower(); 
00111         }
00112 
00116         public String toString() 
00117         {
00118             return getValue().toString();
00119         }
00120     }
00121 
00129     public Handle AssertSoft(BoolExpr constraint, int weight, String group)
00130     {
00131         getContext().checkContextMatch(constraint);
00132         Symbol s = getContext().mkSymbol(group);
00133         return new Handle(this, Native.optimizeAssertSoft(getContext().nCtx(), getNativeObject(), constraint.getNativeObject(), Integer.toString(weight), s.getNativeObject()));
00134     }
00135     
00136 
00143     public Status Check()
00144     {
00145         Z3_lbool r = Z3_lbool.fromInt(Native.optimizeCheck(getContext().nCtx(), getNativeObject()));
00146         switch (r) {
00147         case Z3_L_TRUE:
00148             return Status.SATISFIABLE;
00149         case Z3_L_FALSE:
00150             return Status.UNSATISFIABLE;
00151         default:
00152             return Status.UNKNOWN;
00153         }
00154     }
00155     
00159     public void Push()
00160     {
00161         Native.optimizePush(getContext().nCtx(), getNativeObject());
00162     }
00163 
00164 
00171     public void Pop()
00172     {
00173         Native.optimizePop(getContext().nCtx(), getNativeObject());
00174     }
00175 
00176 
00183     public Model getModel()
00184     {
00185         long x = Native.optimizeGetModel(getContext().nCtx(), getNativeObject());
00186         if (x == 0)
00187             return null;
00188         else
00189             return new Model(getContext(), x);
00190     }
00191 
00197     public Handle MkMaximize(ArithExpr e)
00198     {
00199         return new Handle(this, Native.optimizeMaximize(getContext().nCtx(), getNativeObject(), e.getNativeObject()));
00200     }
00201     
00206     public Handle MkMinimize(ArithExpr e)
00207     {
00208         return new Handle(this, Native.optimizeMinimize(getContext().nCtx(), getNativeObject(), e.getNativeObject()));
00209     }
00210     
00214     private ArithExpr GetLower(int index)
00215     {
00216         return (ArithExpr)Expr.create(getContext(), Native.optimizeGetLower(getContext().nCtx(), getNativeObject(), index));
00217     }
00218     
00219     
00223     private ArithExpr GetUpper(int index)
00224     {
00225         return (ArithExpr)Expr.create(getContext(), Native.optimizeGetUpper(getContext().nCtx(), getNativeObject(), index));
00226     }
00227 
00231     public String getReasonUnknown()
00232     {
00233         return Native.optimizeGetReasonUnknown(getContext().nCtx(),
00234                 getNativeObject());     
00235     }
00236     
00237     
00241     public String toString()
00242     {
00243         return Native.optimizeToString(getContext().nCtx(), getNativeObject());
00244     }
00245     
00249     public Statistics getStatistics()
00250     {
00251         return new Statistics(getContext(), Native.optimizeGetStatistics(getContext().nCtx(), getNativeObject()));
00252     }
00253 
00254 
00255     Optimize(Context ctx, long obj) throws Z3Exception
00256     {
00257         super(ctx, obj);
00258     }
00259 
00260     Optimize(Context ctx) throws Z3Exception
00261     {
00262         super(ctx, Native.mkOptimize(ctx.nCtx()));
00263     }
00264 
00265     
00266     void incRef(long o)
00267     {
00268         getContext().getOptimizeDRQ().incAndClear(getContext(), o);
00269         super.incRef(o);
00270     }
00271 
00272     void decRef(long o)
00273     {
00274         getContext().getOptimizeDRQ().add(o);
00275         super.decRef(o);
00276     }
00277 
00278 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines