chore: save current workspace progress
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user