diff --git a/DynamicModel.cc b/DynamicModel.cc index a2325314..995a2028 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -2151,18 +2151,18 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative computeNonSingularNormalization(contemporaneous_jacobian, cutoff, static_jacobian, dynamic_jacobian); - computePrologueAndEpilogue(static_jacobian, equation_reordered, variable_reordered, prologue, epilogue); + computePrologueAndEpilogue(static_jacobian, equation_reordered, variable_reordered); map >, NodeID> first_order_endo_derivatives = collect_first_order_derivatives_endogenous(); - equation_type_and_normalized_equation = equationTypeDetermination(equations, first_order_endo_derivatives, variable_reordered, equation_reordered, mfs); + equation_type_and_normalized_equation = equationTypeDetermination(first_order_endo_derivatives, variable_reordered, equation_reordered, mfs); cout << "Finding the optimal block decomposition of the model ...\n"; if (prologue+epilogue < (unsigned int) equation_number()) - computeBlockDecompositionAndFeedbackVariablesForEachBlock(static_jacobian, dynamic_jacobian, prologue, epilogue, equation_reordered, variable_reordered, blocks, equation_type_and_normalized_equation, false, true, mfs, inv_equation_reordered, inv_variable_reordered); + computeBlockDecompositionAndFeedbackVariablesForEachBlock(static_jacobian, dynamic_jacobian, equation_reordered, variable_reordered, blocks, equation_type_and_normalized_equation, false, true, mfs, inv_equation_reordered, inv_variable_reordered); - block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(dynamic_jacobian, prologue, epilogue, blocks, equations, equation_type_and_normalized_equation, variable_reordered, equation_reordered); + block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(dynamic_jacobian, blocks, equation_type_and_normalized_equation, variable_reordered, equation_reordered); printBlockDecomposition(blocks); diff --git a/ModelTree.cc b/ModelTree.cc index 2e2c403e..3fc5d76a 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -246,7 +246,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_type &eval_context, jaco { int nb_elements_contemparenous_Jacobian = 0; set > jacobian_elements_to_delete; - for (first_derivatives_type::iterator it = first_derivatives.begin(); + for (first_derivatives_type::const_iterator it = first_derivatives.begin(); it != first_derivatives.end(); it++) { int deriv_id = it->first.second; @@ -304,7 +304,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_type &eval_context, jaco } void -ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector &equation_reordered, vector &variable_reordered, unsigned int &prologue, unsigned int &epilogue) +ModelTree::computePrologueAndEpilogue(const jacob_map &static_jacobian_arg, vector &equation_reordered, vector &variable_reordered) { vector eq2endo(equation_number(), 0); equation_reordered.resize(equation_number()); @@ -411,7 +411,7 @@ ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector &equations, map >, NodeID> &first_order_endo_derivatives, vector &Index_Var_IM, vector &Index_Equ_IM, int mfs) +ModelTree::equationTypeDetermination(const map >, NodeID> &first_order_endo_derivatives, const vector &Index_Var_IM, const vector &Index_Equ_IM, int mfs) const { NodeID lhs, rhs; BinaryOpNode *eq_node; @@ -419,14 +419,13 @@ ModelTree::equationTypeDetermination(vector &equations, mapget_arg1(); rhs = eq_node->get_arg2(); Equation_Simulation_Type = E_SOLVE; - map >, NodeID>::iterator derivative = first_order_endo_derivatives.find(make_pair(eq, make_pair(var, 0))); + map >, NodeID>::const_iterator derivative = first_order_endo_derivatives.find(make_pair(eq, make_pair(var, 0))); pair res; if (derivative != first_order_endo_derivatives.end()) { @@ -460,7 +459,7 @@ ModelTree::equationTypeDetermination(vector &equations, map &components_set, int nb_blck_sim, int prologue, int epilogue, t_lag_lead_vector &equation_lead_lag, t_lag_lead_vector &variable_lead_lag, vector equation_reordered, vector variable_reordered) const +ModelTree::getVariableLeadLagByBlock(const dynamic_jacob_map &dynamic_jacobian, const vector &components_set, int nb_blck_sim, t_lag_lead_vector &equation_lead_lag, t_lag_lead_vector &variable_lead_lag, const vector &equation_reordered, const vector &variable_reordered) const { int nb_endo = symbol_table.endo_nbr(); variable_lead_lag = t_lag_lead_vector(nb_endo, make_pair(0, 0)); @@ -504,7 +503,7 @@ ModelTree::getVariableLeadLagByBlock(dynamic_jacob_map &dynamic_jacobian, vector } void -ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &static_jacobian, dynamic_jacob_map &dynamic_jacobian, int prologue, int epilogue, vector &equation_reordered, vector &variable_reordered, vector > &blocks, t_equation_type_and_normalized_equation &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs, vector &inv_equation_reordered, vector &inv_variable_reordered) const +ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob_map &static_jacobian, const dynamic_jacob_map &dynamic_jacobian, vector &equation_reordered, vector &variable_reordered, vector > &blocks, const t_equation_type_and_normalized_equation &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs, vector &inv_equation_reordered, vector &inv_variable_reordered) const { int nb_var = variable_reordered.size(); int n = nb_var - prologue - epilogue; @@ -573,7 +572,7 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map & t_lag_lead_vector equation_lag_lead, variable_lag_lead; - getVariableLeadLagByBlock(dynamic_jacobian, endo2block, num, prologue, epilogue, equation_lag_lead, variable_lag_lead, equation_reordered, variable_reordered); + getVariableLeadLagByBlock(dynamic_jacobian, endo2block, num, equation_lag_lead, variable_lag_lead, equation_reordered, variable_reordered); vector tmp_equation_reordered(equation_reordered), tmp_variable_reordered(variable_reordered); int order = prologue; @@ -637,7 +636,7 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map & } void -ModelTree::printBlockDecomposition(vector > blocks) +ModelTree::printBlockDecomposition(const vector > &blocks) const { int largest_block = 0; int Nb_SimulBlocks = 0; @@ -666,7 +665,7 @@ ModelTree::printBlockDecomposition(vector > blocks) } t_block_type_firstequation_size_mfs -ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian, int prologue, int epilogue, vector > &blocks, vector &equations, t_equation_type_and_normalized_equation &Equation_Type, vector &variable_reordered, vector &equation_reordered) +ModelTree::reduceBlocksAndTypeDetermination(const dynamic_jacob_map &dynamic_jacobian, const vector > &blocks, const t_equation_type_and_normalized_equation &Equation_Type, const vector &variable_reordered, const vector &equation_reordered) { int i = 0; int count_equ = 0, blck_count_simult = 0; @@ -786,7 +785,7 @@ ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian, } vector -ModelTree::BlockLinear(t_blocks_derivatives &blocks_derivatives, vector &variable_reordered) +ModelTree::BlockLinear(const t_blocks_derivatives &blocks_derivatives, const vector &variable_reordered) const { unsigned int nb_blocks = getNbBlocks(); vector blocks_linear(nb_blocks, true); diff --git a/ModelTree.hh b/ModelTree.hh index 094f4666..5415bf9c 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -163,19 +163,19 @@ protected: //! Evaluate the jacobian and suppress all the elements below the cutoff void evaluateAndReduceJacobian(const eval_context_type &eval_context, jacob_map &contemporaneous_jacobian, jacob_map &static_jacobian, dynamic_jacob_map &dynamic_jacobian, double cutoff, bool verbose); //! Search the equations and variables belonging to the prologue and the epilogue of the model - void computePrologueAndEpilogue(jacob_map &static_jacobian, vector &equation_reordered, vector &variable_reordered, unsigned int &prologue, unsigned int &epilogue); + void computePrologueAndEpilogue(const jacob_map &static_jacobian, vector &equation_reordered, vector &variable_reordered); //! Determine the type of each equation of model and try to normalized the unnormalized equation using computeNormalizedEquations - t_equation_type_and_normalized_equation equationTypeDetermination(vector &equations, map >, NodeID> &first_order_endo_derivatives, vector &Index_Var_IM, vector &Index_Equ_IM, int mfs); + t_equation_type_and_normalized_equation equationTypeDetermination(const map >, NodeID> &first_order_endo_derivatives, const vector &Index_Var_IM, const vector &Index_Equ_IM, int mfs) const; //! Compute the block decomposition and for a non-recusive block find the minimum feedback set - void computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &static_jacobian, dynamic_jacob_map &dynamic_jacobian, int prologue, int epilogue, vector &Index_Equ_IM, vector &Index_Var_IM, vector > &blocks, t_equation_type_and_normalized_equation &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs, vector &inv_equation_reordered, vector &inv_variable_reordered) const; + void computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob_map &static_jacobian, const dynamic_jacob_map &dynamic_jacobian, vector &equation_reordered, vector &variable_reordered, vector > &blocks, const t_equation_type_and_normalized_equation &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs, vector &inv_equation_reordered, vector &inv_variable_reordered) const; //! Reduce the number of block merging the same type equation in the prologue and the epilogue and determine the type of each block - t_block_type_firstequation_size_mfs reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian, int prologue, int epilogue, vector > &blocks, vector &equations, t_equation_type_and_normalized_equation &Equation_Type, vector &Index_Var_IM, vector &Index_Equ_IM); + t_block_type_firstequation_size_mfs reduceBlocksAndTypeDetermination(const dynamic_jacob_map &dynamic_jacobian, const vector > &blocks, const t_equation_type_and_normalized_equation &Equation_Type, const vector &variable_reordered, const vector &equation_reordered); //! Determine the maximum number of lead and lag for the endogenous variable in a bloc - void getVariableLeadLagByBlock(dynamic_jacob_map &dynamic_jacobian, vector &components_set, int nb_blck_sim, int prologue, int epilogue, t_lag_lead_vector &equation_lead_lag, t_lag_lead_vector &variable_lead_lag, vector equation_reordered, vector variable_reordered) const; + void getVariableLeadLagByBlock(const dynamic_jacob_map &dynamic_jacobian, const vector &components_set, int nb_blck_sim, t_lag_lead_vector &equation_lead_lag, t_lag_lead_vector &variable_lead_lag, const vector &equation_reordered, const vector &variable_reordered) const; //! Print an abstract of the block structure of the model - void printBlockDecomposition(vector > blocks); + void printBlockDecomposition(const vector > &blocks) const; //! Determine for each block if it is linear or not - vector BlockLinear(t_blocks_derivatives &blocks_derivatives, vector &variable_reordered); + vector BlockLinear(const t_blocks_derivatives &blocks_derivatives, const vector &variable_reordered) const; virtual SymbolType getTypeByDerivID(int deriv_id) const throw (UnknownDerivIDException) = 0; virtual int getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException) = 0; diff --git a/StaticModel.cc b/StaticModel.cc index 5df774e8..64935f7f 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -866,18 +866,18 @@ StaticModel::computingPass(const eval_context_type &eval_context, bool no_tmp_te computeNonSingularNormalization(contemporaneous_jacobian, cutoff, static_jacobian, dynamic_jacobian); - computePrologueAndEpilogue(static_jacobian, equation_reordered, variable_reordered, prologue, epilogue); + computePrologueAndEpilogue(static_jacobian, equation_reordered, variable_reordered); map >, NodeID> first_order_endo_derivatives = collect_first_order_derivatives_endogenous(); - equation_type_and_normalized_equation = equationTypeDetermination(equations, first_order_endo_derivatives, variable_reordered, equation_reordered, mfs); + equation_type_and_normalized_equation = equationTypeDetermination(first_order_endo_derivatives, variable_reordered, equation_reordered, mfs); cout << "Finding the optimal block decomposition of the model ...\n"; if (prologue+epilogue < (unsigned int) equation_number()) - computeBlockDecompositionAndFeedbackVariablesForEachBlock(static_jacobian, dynamic_jacobian, prologue, epilogue, equation_reordered, variable_reordered, blocks, equation_type_and_normalized_equation, false, false, mfs, inv_equation_reordered, inv_variable_reordered); + computeBlockDecompositionAndFeedbackVariablesForEachBlock(static_jacobian, dynamic_jacobian, equation_reordered, variable_reordered, blocks, equation_type_and_normalized_equation, false, false, mfs, inv_equation_reordered, inv_variable_reordered); - block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(dynamic_jacobian, prologue, epilogue, blocks, equations, equation_type_and_normalized_equation, variable_reordered, equation_reordered); + block_type_firstequation_size_mfs = reduceBlocksAndTypeDetermination(dynamic_jacobian, blocks, equation_type_and_normalized_equation, variable_reordered, equation_reordered); printBlockDecomposition(blocks);