public void AddFunctionConstraint(FunctionConstraint constraint) { if (constraint is VariableConstraint) { // Not really a function constraint (i.e. general non-linear constraint). Let the base class take care of it. AddVariableConstraint((VariableConstraint)constraint); return; } Function function = constraint.Function; if (function is Variable) { // Same as above. AddVariableConstraint(new VariableConstraint((Variable)function, constraint.MinValue, constraint.MaxValue)); return; } FunctionConstraint constraint0 = FunctionConstraints.Find(delegate(FunctionConstraint c) { return c.Function == function; }); if (constraint0 != null) { // Modify an existing constraint (i.e. regarding the same variable). double minValue = Math.Max(constraint0.MinValue, constraint.MinValue); double maxValue = Math.Min(constraint0.MaxValue, constraint.MaxValue); if (minValue <= maxValue) { // Remove the existing constraint and add a new with a smaller interval. FunctionConstraints.Remove(constraint0); FunctionConstraints.Add(new FunctionConstraint(function, minValue, maxValue)); } else { // The two intervals are disjoint. throw new InconsistentConstraintException("Inconsistency found in constraints.", constraint); } } else { FunctionConstraints.Add(constraint); } }
public InconsistentConstraintException(string message, FunctionConstraint constraint) : base(message, constraint) { }
public ConstraintViolationException(string message, FunctionConstraint constraint) : base(message) { Constraint = constraint; }