chore: save current workspace progress

This commit is contained in:
梁薄云
2026-08-09 22:13:18 +08:00
parent 650c2ab0e3
commit 2f4fd15e52
449 changed files with 76593 additions and 971 deletions
@@ -60,3 +60,29 @@ internal sealed class FakeQpSolver : IQpSolver
return _results.Dequeue();
}
}
internal sealed class CancellingQpSolver : IQpSolver
{
private readonly IQpSolver inner;
private readonly CancellationTokenSource cancellation;
private readonly int cancelAfterSolveCount;
private int solveCount;
public CancellingQpSolver(IQpSolver inner, CancellationTokenSource cancellation, int cancelAfterSolveCount = 1)
{
this.inner = inner ?? throw new ArgumentNullException(nameof(inner));
this.cancellation = cancellation ?? throw new ArgumentNullException(nameof(cancellation));
if (cancelAfterSolveCount <= 0) throw new ArgumentOutOfRangeException(nameof(cancelAfterSolveCount));
this.cancelAfterSolveCount = cancelAfterSolveCount;
}
public QpSolveResult Solve(QuadraticProgram problem, QpSolverSettings settings, IReadOnlyList<double> warmStart,
CancellationToken cancellationToken)
{
QpSolveResult result = inner.Solve(problem, settings, warmStart, cancellationToken);
solveCount++;
if (solveCount == cancelAfterSolveCount)
cancellation.Cancel();
return result;
}
}