Commit 99dc91eb authored by Chinmay Garde's avatar Chinmay Garde

Add bulk remove options

parent e9335659
......@@ -59,6 +59,13 @@ class Solver {
return _optimizeObjectiveRow(_objective);
}
Result removeConstraints(List<Constraint> constraints) {
_SolverBulkUpdate applier = (Constraint c) => removeConstraint(c);
_SolverBulkUpdate undoer = (Constraint c) => addConstraint(c);
return _bulkEdit(constraints, applier, undoer);
}
Result removeConstraint(Constraint constraint) {
_Tag tag = _constraints[constraint];
if (tag == null) {
......@@ -129,6 +136,14 @@ class Solver {
return Result.success;
}
Result removeEditVariables(List<Variable> variables) {
_SolverBulkUpdate applier = (Variable v) => removeEditVariable(v);
_SolverBulkUpdate undoer = (Variable v) =>
addEditVariable(v, _edits[v].constraint.priority);
return _bulkEdit(variables, applier, undoer);
}
Result removeEditVariable(Variable variable) {
_EditInfo info = _edits[variable];
if (info == null) {
......
......@@ -603,4 +603,25 @@ void main() {
expect(s.addEditVariables(
[left.variable, right.variable, mid.variable], 999.0), Result.success);
});
test('bulk_remove_constraints_and_variables', () {
Solver s = new Solver();
var left = new Param(0.0);
var right = new Param(100.0);
var mid = new Param(0.0);
expect(s.addEditVariables(
[left.variable, right.variable, mid.variable], 999.0), Result.success);
var c1 = left <= mid;
var c2 = mid <= right;
expect(s.addConstraints([c1, c2]), Result.success);
expect(s.removeConstraints([c1, c2]), Result.success);
expect(s.removeEditVariables(
[left.variable, right.variable, mid.variable]), Result.success);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment