1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2013 Peter Caspers
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file projectedconstraint.hpp
21 \brief Projected constraint
22*/
23
24#ifndef quantlib_optimization_projectedconstraint_h
25#define quantlib_optimization_projectedconstraint_h
26
27#include <ql/math/optimization/constraint.hpp>
28#include <ql/math/optimization/projection.hpp>
29#include <utility>
30
31namespace QuantLib {
32
33 class ProjectedConstraint : public Constraint {
34
35 private:
36
37 class Impl final : public Constraint::Impl {
38 public:
39 Impl(Constraint constraint,
40 const Array& parameterValues,
41 const std::vector<bool>& fixParameters)
42 : constraint_(std::move(constraint)), projection_(parameterValues, fixParameters) {}
43 Impl(Constraint constraint, const Projection& projection)
44 : constraint_(std::move(constraint)), projection_(projection) {}
45 bool test(const Array& params) const override {
46 return constraint_.test(p: projection_.include(projectedParameters: params));
47 }
48 Array upperBound(const Array& params) const override {
49 return projection_.project(parameters: constraint_.upperBound(params: projection_.include(projectedParameters: params)));
50 }
51 Array lowerBound(const Array& params) const override {
52 return projection_.project(parameters: constraint_.lowerBound(params: projection_.include(projectedParameters: params)));
53 }
54
55 private:
56 const Constraint constraint_;
57 const Projection projection_;
58 };
59
60 public:
61
62 ProjectedConstraint(const Constraint &constraint,
63 const Array &parameterValues,
64 const std::vector<bool> &fixParameters)
65 : Constraint(ext::shared_ptr<Constraint::Impl>(
66 new ProjectedConstraint::Impl(constraint, parameterValues,
67 fixParameters))) {}
68
69 ProjectedConstraint(const Constraint &constraint,
70 const Projection &projection)
71 : Constraint(ext::shared_ptr<Constraint::Impl>(
72 new ProjectedConstraint::Impl(constraint, projection))) {}
73 };
74}
75
76#endif
77

source code of quantlib/ql/math/optimization/projectedconstraint.hpp