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.
Source
Result addConstraint(Constraint constraint) { if (_constraints.containsKey(constraint)) return Result.duplicateConstraint; _Tag tag = new _Tag(new _Symbol(_SymbolType.invalid), new _Symbol(_SymbolType.invalid)); _Row row = _createRow(constraint, tag); _Symbol subject = _chooseSubjectForRow(row, 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; } _constraints[constraint] = tag; return _optimizeObjectiveRow(_objective); }