1#ifndef CPPAD_CG_EVALUATOR_SOLVE_INCLUDED
2#define CPPAD_CG_EVALUATOR_SOLVE_INCLUDED
36 using SourceCodePath =
typename CodeHandler<Scalar>::SourceCodePath;
44 const std::vector<const SourceCodePath*>* paths_;
49 const std::vector<const std::vector<CG<Scalar>*>*>* replaceOnPath_;
58 const std::map<const PathNodeEdges<Scalar>*,
CG<Scalar>>* replaceOnGraph_;
62 const std::set<const OperationNode<Scalar>*>* clone_;
66 const std::map<const OperationPathNode<Scalar>,
CG<Scalar>>* replaceArgument_;
79 const std::vector<const SourceCodePath*>&
paths,
88 CPPADCG_ASSERT_UNKNOWN(paths_->size() == replaceOnPath_->size());
90 for (
size_t i = 0;
i <
paths.size(); ++
i) {
141 CPPADCG_ASSERT_UNKNOWN(this->depth_ > 0);
143 if(paths_ !=
nullptr) {
144 const auto&
paths = *paths_;
145 for (
size_t i = 0;
i <
paths.size(); ++
i) {
146 size_t d = this->depth_ - 1;
147 if (isOnPath(*
paths[
i])) {
150 auto*
r = (*(*replaceOnPath_)[
i])[
d];
160 if(pathGraph_ !=
nullptr) {
162 if (
egdes !=
nullptr) {
163 auto it = replaceOnGraph_->find(
egdes);
164 if (
it != replaceOnGraph_->end()) {
172 if (clone_ !=
nullptr) {
173 if (clone_->find(&node) != clone_->end()) {
178 if (replaceArgument_ !=
nullptr) {
179 size_t d = this->depth_ - 1;
181 auto it = replaceArgument_->find(this->path_[
d - 1]);
182 if (
it != replaceArgument_->end()) {
192 inline bool isOnPath(
const SourceCodePath&
path)
const {
193 size_t d = this->depth_ - 1;
195 if (
d >=
path.size())
198 if (this->path_[
d].node !=
path[
d].node)
202 for (
size_t j = 0;
j <
d; ++
j) {
203 if (this->path_[
j] !=
path[
j]) {
EvaluatorCloneSolve(CodeHandler< Scalar > &handler, const std::vector< const SourceCodePath * > &paths, const std::vector< const std::vector< CG< Scalar > * > * > &replaceOnPath)
ActiveOut evalOperation(OperationNode< Scalar > &node)
EvaluatorCloneSolve(CodeHandler< Scalar > &handler, const BidirGraph< Scalar > &pathGraph, const std::map< const PathNodeEdges< Scalar > *, CG< Scalar > > &replaceOnGraph)
EvaluatorCloneSolve(CodeHandler< Scalar > &handler, const std::set< const OperationNode< Scalar > * > &clone, const std::map< const OperationPathNode< Scalar >, CG< Scalar > > &replaceArgument)
CG< ScalarOut > evalOperation(OperationNode< ScalarIn > &node)
bool GreaterThanZero(const cg::CG< Base > &x)