1 #ifndef CPPAD_CG_PANTELIDES_INCLUDED 2 #define CPPAD_CG_PANTELIDES_INCLUDED 19 #include <cppad/cg/dae_index_reduction/dae_structural_index_reduction.hpp> 20 #include <cppad/cg/dae_index_reduction/augment_path_depth_lookahead.hpp> 55 const std::vector<DaeVarInfo>& varInfo,
56 const std::vector<std::string>& eqName,
57 const std::vector<Base>& x) :
61 augmentPath_(&defaultAugmentPath_) {
79 inline std::unique_ptr<ADFun<CG<Base>>>
reduceIndex(std::vector<DaeVarInfo>& newVarInfo,
80 std::vector<DaeEquationInfo>& equationInfo)
override {
82 throw CGException(
"reduceIndex() can only be called once!");
84 if (this->verbosity_ >= Verbosity::Low)
85 log() <<
"######## Pantelides method ########\n";
87 augmentPath_->setLogger(*
this);
93 if (this->verbosity_ >= Verbosity::Low) {
94 graph_.printResultInfo(
"Pantelides");
96 log() <<
"Structural index: " << graph_.getStructuralIndex() << std::endl;
99 std::unique_ptr<ADFun<CGBase>> reducedFun(graph_.generateNewModel(newVarInfo, equationInfo, x_));
111 auto& vnodes = graph_.variables();
112 auto& enodes = graph_.equations();
116 if (this->verbosity_ >= Verbosity::High)
117 graph_.printDot(this->log());
119 size_t Ndash = enodes.size();
120 for (
size_t k = 0; k < Ndash; k++) {
123 if (this->verbosity_ >= Verbosity::High)
124 log() <<
"Outer loop: equation k = " << *i <<
"\n";
126 bool pathfound =
false;
134 if (!jj->isDeleted() && jj->derivative() !=
nullptr) {
135 jj->deleteNode(log(), this->verbosity_);
144 const size_t vsize = vnodes.size();
145 for (
size_t l = 0; l < vsize; ++l) {
147 if (jj->isColored() && !jj->isDeleted()) {
149 graph_.createDerivate(*jj);
153 const size_t esize = enodes.size();
154 for (
size_t l = 0; l < esize; l++) {
156 if (ll->isColored()) {
158 graph_.createDerivate(*ll);
163 for (
size_t l = esize; l < enodes.size(); l++) {
165 const std::vector<Vnode<Base>*>& nvars = ll->originalVariables();
168 if (js->equations().size() > 1) {
174 throw CGException(
"Invalid equation structure. The model appears to be over-defined.");
178 if (jj->isColored() && !jj->isDeleted()) {
180 jDiff->setAssignmentEquation(*jj->assignmentEquation()->derivative(), log(), this->verbosity_);
186 if (this->verbosity_ >= Verbosity::High) {
187 log() <<
"Set current equation to (i=" << i->index() <<
") " << *i <<
"\n";
189 graph_.printDot(this->log());
Vnode< Base > * derivative() const
std::unique_ptr< ADFun< CG< Base > > > reduceIndex(std::vector< DaeVarInfo > &newVarInfo, std::vector< DaeEquationInfo > &equationInfo) override
Enode< Base > * derivative() const
virtual bool augmentPath(Enode< Base > &i)=0
Pantelides(ADFun< CG< Base > > &fun, const std::vector< DaeVarInfo > &varInfo, const std::vector< std::string > &eqName, const std::vector< Base > &x)