addEditVariable method
Attempt to add a single edit Variable to the Solver at the given
priority. No edit variables may be added to the Solver at
Priority.required
.
Check the Result returned to make sure the operation succeeded. Any
errors will be reported via the message
property on the Result.
Possible Results:
- Result.success: The edit variable was successfully added to Solver at the specified priority.
- Result.duplicateEditVariable: The edit variable was already present in the Solver.
- Result.badRequiredStrength: The edit variable was added at Priority.required. Edit variables are used to suggest values to the solver. Since suggestions can't be mandatory, priorities cannot be Priority.required. If variable values need to be fixed at Priority.required, add that preference as a constraint. This allows the solver to check for satisfiability of the constraint (w.r.t other constraints at Priority.required) and check for duplicates.
Implementation
Result addEditVariable(Variable variable, double priority) {
if (_edits.containsKey(variable)) {
return Result.duplicateEditVariable;
}
if (!_isValidNonRequiredPriority(priority)) {
return Result.badRequiredStrength;
}
final constraint = Constraint(
Expression(<Term>[Term(variable, 1)], 0),
Relation.equalTo,
)..priority = priority;
// ignore: unused_local_variable
final result = addConstraint(constraint);
assert(result == Result.success);
final info = _EditInfo()
..tag = _constraints[constraint]!
..constraint = constraint
..constant = 0.0;
_edits[variable] = info;
return Result.success;
}