linear_interpolant.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_LINEAR_INTERPOLANT_HPP
27 #define CASADI_LINEAR_INTERPOLANT_HPP
28 
29 #include "casadi/core/interpolant_impl.hpp"
30 #include <casadi/solvers/casadi_interpolant_linear_export.h>
31 
40 
41 namespace casadi {
51  class LinearInterpolant : public Interpolant {
52  public:
53  // Constructor
54  LinearInterpolant(const std::string& name,
55  const std::vector<double>& grid,
56  const std::vector<casadi_int>& offset,
57  const std::vector<double>& values,
58  casadi_int m);
59 
60  // Destructor
61  ~LinearInterpolant() override;
62 
63  // Get name of the plugin
64  const char* plugin_name() const override { return "linear";}
65 
66  // Name of the class
67  std::string class_name() const override { return "LinearInterpolant";}
68 
70  static Interpolant* creator(const std::string& name,
71  const std::vector<double>& grid,
72  const std::vector<casadi_int>& offset,
73  const std::vector<double>& values,
74  casadi_int m) {
75  return new LinearInterpolant(name, grid, offset, values, m);
76  }
77 
78  static Function do_inline(const std::string& name,
79  const std::vector<double>& grid,
80  const std::vector<casadi_int>& offset,
81  const std::vector<double>& values,
82  casadi_int m,
83  const Dict& opts);
84 
85  // Initialize
86  void init(const Dict& opts) override;
87 
89  int eval(const double** arg, double** res, casadi_int* iw, double* w, void* mem) const override;
90 
92 
93  bool has_jacobian() const override { return true;}
94  Function get_jacobian(const std::string& name,
95  const std::vector<std::string>& inames,
96  const std::vector<std::string>& onames,
97  const Dict& opts) const override;
99 
101  bool has_codegen() const override { return true;}
102 
104  void codegen_body(CodeGenerator& g) const override;
105 
107  static const std::string meta_doc;
108 
110 
111  static const Options options_;
112  const Options& get_options() const override { return options_;}
114 
116  void serialize_body(SerializingStream &s) const override;
118  void serialize_type(SerializingStream &s) const override;
119 
121  static ProtoFunction* deserialize(DeserializingStream& s);
122 
123  std::vector<casadi_int> lookup_mode_;
124 
125  protected:
127  explicit LinearInterpolant(DeserializingStream& s);
128  };
129 
131  class LinearInterpolantJac : public FunctionInternal {
132  public:
134  LinearInterpolantJac(const std::string& name) : FunctionInternal(name) {}
135 
137  ~LinearInterpolantJac() override;
138 
140  std::string class_name() const override { return "LinearInterpolantJac";}
141 
143  bool has_codegen() const override { return true;}
144 
146  void codegen_body(CodeGenerator& g) const override;
147 
148  // Initialize
149  void init(const Dict& opts) override;
150 
152  int eval(const double** arg, double** res, casadi_int* iw, double* w, void* mem) const override;
153 
155 
156  bool has_jacobian() const override { return true;}
157  Function get_jacobian(const std::string& name,
158  const std::vector<std::string>& inames,
159  const std::vector<std::string>& onames,
160  const Dict& opts) const override;
162 
164  void serialize_type(SerializingStream &s) const override;
165 
167  bool has_parametric_values() const;
168  bool has_parametric_grid() const;
169 
171  std::string serialize_base_function() const override { return "Interpolant"; }
172 
174  explicit LinearInterpolantJac(DeserializingStream& s) : FunctionInternal(s) {}
175  };
176 
177 } // namespace casadi
178 
180 #endif // CASADI_LINEAR_INTERPOLANT_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.