mirror of
https://github.com/Z3Prover/z3
synced 2025-04-14 21:08:46 +00:00
Merge pull request #921 from cheshire/obj_value_as_vector_java
Obj value as vector java
This commit is contained in:
commit
f8a3a46d44
|
@ -14,7 +14,6 @@ Author:
|
||||||
Nikolaj Bjorner (nbjorner) 2015-07-16
|
Nikolaj Bjorner (nbjorner) 2015-07-16
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
package com.microsoft.z3;
|
package com.microsoft.z3;
|
||||||
|
@ -23,10 +22,10 @@ import com.microsoft.z3.enumerations.Z3_lbool;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object for managing optimizization context
|
* Object for managing optimization context
|
||||||
**/
|
**/
|
||||||
public class Optimize extends Z3Object
|
public class Optimize extends Z3Object {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* A string that describes all available optimize solver parameters.
|
* A string that describes all available optimize solver parameters.
|
||||||
**/
|
**/
|
||||||
|
@ -70,51 +69,75 @@ public class Optimize extends Z3Object
|
||||||
**/
|
**/
|
||||||
public void Add(BoolExpr ... constraints)
|
public void Add(BoolExpr ... constraints)
|
||||||
{
|
{
|
||||||
Assert(constraints);
|
Assert(constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle to objectives returned by objective functions.
|
* Handle to objectives returned by objective functions.
|
||||||
**/
|
**/
|
||||||
public class Handle
|
public static class Handle {
|
||||||
{
|
|
||||||
Optimize opt;
|
|
||||||
int handle;
|
|
||||||
Handle(Optimize opt, int h)
|
|
||||||
{
|
|
||||||
this.opt = opt;
|
|
||||||
this.handle = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private final Optimize opt;
|
||||||
* Retrieve a lower bound for the objective handle.
|
private final int handle;
|
||||||
**/
|
|
||||||
public ArithExpr getLower()
|
|
||||||
{
|
|
||||||
return opt.GetLower(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Handle(Optimize opt, int h)
|
||||||
* Retrieve an upper bound for the objective handle.
|
{
|
||||||
**/
|
this.opt = opt;
|
||||||
public ArithExpr getUpper()
|
this.handle = h;
|
||||||
{
|
}
|
||||||
return opt.GetUpper(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the value of an objective.
|
* Retrieve a lower bound for the objective handle.
|
||||||
**/
|
**/
|
||||||
public ArithExpr getValue()
|
public ArithExpr getLower()
|
||||||
{
|
{
|
||||||
return getLower();
|
return opt.GetLower(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a string representation of the handle.
|
* Retrieve an upper bound for the objective handle.
|
||||||
**/
|
**/
|
||||||
@Override
|
public ArithExpr getUpper()
|
||||||
public String toString()
|
{
|
||||||
|
return opt.GetUpper(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a triple representing the upper bound of the objective handle.
|
||||||
|
*
|
||||||
|
* The triple contains values {@code inf, value, eps},
|
||||||
|
* where the objective value is unbounded iff {@code inf} is non-zero,
|
||||||
|
* and otherwise is represented by the expression {@code value + eps * EPSILON},
|
||||||
|
* where {@code EPSILON} is an arbitrarily small real number.
|
||||||
|
*/
|
||||||
|
public ArithExpr[] getUpperAsVector()
|
||||||
|
{
|
||||||
|
return opt.GetUpperAsVector(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a triple representing the upper bound of the objective handle.
|
||||||
|
*
|
||||||
|
* <p>See {@link #getUpperAsVector()} for triple semantics.
|
||||||
|
*/
|
||||||
|
public ArithExpr[] getLowerAsVector()
|
||||||
|
{
|
||||||
|
return opt.GetLowerAsVector(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the value of an objective.
|
||||||
|
**/
|
||||||
|
public ArithExpr getValue()
|
||||||
|
{
|
||||||
|
return getLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a string representation of the handle.
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
{
|
{
|
||||||
return getValue().toString();
|
return getValue().toString();
|
||||||
}
|
}
|
||||||
|
@ -126,7 +149,6 @@ public class Optimize extends Z3Object
|
||||||
* Return an objective which associates with the group of constraints.
|
* Return an objective which associates with the group of constraints.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public Handle AssertSoft(BoolExpr constraint, int weight, String group)
|
public Handle AssertSoft(BoolExpr constraint, int weight, String group)
|
||||||
{
|
{
|
||||||
getContext().checkContextMatch(constraint);
|
getContext().checkContextMatch(constraint);
|
||||||
|
@ -134,13 +156,11 @@ public class Optimize extends Z3Object
|
||||||
return new Handle(this, Native.optimizeAssertSoft(getContext().nCtx(), getNativeObject(), constraint.getNativeObject(), Integer.toString(weight), s.getNativeObject()));
|
return new Handle(this, Native.optimizeAssertSoft(getContext().nCtx(), getNativeObject(), constraint.getNativeObject(), Integer.toString(weight), s.getNativeObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check satisfiability of asserted constraints.
|
* Check satisfiability of asserted constraints.
|
||||||
* Produce a model that (when the objectives are bounded and
|
* Produce a model that (when the objectives are bounded and
|
||||||
* don't use strict inequalities) meets the objectives.
|
* don't use strict inequalities) meets the objectives.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public Status Check()
|
public Status Check()
|
||||||
{
|
{
|
||||||
Z3_lbool r = Z3_lbool.fromInt(Native.optimizeCheck(getContext().nCtx(), getNativeObject()));
|
Z3_lbool r = Z3_lbool.fromInt(Native.optimizeCheck(getContext().nCtx(), getNativeObject()));
|
||||||
|
@ -162,13 +182,11 @@ public class Optimize extends Z3Object
|
||||||
Native.optimizePush(getContext().nCtx(), getNativeObject());
|
Native.optimizePush(getContext().nCtx(), getNativeObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backtrack one backtracking point.
|
* Backtrack one backtracking point.
|
||||||
*
|
*
|
||||||
* Note that an exception is thrown if Pop is called without a corresponding Push.
|
* Note that an exception is thrown if Pop is called without a corresponding Push.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public void Pop()
|
public void Pop()
|
||||||
{
|
{
|
||||||
Native.optimizePop(getContext().nCtx(), getNativeObject());
|
Native.optimizePop(getContext().nCtx(), getNativeObject());
|
||||||
|
@ -218,7 +236,6 @@ public class Optimize extends Z3Object
|
||||||
return (ArithExpr)Expr.create(getContext(), Native.optimizeGetLower(getContext().nCtx(), getNativeObject(), index));
|
return (ArithExpr)Expr.create(getContext(), Native.optimizeGetLower(getContext().nCtx(), getNativeObject(), index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an upper bound for the objective handle.
|
* Retrieve an upper bound for the objective handle.
|
||||||
**/
|
**/
|
||||||
|
@ -227,6 +244,42 @@ public class Optimize extends Z3Object
|
||||||
return (ArithExpr)Expr.create(getContext(), Native.optimizeGetUpper(getContext().nCtx(), getNativeObject(), index));
|
return (ArithExpr)Expr.create(getContext(), Native.optimizeGetUpper(getContext().nCtx(), getNativeObject(), index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Triple representing the upper bound for the objective handle.
|
||||||
|
*
|
||||||
|
* <p>See {@link Handle#getUpperAsVector}.
|
||||||
|
*/
|
||||||
|
private ArithExpr[] GetUpperAsVector(int index) {
|
||||||
|
return unpackObjectiveValueVector(
|
||||||
|
Native.optimizeGetUpperAsVector(
|
||||||
|
getContext().nCtx(), getNativeObject(), index
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Triple representing the upper bound for the objective handle.
|
||||||
|
*
|
||||||
|
* <p>See {@link Handle#getLowerAsVector}.
|
||||||
|
*/
|
||||||
|
private ArithExpr[] GetLowerAsVector(int index) {
|
||||||
|
return unpackObjectiveValueVector(
|
||||||
|
Native.optimizeGetLowerAsVector(
|
||||||
|
getContext().nCtx(), getNativeObject(), index
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArithExpr[] unpackObjectiveValueVector(long nativeVec) {
|
||||||
|
ASTVector vec = new ASTVector(
|
||||||
|
getContext(), nativeVec
|
||||||
|
);
|
||||||
|
return new ArithExpr[] {
|
||||||
|
(ArithExpr) vec.get(0), (ArithExpr) vec.get(1), (ArithExpr) vec.get(2)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string the describes why the last to check returned unknown
|
* Return a string the describes why the last to check returned unknown
|
||||||
**/
|
**/
|
||||||
|
@ -236,7 +289,6 @@ public class Optimize extends Z3Object
|
||||||
getNativeObject());
|
getNativeObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the context to a String (SMT-LIB parseable benchmark).
|
* Print the context to a String (SMT-LIB parseable benchmark).
|
||||||
**/
|
**/
|
||||||
|
|
Loading…
Reference in a new issue