nodes_variables.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 
00010 * Redistributions in binary form must reproduce the above copyright notice,
00011   this list of conditions and the following disclaimer in the documentation
00012   and/or other materials provided with the distribution.
00013 
00014 * Neither the name of the copyright holder nor the names of its
00015   contributors may be used to endorse or promote products derived from
00016   this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00022 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00024 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00025 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 ******************************************************************************/
00029 
00030 #ifndef TOWR_VARIABLES_NODE_VALUES_H_
00031 #define TOWR_VARIABLES_NODE_VALUES_H_
00032 
00033 #include <ifopt/variable_set.h>
00034 
00035 #include "state.h"
00036 #include "nodes_observer.h"
00037 
00038 namespace towr {
00039 
00071 class NodesVariables : public ifopt::VariableSet {
00072 public:
00073   using Ptr          = std::shared_ptr<NodesVariables>;
00074   using VecDurations = std::vector<double>;
00075   using ObserverPtr  = NodesObserver*;
00076 
00085   struct NodeValueInfo {
00086     int id_;   
00087     Dx deriv_; 
00088     int dim_;  
00089 
00090     NodeValueInfo() = default;
00091     NodeValueInfo(int node_id, Dx deriv, int node_dim);
00092     int operator==(const NodeValueInfo& right) const;
00093   };
00094 
00105   virtual std::vector<NodeValueInfo> GetNodeValuesInfo(int opt_idx) const = 0;
00106 
00114   int GetOptIndex(const NodeValueInfo& nvi) const;
00115   static const int NodeValueNotOptimized = -1;
00116 
00125   VectorXd GetValues () const override;
00126 
00137   void SetVariables (const VectorXd&x) override;
00138 
00142   VecBound GetBounds () const override;
00143 
00147   const std::vector<Node> GetNodes() const;
00148 
00152   int GetPolynomialCount() const;
00153 
00157   const std::vector<Node> GetBoundaryNodes(int poly_id) const;
00158 
00159   enum Side {Start=0, End};
00165   static int GetNodeId(int poly_id, Side side);
00166 
00171   void AddObserver(ObserverPtr const spline);
00172 
00176   int GetDim() const;
00177 
00184   void SetByLinearInterpolation(const VectorXd& initial_val,
00185                                 const VectorXd& final_val,
00186                                 double t_total);
00187 
00194   void AddStartBound (Dx deriv, const std::vector<int>& dimensions,
00195                       const VectorXd& val);
00196 
00203   void AddFinalBound(Dx deriv, const std::vector<int>& dimensions,
00204                      const VectorXd& val);
00205 
00206 protected:
00211   NodesVariables (const std::string& variable_name);
00212   virtual ~NodesVariables () = default;
00213 
00214   VecBound bounds_; 
00215   std::vector<Node> nodes_;
00216   int n_dim_;
00217 
00218 private:
00222   void UpdateObservers() const;
00223   std::vector<ObserverPtr> observers_;
00224 
00232   void AddBounds(int node_id, Dx deriv, const std::vector<int>& dim,
00233                  const VectorXd& values);
00239   void AddBound(const NodeValueInfo& node_info, double value);
00240 };
00241 
00242 } /* namespace towr */
00243 
00244 #endif /* TOWR_VARIABLES_NODE_VALUES_H_ */


towr
Author(s): Alexander W. Winkler
autogenerated on Mon Apr 15 2019 02:42:32