Skip to content

Commit b0fef64

Browse files
Add assert_and_track support to Optimize class in .NET binding (#7437)
Related to #7436 #7436 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Z3Prover/z3/issues/7436?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 8b657f2 commit b0fef64

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/api/dotnet/Optimize.cs

+22
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ private void AddConstraints(IEnumerable<BoolExpr> constraints)
148148
Native.Z3_optimize_assert(Context.nCtx, NativeObject, a.NativeObject);
149149
}
150150
}
151+
152+
/// <summary>
153+
/// Assert a constraint into the optimize solver, and track it (in the unsat) core
154+
/// using the Boolean constant p.
155+
/// </summary>
156+
/// <remarks>
157+
/// This API is an alternative to <see cref="Check(Expr[])"/> with assumptions for extracting unsat cores.
158+
/// Both APIs can be used in the same solver. The unsat core will contain a combination
159+
/// of the Boolean variables provided using <see cref="AssertAndTrack(BoolExpr[],BoolExpr[])"/>
160+
/// and the Boolean literals
161+
/// provided using <see cref="Check(Expr[])"/> with assumptions.
162+
/// </remarks>
163+
public void AssertAndTrack(BoolExpr constraint, BoolExpr p)
164+
{
165+
Debug.Assert(constraint != null);
166+
Debug.Assert(p != null);
167+
Context.CheckContextMatch(constraint);
168+
Context.CheckContextMatch(p);
169+
170+
Native.Z3_optimize_assert_and_track(Context.nCtx, NativeObject, constraint.NativeObject, p.NativeObject);
171+
}
172+
151173
/// <summary>
152174
/// Handle to objectives returned by objective functions.
153175
/// </summary>

0 commit comments

Comments
 (0)