addConstraint method
Attempts to add an individual Constraint to the solver.
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 constraint was successfully added.
- Result.duplicateConstraint: The constraint was already present in the solver.
- Result.unsatisfiableConstraint: The constraint was at Priority.required but could not be added because of a conflict with another constraint at that priority already in the solver. Try lowering the priority of the constraint and try again.
Implementation
Result addConstraint(Constraint constraint) {
if (_constraints.containsKey(constraint)) {
return Result.duplicateConstraint;
}
final tag = _Tag(
_Symbol(_SymbolType.invalid),
_Symbol(_SymbolType.invalid),
);
final row = _createRow(constraint, tag);
var subject = _chooseSubjectForRow(row, tag);
_constraints[constraint] = tag;
if (subject.type == _SymbolType.invalid && _allDummiesInRow(row)) {
if (!_nearZero(row.constant)) {
return Result.unsatisfiableConstraint;
} else {
subject = tag.marker;
}
}
if (subject.type == _SymbolType.invalid) {
if (!_addWithArtificialVariableOnRow(row)) {
return Result.unsatisfiableConstraint;
}
} else {
row.solveForSymbol(subject);
_substitute(subject, row);
_rows[subject] = row;
}
return _optimizeObjectiveRow(_objective);
}