scalar_bound_interval.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  */
36 
38 //
39 // Class to specify an interval constraint on a scalar control variable.
40 //
42 
43 #ifndef FASTRACK_CONTROL_SCALAR_BOUND_INTERVAL_H
44 #define FASTRACK_CONTROL_SCALAR_BOUND_INTERVAL_H
45 
47 
48 namespace fastrack {
49 namespace control {
50 
51 class ScalarBoundInterval : public ControlBound<double> {
52  public:
54  explicit ScalarBoundInterval(double min, double max) : min_(min), max_(max) {}
55 
56  // Assume 'params' is [min, max].
57  explicit ScalarBoundInterval(const std::vector<double>& params)
58  : min_(params[0]), max_(params[1]) {
59  if (params.size() != 2)
60  throw std::runtime_error("Incorrect number of parameters.");
61  }
62 
63  // Accessors.
64  double Min() const { return min_; }
65  double Max() const { return max_; }
66 
67  // Custom definition of copy-assign operator.
69  if (&other == this) return *this;
70 
71  min_ = other.min_;
72  max_ = other.max_;
73  return *this;
74  }
75 
76  // Derived classes must be able to check whether a query is inside the bound.
77  inline bool Contains(const double& query) const {
78  return min_ <= query && query <= max_;
79  }
80 
81  // Derived classes must be able to compute the projection of a vector
82  // (represented as the templated type) onto the surface of the bound.
83  // NOTE: We will treat this vector as emanating from the natural origin
84  // of the bound so that it constitutes a meaningful direction with respect
85  // to that origin.
86  inline double ProjectToSurface(const double& query) const {
87  return (query >= 0.0) ? max_ : min_;
88  }
89 
90  private:
91  // Min and max interval values.
92  double min_, max_;
93 }; //\class ControlBound
94 
95 } // namespace control
96 } // namespace fastrack
97 
98 #endif
double ProjectToSurface(const double &query) const
ScalarBoundInterval & operator=(const ScalarBoundInterval &other)
bool Contains(const double &query) const
Definition: box.h:53
ScalarBoundInterval(const std::vector< double > &params)


fastrack
Author(s): David Fridovich-Keil
autogenerated on Mon Aug 3 2020 21:28:37