1 #ifndef CPPAD_CG_SOARES_SECCHI_HPP
2 #define CPPAD_CG_SOARES_SECCHI_HPP
19 #include <cppad/cg/dae_index_reduction/dae_structural_index_reduction.hpp>
20 #include <cppad/cg/dae_index_reduction/augment_path_depth_lookahead.hpp>
21 #include <cppad/cg/dae_index_reduction/augment_path_depth_lookahead_a.hpp>
64 const std::vector<DaeVarInfo>& varInfo,
65 const std::vector<std::string>& eqName,
66 const std::vector<Base>& x) :
70 augmentPath_(&defaultAugmentPath_),
71 augmentPathA_(&defaultAugmentPathA_){
82 AugmentPath<Base>& getAugmentPath()
const {
86 void setAugmentPath(AugmentPath<Base>& a)
const {
96 graph_.setPreserveNames(p);
105 return graph_.isPreserveNames();
118 inline std::unique_ptr<ADFun<CG<Base>>>
reduceIndex(std::vector<DaeVarInfo>& newVarInfo,
119 std::vector<DaeEquationInfo>& equationInfo)
override {
121 throw CGException(
"reduceIndex() can only be called once!");
123 if (this->verbosity_ >= Verbosity::High)
124 log() <<
"######## Soares Secchi method ########\n";
126 augmentPath_->setLogger(*
this);
127 augmentPathA_->setLogger(*
this);
139 if (this->verbosity_ >= Verbosity::Low) {
140 graph_.printResultInfo(
"Soares Secchi");
142 log() <<
"Structural index: " << graph_.getStructuralIndex() << std::endl;
145 std::unique_ptr<ADFun<CGBase>> reducedFun(graph_.generateNewModel(newVarInfo, equationInfo, x_));
158 return graph_.getStructuralIndex();
167 inline void detectSubset2Dif() {
168 auto& vnodes = graph_.variables();
169 auto& enodes = graph_.equations();
171 std::set<Enode<Base>*> marked;
172 std::set<Enode<Base>*> lastMarked;
174 if (this->verbosity_ >= Verbosity::High)
175 graph_.printDot(this->log());
179 for (
size_t k = 0; k < enodes.size(); k++) {
182 if (this->verbosity_ >= Verbosity::High)
183 log() <<
"Outer loop: equation k = " << *i <<
"\n";
185 if (i->assignmentVariable() !=
nullptr) {
192 for (Enode<Base>* ii: enodes) {
194 if (ii->isColored() && ii->derivative() ==
nullptr) {
204 throw CGException(
"Singular system detected.");
207 for (
auto* jj: vnodes)
211 for (
auto* ii: enodes)
220 for (Enode<Base>* i: marked) {
221 graph_.createDerivate(*i,
false);
224 if (this->verbosity_ >= Verbosity::High)
225 graph_.printDot(this->log());
227 lastMarked.swap(marked);
232 for (
const Enode<Base>* i: lastMarked) {