3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2014-03-24 03:11:53 -07:00
parent ff1543d700
commit b71580f11c
3 changed files with 18 additions and 5 deletions

View file

@ -79,7 +79,7 @@ extern "C" {
LOG_Z3_optimize_assert_soft(c, o, a, weight, id);
RESET_ERROR_CODE();
CHECK_FORMULA(a,0);
rational w("weight");
rational w(weight);
return to_optimize_ref(o).add_soft_constraint(to_expr(a), w, to_symbol(id));
Z3_CATCH_RETURN(0);
}

View file

@ -165,7 +165,7 @@ namespace Microsoft.Z3
}
}
x
#region Internal
internal Optimize(Context ctx, IntPtr obj)
: base(ctx, obj)

View file

@ -6321,9 +6321,22 @@ class Optimize(Z3PPObject):
"""Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
self.assert_exprs(*args)
def add_soft(self, arg, weight = None):
"""Add soft constraint with optional weight."""
pass
def add_soft(self, arg, weight = "1", id = None):
"""Add soft constraint with optional weight and optional identifier.
If no weight is supplied, then the penalty for violating the soft constraint
is 1.
Soft constraints are grouped by identifiers. Soft constraints that are
added without identifiers are grouped by default.
"""
if _is_int(weight):
weight = "%d" % weight
if not isinstance(weight, str):
raise Z3Exception("weight should be a string or an integer")
if id == None:
id = 0
id = to_symbol(id, self.ctx)
v = Z3_optimize_assert_soft(self.ctx.ref(), self.optimize, arg.as_ast(), weight, id)
return OptimizeObjective(v)
def maximize(self, arg):
"""Add objective function to maximize."""