Skip to content

Commit

Permalink
Add assert_and_track support to Optimize class in .NET binding (#7437)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
NikolajBjorner authored Oct 26, 2024
1 parent 8b657f2 commit b0fef64
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/api/dotnet/Optimize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ private void AddConstraints(IEnumerable<BoolExpr> constraints)
Native.Z3_optimize_assert(Context.nCtx, NativeObject, a.NativeObject);
}
}

/// <summary>
/// Assert a constraint into the optimize solver, and track it (in the unsat) core
/// using the Boolean constant p.
/// </summary>
/// <remarks>
/// This API is an alternative to <see cref="Check(Expr[])"/> with assumptions for extracting unsat cores.
/// Both APIs can be used in the same solver. The unsat core will contain a combination
/// of the Boolean variables provided using <see cref="AssertAndTrack(BoolExpr[],BoolExpr[])"/>
/// and the Boolean literals
/// provided using <see cref="Check(Expr[])"/> with assumptions.
/// </remarks>
public void AssertAndTrack(BoolExpr constraint, BoolExpr p)
{
Debug.Assert(constraint != null);
Debug.Assert(p != null);
Context.CheckContextMatch(constraint);
Context.CheckContextMatch(p);

Native.Z3_optimize_assert_and_track(Context.nCtx, NativeObject, constraint.NativeObject, p.NativeObject);
}

/// <summary>
/// Handle to objectives returned by objective functions.
/// </summary>
Expand Down

0 comments on commit b0fef64

Please sign in to comment.