CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
augment_path_depth_lookahead_a.hpp
1 #ifndef CPPAD_CG_AUGMENTPATHDEPTHLOOKAHEAD_A_INCLUDED
2 #define CPPAD_CG_AUGMENTPATHDEPTHLOOKAHEAD_A_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2016 Ciengis
6  * Copyright (C) 2018 Joao Leal
7  *
8  * CppADCodeGen is distributed under multiple licenses:
9  *
10  * - Eclipse Public License Version 1.0 (EPL1), and
11  * - GNU General Public License Version 3 (GPL3).
12  *
13  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15  * ----------------------------------------------------------------------------
16  * Author: Joao Leal
17  */
18 
19 #include <cppad/cg/dae_index_reduction/augment_path.hpp>
20 
21 namespace CppAD {
22 namespace cg {
23 
32 template<class Base>
34 protected:
36  using ADCG = CppAD::AD<CGBase>;
37 public:
38 
39  bool augmentPath(Enode <Base>& i) override final {
40  i.color(this->logger_->log(), this->logger_->getVerbosity()); // avoids infinite recursion
41 
42  const std::vector<Vnode<Base>*>&vars = i.variables();
43 
44  // first look for derivative variables
45  for (Vnode<Base>* jj : vars) {
46  if (jj->derivative() == nullptr && // highest order derivative
47  jj->antiDerivative() != nullptr && // not an algebraic variable
48  jj->assignmentEquation() == nullptr) { // not assigned yet
49 
50  jj->setAssignmentEquation(i, this->logger_->log(), this->logger_->getVerbosity());
51  return true;
52  }
53  }
54 
55  for (Vnode<Base>* jj : vars) {
56  if (!jj->isColored() &&
57  jj->derivative() == nullptr && // highest order derivative
58  jj->antiDerivative() != nullptr) { // not an algebraic variable
59 
60  Enode<Base>& k = *jj->assignmentEquation(); // all variables are assigned to another equation
61 
62  if (!k.isColored()) {
63  //jj->color(this->logger_->log(), this->logger_->getVerbosity()); // do not color variables!
64 
65  bool pathFound = augmentPath(k);
66  if (pathFound) {
67  jj->setAssignmentEquation(i, this->logger_->log(), this->logger_->getVerbosity());
68  return true;
69  }
70  }
71  }
72  }
73 
74  return false;
75  }
76 
77 };
78 
79 } // END cg namespace
80 } // END CppAD namespace
81 
82 #endif
bool augmentPath(Enode< Base > &i) override final