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

Add support for updating edits

parent 8187c685
......@@ -82,20 +82,52 @@ class Solver {
return _optimizeObjectiveRow(_objective);
}
Result hasConstraint(Constraint c) {
return Result.unimplemented;
bool hasConstraint(Constraint constraint) {
return _constraints.containsKey(constraint);
}
Result addEditVariable(Variable v, double priority) {
return Result.unimplemented;
Result addEditVariable(Variable variable, double priority) {
if (_edits.containsKey(variable)) {
return Result.duplicateEditVariable;
}
Result removeEditVariable(Variable v) {
return Result.unimplemented;
if (!_isValidNonRequiredPriority(priority)) {
return Result.badRequiredStrength;
}
Result hasEditVariable(Variable v) {
return Result.unimplemented;
Constraint constraint = new Constraint(
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) {
......@@ -411,3 +443,7 @@ class EditInfo {
Constraint constraint;
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