Commit 45c28cad authored by ferhat's avatar ferhat
Browse files

- minor modifications in Reorder_the_recursive_variables prototype

- no function comment in MinimumFeedbackSet.cc
- writeChaineRuleDerivative in DynamicModel.cc instead of ModelTree.cc


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2836 ac1d8469-bf42-47a9-8791-bf33cf982152
parent d2dfda62
......@@ -290,7 +290,7 @@ BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Blo
components_set[i].second.first = feed_back_vertices;
blocks[i].second = feed_back_vertices.size();
vector<int> Reordered_Vertice;
Reordered_Vertice = Reorder_the_recursive_variables(G, feed_back_vertices);
Reorder_the_recursive_variables(G, feed_back_vertices, Reordered_Vertice);
//First we have the recursive equations conditional on feedback variables
for (vector<int>::iterator its = Reordered_Vertice.begin(); its != Reordered_Vertice.end(); its++)
{
......
......@@ -2928,6 +2928,19 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
paramsDerivsFile.close();
}
void
DynamicModel::writeChaineRuleDerivative(ostream &output, int eq, int var, int lag,
ExprNodeOutputType output_type,
const temporary_terms_type &temporary_terms) const
{
map<pair<int, pair<int, int> >, NodeID>::const_iterator it = first_chaine_rule_derivatives.find(make_pair(eq, make_pair(var, lag)));
if (it != first_chaine_rule_derivatives.end())
(it->second)->writeOutput(output, output_type, temporary_terms);
else
output << 0;
}
void
DynamicModel::writeLatexFile(const string &basename) const
{
......@@ -2955,3 +2968,5 @@ DynamicModel::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOut
output << row_nb + col_nb * NNZDerivatives[1];
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
......@@ -77,6 +77,10 @@ private:
//! Temporary terms for the file containing parameters dervicatives
temporary_terms_type params_derivs_temporary_terms;
typedef map< pair< int, pair< int, int> >, NodeID> first_chaine_rule_derivatives_type;
first_chaine_rule_derivatives_type first_chaine_rule_derivatives;
//! Writes dynamic model file (Matlab version)
void writeDynamicMFile(const string &dynamic_basename) const;
//! Writes dynamic model file (C version)
......@@ -133,6 +137,10 @@ private:
/*! Writes either (i+1,j+1) or [i+j*NNZDerivatives[1]] */
void hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
//! Write chaine rule derivative of a recursive equation w.r. to a variable
void writeChaineRuleDerivative(ostream &output, int eq, int var, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
public:
DynamicModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
//! Mode in which the ModelTree is supposed to work (Matlab, DLL or SparseDLL)
......
......@@ -26,8 +26,6 @@ namespace MFS
void
Suppress(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type& G)
{
/*clear all in and out edges of vertex_to_eliminate
and remove vertex_to_eliminate from the graph*/
clear_vertex(vertex_to_eliminate, G);
remove_vertex(vertex_to_eliminate, G);
}
......@@ -43,7 +41,6 @@ namespace MFS
void
Eliminate(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type& G)
{
/*before the vertex i suppression replace all edges e_k_i and e_i_j by e_k_j*/
if (in_degree (vertex_to_eliminate, G) > 0 && out_degree (vertex_to_eliminate, G) > 0)
{
AdjacencyList_type::in_edge_iterator it_in, in_end;
......@@ -69,14 +66,11 @@ namespace MFS
color[u] = gray_color;
graph_traits<AdjacencyList_type>::out_edge_iterator vi, vi_end;
for (tie(vi, vi_end) = out_edges(u, g); vi != vi_end; ++vi)
if (color[target(*vi, g)] == white_color)
if (color[target(*vi, g)] == white_color && has_cycle_dfs(g, target(*vi, g), color, circuit_stack))
{
if (has_cycle_dfs(g, target(*vi, g), color, circuit_stack))
{
// cycle detected, return immediately
circuit_stack.push_back(v_index[target(*vi, g)]);
return true;
}
// cycle detected, return immediately
circuit_stack.push_back(v_index[target(*vi, g)]);
return true;
}
else if (color[target(*vi, g)] == gray_color)
{
......@@ -215,8 +209,6 @@ namespace MFS
vector_vertex_descriptor
Collect_Doublet(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type& G)
{
/*collect all doublet (for each edge e_i_k there is an edge e_k_i with k!=i) in the graph
and return the vector of doublet*/
AdjacencyList_type::in_edge_iterator it_in, in_end;
AdjacencyList_type::out_edge_iterator it_out, out_end;
vector<AdjacencyList_type::vertex_descriptor> Doublet;
......@@ -231,7 +223,6 @@ namespace MFS
bool
Vertex_Belong_to_a_Clique(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type& G)
{
/*Detect all the clique (all vertex in a clique are related to each other) in the graph*/
vector<AdjacencyList_type::vertex_descriptor> liste;
bool agree = true;
AdjacencyList_type::in_edge_iterator it_in, in_end;
......@@ -271,7 +262,6 @@ namespace MFS
bool
Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(AdjacencyList_type& G)
{
/*Graph reduction: eliminating purely intermediate variables or variables outside of any circuit*/
bool something_has_been_done = false;
bool not_a_loop;
int i;
......@@ -466,8 +456,8 @@ namespace MFS
}
};
vector<int>
Reorder_the_recursive_variables(const AdjacencyList_type& G1, set<int> &feedback_vertices)
void
Reorder_the_recursive_variables(const AdjacencyList_type& G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices)
{
AdjacencyList_type G(G1);
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
......@@ -477,11 +467,7 @@ namespace MFS
fv.insert(*its);
int i=0;
for (its = fv.begin(); its != fv.end(); ++its, i++)
{
//cout << "supress " << v_index[vertex(*its, G)]+1 << " " << *its << "\n";
Suppress(*its, G);
}
vector< int> Reordered_Vertices;
Suppress(*its, G);
bool something_has_been_done = true;
while (something_has_been_done)
{
......@@ -507,6 +493,5 @@ namespace MFS
}
if (num_vertices(G))
cout << "Error in the computation of feedback vertex set\n";
return Reordered_Vertices;
}
}
......@@ -73,7 +73,7 @@ namespace MFS
void Suppress(int vertex_num, AdjacencyList_type& G);
//! Reorder the recursive variables
/*! They appear first in a quasi triangular form and they are followed by the feedback variables */
vector<int> Reorder_the_recursive_variables(const AdjacencyList_type& G1, set<int> &feed_back_vertices);
void Reorder_the_recursive_variables(const AdjacencyList_type& G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices);
};
#endif // _MINIMUMFEEDBACKSET_HH
......@@ -65,18 +65,6 @@ ModelTree::computeJacobian(const set<int> &vars)
}
}
void
ModelTree::writeChaineRuleDerivative(ostream &output, int eq, int var, int lag,
ExprNodeOutputType output_type,
const temporary_terms_type &temporary_terms) const
{
map<pair<int, pair<int, int> >, NodeID>::const_iterator it = first_chaine_rule_derivatives.find(make_pair(eq, make_pair(var, lag)));
if (it != first_chaine_rule_derivatives.end())
(it->second)->writeOutput(output, output_type, temporary_terms);
else
output << 0;
}
void
......
......@@ -47,8 +47,6 @@ protected:
*/
first_derivatives_type first_derivatives;
typedef map< pair< int, pair< int, int> >, NodeID> first_chaine_rule_derivatives_type;
first_chaine_rule_derivatives_type first_chaine_rule_derivatives;
typedef map<pair<int, pair<int, int> >, NodeID> second_derivatives_type;
//! Second order derivatives
......@@ -83,8 +81,6 @@ protected:
//! Write derivative of an equation w.r. to a variable
void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
//! Write chaine rule derivative of a recursive equation w.r. to a variable
void writeChaineRuleDerivative(ostream &output, int eq, int var, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
//! Computes temporary terms (for all equations and derivatives)
void computeTemporaryTerms(bool is_matlab);
//! Writes temporary terms
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment