Commit 5137e03c authored by Chinmay Garde's avatar Chinmay Garde

Add support for updating edits

parent 8187c685
...@@ -82,20 +82,52 @@ class Solver { ...@@ -82,20 +82,52 @@ class Solver {
return _optimizeObjectiveRow(_objective); return _optimizeObjectiveRow(_objective);
} }
Result hasConstraint(Constraint c) { bool hasConstraint(Constraint constraint) {
return Result.unimplemented; return _constraints.containsKey(constraint);
} }
Result addEditVariable(Variable v, double priority) { Result addEditVariable(Variable variable, double priority) {
return Result.unimplemented; if (_edits.containsKey(variable)) {
return Result.duplicateEditVariable;
} }
Result removeEditVariable(Variable v) { if (!_isValidNonRequiredPriority(priority)) {
return Result.unimplemented; return Result.badRequiredStrength;
} }
Result hasEditVariable(Variable v) { Constraint constraint = new Constraint(
return Result.unimplemented; new Expression([new Term(variable, 1.0)], 0.0), Relation.equalTo);
if (addConstraint(constraint) != Result.success) {
return Result.internalSolverError;
}
EditInfo info = new EditInfo();
info.tag = _constraints[constraint];
info.constraint = constraint;
info.constant = 0.0;
_edits[variable] = info;
return Result.success;
}
Result removeEditVariable(Variable variable) {
EditInfo info = _edits[variable];
if (info == null) {
return Result.unknownEditVariable;
}
if (removeConstraint(info.constraint) != Result.success) {
return Result.internalSolverError;
}
_edits.remove(variable);
return Result.success;
}
bool hasEditVariable(Variable variable) {
return _edits.containsKey(variable);
} }
Result suggestVariable(Variable v, double value) { Result suggestVariable(Variable v, double value) {
...@@ -411,3 +443,7 @@ class EditInfo { ...@@ -411,3 +443,7 @@ class EditInfo {
Constraint constraint; Constraint constraint;
double constant; double constant;
} }
bool _isValidNonRequiredPriority(double priority) {
return (priority >= 0.0 && priority < Constraint.requiredPriority);
}
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