25#ifndef quantlib_optimization_constraint_h
26#define quantlib_optimization_constraint_h
46 std::numeric_limits < Array::value_type > ::max());
51 -std::numeric_limits < Array::value_type > ::max());
61 "upper bound size (" << result.
size()
62 <<
") not equal to params size ("
63 << params.
size() <<
")");
69 "lower bound size (" << result.
size()
70 <<
") not equal to params size ("
71 << params.
size() <<
")");
75 Constraint(ext::shared_ptr<Impl> impl = ext::shared_ptr<Impl>());
83 bool test(
const Array&)
const override {
return true; }
97 return std::all_of(params.
begin(), params.
end(), [](
Real p) { return p > 0.0; });
101 std::numeric_limits < Array::value_type > ::max());
121 return std::all_of(params.
begin(), params.
end(), [
this](
Real p) { return low_ <= p && p <= high_; });
152 for (
Size iter = 0; iter < c1ub.
size(); iter++) {
153 rtrnArray.
at(iter) = std::min(c1ub.
at(iter), c2ub.
at(iter));
161 for (
Size iter = 0; iter < c1lb.
size(); iter++) {
162 rtrnArray.
at(iter) = std::max(c1lb.
at(iter), c2lb.
at(iter));
183 "Upper and lower boundaries sizes are inconsistent.");
187 "Number of parameters and boundaries sizes are inconsistent.");
188 for (
Size i = 0; i < params.
size(); i++) {
189 if ((params[i] <
low_[i]) || (params[i] >
high_[i]))
1-D array used in linear algebra.
1-D array used in linear algebra.
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
bool test(const Array ¶ms) const override
Tests if params satisfy the constraint.
Array lowerBound(const Array ¶ms) const override
Returns lower bound for given parameters.
Array upperBound(const Array ¶ms) const override
Returns upper bound for given parameters.
Impl(Real low, Real high)
Constraint imposing all arguments to be in [low,high]
BoundaryConstraint(Real low, Real high)
bool test(const Array ¶ms) const override
Tests if params satisfy the constraint.
Array lowerBound(const Array ¶ms) const override
Returns lower bound for given parameters.
Array upperBound(const Array ¶ms) const override
Returns upper bound for given parameters.
Impl(Constraint c1, Constraint c2)
Constraint enforcing both given sub-constraints
CompositeConstraint(const Constraint &c1, const Constraint &c2)
Base class for constraint implementations.
virtual Array lowerBound(const Array ¶ms) const
Returns lower bound for given parameters.
virtual bool test(const Array ¶ms) const =0
Tests if params satisfy the constraint.
virtual Array upperBound(const Array ¶ms) const
Returns upper bound for given parameters.
bool test(const Array &p) const
Real update(Array &p, const Array &direction, Real beta) const
ext::shared_ptr< Impl > impl_
Array lowerBound(const Array ¶ms) const
Array upperBound(const Array ¶ms) const
bool test(const Array &) const override
Tests if params satisfy the constraint.
Array lowerBound(const Array &) const override
Returns lower bound for given parameters.
bool test(const Array ¶ms) const override
Tests if params satisfy the constraint.
Impl(Array low, Array high)
Array upperBound(const Array &) const override
Returns upper bound for given parameters.
Constraint imposing i-th argument to be in [low_i,high_i] for all i
NonhomogeneousBoundaryConstraint(const Array &low, const Array &high)
bool test(const Array ¶ms) const override
Tests if params satisfy the constraint.
Array lowerBound(const Array ¶ms) const override
Returns lower bound for given parameters.
Array upperBound(const Array ¶ms) const override
Returns upper bound for given parameters.
Constraint imposing positivity to all arguments
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container