File: boundedproblem.h

package info (click to toggle)
cppnumericalsolvers 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: cpp: 2,694; python: 236; sh: 20; makefile: 10
file content (59 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 *  This file is part of CppNumericalSolvers
 *
 *  Copyright (C) Tobias Wood @spinicist 2016
 *
 *  This Source Code form is subject to the terms of the MIT license.
 *  Please see the LICENSE file.
 *
 */

#ifndef BOUNDEDPROBLEM_H
#define BOUNDEDPROBLEM_H

#include <vector>
#include <Eigen/Core>

#include "problem.h"

namespace cppoptlib {

template<typename Scalar_, int CompileDim_ = Eigen::Dynamic>
class BoundedProblem : public Problem<Scalar_, CompileDim_> {
public:
    using Superclass = Problem<Scalar_, CompileDim_>;
    using typename Superclass::Scalar;
    using typename Superclass::TVector;

protected:
    TVector m_lowerBound;
    TVector m_upperBound;

public:
    BoundedProblem(int RunDim = CompileDim_) : Superclass() {
        TVector infBound(RunDim);
        infBound.setConstant(std::numeric_limits<Scalar>::infinity());
        m_lowerBound = -infBound;
        m_upperBound = infBound;
    }

    BoundedProblem(const TVector &l, const TVector &u) :
        Superclass(),
        m_lowerBound(l),
        m_upperBound(u)
    {}

    const TVector &lowerBound() const { return m_lowerBound; }
    void setLowerBound(const TVector &lb) { m_lowerBound = lb; }
    const TVector &upperBound() const { return m_upperBound; }
    void setUpperBound(const TVector &ub) { m_upperBound = ub; }

    void setBoxConstraint(TVector  lb, TVector  ub) {
        setLowerBound(lb);
        setUpperBound(ub);
    }
};

} // end namespace cppoptlib

#endif // BOUNDEDPROBLEM_H