- extension of normalization of equations to nonlinear equations
- mfs: new option for 'steady' and 'model' commands. Determines the equation belonging to the set of feedback variables. mfs = 0 => all variables are considered as feedback variables (default value) mfs = 1 => using only naturally normalized equation as potential recursive equations (all variables assigned to unnormalized equations are considered as feedback variable) mfs = 2 => adding to the set of potential recursive equation with mfs = 1 the linear equation in endogenous variable normalized (all variables assigned to nonlinear unnormalized equations are considered as feedback variable) mfs = 3 => adding to the set of potential recursive equation with mfs = 2 the non linear equation in endogenous variable normalized - correction of few buggs in simulate.dll - block_mfs_dll: new option for 'steady' command. Use simulate.dll to solve the steady state model (speedup the computation of the steady-state and the homotopy) git-svn-id: https://www.dynare.org/svn/dynare/trunk@2866 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
91a7432d56
commit
4897b602c6
|
@ -20,7 +20,6 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
@ -46,6 +45,7 @@ BlockTriangular::BlockTriangular(SymbolTable &symbol_table_arg, NumericalConstan
|
|||
bt_verbose = 0;
|
||||
ModelBlock = NULL;
|
||||
periods = 0;
|
||||
prologue = epilogue = 0;
|
||||
Normalized_Equation = new DataTree(symbol_table, num_const);
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ BlockTriangular::Prologue_Epilogue(bool *IM, int &prologue, int &epilogue, int n
|
|||
//------------------------------------------------------------------------------
|
||||
// Find a matching between equations and endogenous variables
|
||||
bool
|
||||
BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, bool verbose, bool *IM0, vector<int> &Index_Equ_IM) const
|
||||
BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, int verbose, bool *IM0, vector<int> &Index_Equ_IM) const
|
||||
{
|
||||
int n = equation_number - prologue - epilogue;
|
||||
|
||||
|
@ -143,9 +143,17 @@ BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prolog
|
|||
mate_map_t::const_iterator it = find(mate_map.begin(), mate_map.begin() + n, graph_traits<BipartiteGraph>::null_vertex());
|
||||
if (it != mate_map.begin() + n)
|
||||
{
|
||||
if (verbose)
|
||||
if (verbose == 1)
|
||||
{
|
||||
cerr << "ERROR: Could not normalize dynamic model. Variable "
|
||||
cerr << "WARNING: Could not normalize dynamic model. Variable "
|
||||
<< symbol_table.getName(symbol_table.getID(eEndogenous, it - mate_map.begin()))
|
||||
<< " is not in the maximum cardinality matching. Trying to find a singular normalization." << endl;
|
||||
//exit(EXIT_FAILURE);
|
||||
return false;
|
||||
}
|
||||
else if (verbose == 2)
|
||||
{
|
||||
cerr << "ERROR: Could not normalize dynamic model (even with a singularity). Variable "
|
||||
<< symbol_table.getName(symbol_table.getID(eEndogenous, it - mate_map.begin()))
|
||||
<< " is not in the maximum cardinality matching." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -183,7 +191,7 @@ BlockTriangular::Get_Variable_LeadLag_By_Block(vector<int > &components_set, int
|
|||
variable_blck[Index_Var_IM[i]] = i;
|
||||
equation_blck[Index_Equ_IM[i]] = i;
|
||||
}
|
||||
else if (i < components_set.size() + prologue)
|
||||
else if (i < (int)components_set.size() + prologue)
|
||||
{
|
||||
variable_blck[Index_Var_IM[i]] = components_set[i-prologue] + prologue;
|
||||
equation_blck[Index_Equ_IM[i]] = components_set[i-prologue] + prologue;
|
||||
|
@ -226,7 +234,7 @@ BlockTriangular::Get_Variable_LeadLag_By_Block(vector<int > &components_set, int
|
|||
}
|
||||
|
||||
void
|
||||
BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_) const
|
||||
BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs) const
|
||||
{
|
||||
t_vtype V_Variable_Type;
|
||||
int n = nb_var - prologue - epilogue;
|
||||
|
@ -272,11 +280,16 @@ BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Blo
|
|||
memcpy(SIM, IM, nb_var*nb_var*sizeof(bool));
|
||||
|
||||
//Add a loop on vertices which could not be normalized or vertices related to lead variables => force those vertices to belong to the feedback set
|
||||
for (int i = 0; i < n; i++)
|
||||
if (Equation_Type[Index_Equ_IM[i+prologue]].first == E_SOLVE or V_Variable_Type[Index_Var_IM[i+prologue]].second > 0 or V_Variable_Type[Index_Var_IM[i+prologue]].first > 0
|
||||
or equation_lead_lag[Index_Equ_IM[i+prologue]].second > 0 or equation_lead_lag[Index_Equ_IM[i+prologue]].first > 0)
|
||||
add_edge(i, i, G2);
|
||||
|
||||
if(select_feedback_variable)
|
||||
for (int i = 0; i < n; i++)
|
||||
if (Equation_Type[Index_Equ_IM[i+prologue]].first == E_SOLVE or V_Variable_Type[Index_Var_IM[i+prologue]].second > 0 or V_Variable_Type[Index_Var_IM[i+prologue]].first > 0
|
||||
or equation_lead_lag[Index_Equ_IM[i+prologue]].second > 0 or equation_lead_lag[Index_Equ_IM[i+prologue]].first > 0
|
||||
or mfs == 0)
|
||||
add_edge(i, i, G2);
|
||||
else
|
||||
for (int i = 0; i < n; i++)
|
||||
if (Equation_Type[Index_Equ_IM[i+prologue]].first == E_SOLVE or mfs == 0)
|
||||
add_edge(i, i, G2);
|
||||
//For each block, the minimum set of feedback variable is computed
|
||||
// and the non-feedback variables are reordered to get
|
||||
// a sub-recursive block without feedback variables
|
||||
|
@ -686,7 +699,7 @@ BlockTriangular::Free_Block(Model_Block *ModelBlock) const
|
|||
}
|
||||
|
||||
t_etype
|
||||
BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM)
|
||||
BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, int mfs)
|
||||
{
|
||||
NodeID lhs, rhs;
|
||||
ostringstream tmp_output;
|
||||
|
@ -709,44 +722,40 @@ BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations,
|
|||
lhs->writeOutput(tmp_output, oMatlabDynamicModelSparse, temporary_terms);
|
||||
tmp_s << "y(it_, " << Index_Var_IM[i]+1 << ")";
|
||||
map<pair<int, pair<int, int> >, NodeID>::iterator derivative = first_order_endo_derivatives.find(make_pair(eq, make_pair(var, 0)));
|
||||
/*cout << "eq=" << eq << " var=" << var << "=";
|
||||
first_cur_endo_derivatives[make_pair(eq, var)]->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
|
||||
cout << "\n";
|
||||
cout << "equation : ";
|
||||
eq_node->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
|
||||
cout << "\n";*/
|
||||
set<pair<int, int> > result;
|
||||
pair<bool, NodeID> res;
|
||||
derivative->second->collectEndogenous(result);
|
||||
/*for(set<pair<int, int> >::const_iterator iitt = result.begin(); iitt!=result.end(); iitt++)
|
||||
cout << "result = " << iitt->first << ", " << iitt->second << "\n";*/
|
||||
set<pair<int, int> >::const_iterator d_endo_variable = result.find(make_pair(var, 0));
|
||||
//Determine whether the equation could be evaluated rather than to be solved
|
||||
if (tmp_output.str() == tmp_s.str() and d_endo_variable == result.end())
|
||||
ostringstream tt("");
|
||||
derivative->second->writeOutput(tt, oMatlabDynamicModelSparse, temporary_terms);
|
||||
//cout << tt.str().c_str() << " tmp_output.str()=" << tmp_output.str() << " tmp_s.str()=" << tmp_s.str();
|
||||
if (tmp_output.str() == tmp_s.str() and tt.str()=="1")
|
||||
{
|
||||
Equation_Simulation_Type = E_EVALUATE;
|
||||
//cout << " E_EVALUATE ";
|
||||
}
|
||||
else
|
||||
{
|
||||
//vector<pair<int, NodeID> > List_of_Op_RHS;
|
||||
//the equation could be normalized by a permutation of the rhs and the lhs
|
||||
if (d_endo_variable == result.end()) //the equation is linear in the endogenous and could be normalized using the derivative
|
||||
vector<pair<int, pair<NodeID, NodeID> > > List_of_Op_RHS;
|
||||
res = equations[eq]->normalizeEquation(var, List_of_Op_RHS);
|
||||
if(mfs==2)
|
||||
{
|
||||
Equation_Simulation_Type = E_EVALUATE_S;
|
||||
//cout << " gone normalized : ";
|
||||
res = equations[eq]->normalizeLinearInEndoEquation(var, derivative->second/*, List_of_Op_RHS*/);
|
||||
/*res.second->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
|
||||
cout << " done\n";*/
|
||||
if(d_endo_variable == result.end() && res.second)
|
||||
Equation_Simulation_Type = E_EVALUATE_S;
|
||||
}
|
||||
else if(mfs==3)
|
||||
{
|
||||
if(res.second) // The equation could be solved analytically
|
||||
Equation_Simulation_Type = E_EVALUATE_S;
|
||||
}
|
||||
}
|
||||
//cout << " " << c_Equation_Type(Equation_Simulation_Type) << endl;
|
||||
V_Equation_Simulation_Type[eq] = make_pair(Equation_Simulation_Type, dynamic_cast<BinaryOpNode *>(res.second));
|
||||
}
|
||||
return (V_Equation_Simulation_Type);
|
||||
}
|
||||
|
||||
/*void
|
||||
BlockTriangular::Recompute_Deriavtives_Respect_to_Feedback_Variables(
|
||||
*/
|
||||
t_type
|
||||
BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue, vector<pair<int, int> > &blocks, vector<BinaryOpNode *> &equations, t_etype &Equation_Type, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM)
|
||||
{
|
||||
|
@ -859,15 +868,15 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
|
|||
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int>
|
||||
BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
|
||||
{
|
||||
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> Derivatives;
|
||||
Derivatives.clear();
|
||||
int nb_endo = symbol_table.endo_nbr();
|
||||
/*ModelBlock.Block_List[Blck].first_order_determinstic_simulation_derivatives = new*/
|
||||
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> Derivatives;
|
||||
Derivatives.clear();
|
||||
int nb_endo = symbol_table.endo_nbr();
|
||||
/*ModelBlock.Block_List[Blck].first_order_determinstic_simulation_derivatives = new*/
|
||||
for(int lag = -ModelBlock->Block_List[blck].Max_Lag; lag <= ModelBlock->Block_List[blck].Max_Lead; lag++)
|
||||
{
|
||||
bool *IM=incidencematrix.Get_IM(lag, eEndogenous);
|
||||
if(IM)
|
||||
{
|
||||
bool *IM=incidencematrix.Get_IM(lag, eEndogenous);
|
||||
if(IM)
|
||||
{
|
||||
for(int eq = 0; eq < ModelBlock->Block_List[blck].Size; eq++)
|
||||
{
|
||||
int eqr = ModelBlock->Block_List[blck].Equation[eq];
|
||||
|
@ -886,26 +895,26 @@ BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
|
|||
OK=false;
|
||||
}
|
||||
|
||||
if(OK)
|
||||
{
|
||||
if (ModelBlock->Block_List[blck].Equation_Type[eq] == E_EVALUATE_S and eq<ModelBlock->Block_List[blck].Nb_Recursives)
|
||||
//It's a normalized equation, we have to recompute the derivative using chain rule derivative function*/
|
||||
if(OK)
|
||||
{
|
||||
if (ModelBlock->Block_List[blck].Equation_Type[eq] == E_EVALUATE_S and eq<ModelBlock->Block_List[blck].Nb_Recursives)
|
||||
//It's a normalized equation, we have to recompute the derivative using chain rule derivative function*/
|
||||
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 1;
|
||||
else
|
||||
//It's a feedback equation we can use the derivatives
|
||||
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 0;
|
||||
}
|
||||
if(var<ModelBlock->Block_List[blck].Nb_Recursives)
|
||||
{
|
||||
int eqs = ModelBlock->Block_List[blck].Equation[var];
|
||||
for(int vars=ModelBlock->Block_List[blck].Nb_Recursives; vars<ModelBlock->Block_List[blck].Size; vars++)
|
||||
{
|
||||
int varrs = ModelBlock->Block_List[blck].Variable[vars];
|
||||
//A new derivative need to be computed using the chain rule derivative function (a feedback variable appear in a recursive equation)
|
||||
if(Derivatives.find(make_pair(make_pair(lag, make_pair(var, vars)), make_pair(eqs, varrs)))!=Derivatives.end())
|
||||
Derivatives[make_pair(make_pair(lag, make_pair(eq, vars)), make_pair(eqr, varrs))] = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
//It's a feedback equation we can use the derivatives
|
||||
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 0;
|
||||
}
|
||||
if(var<ModelBlock->Block_List[blck].Nb_Recursives)
|
||||
{
|
||||
int eqs = ModelBlock->Block_List[blck].Equation[var];
|
||||
for(int vars=ModelBlock->Block_List[blck].Nb_Recursives; vars<ModelBlock->Block_List[blck].Size; vars++)
|
||||
{
|
||||
int varrs = ModelBlock->Block_List[blck].Variable[vars];
|
||||
//A new derivative need to be computed using the chain rule derivative function (a feedback variable appear in a recursive equation)
|
||||
if(Derivatives.find(make_pair(make_pair(lag, make_pair(var, vars)), make_pair(eqs, varrs)))!=Derivatives.end())
|
||||
Derivatives[make_pair(make_pair(lag, make_pair(eq, vars)), make_pair(eqr, varrs))] = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -915,18 +924,18 @@ BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
|
|||
}
|
||||
|
||||
void
|
||||
BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool *IM_0, jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives)
|
||||
BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool *IM_0, jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, bool dynamic, int mfs, double cutoff)
|
||||
{
|
||||
int i, j, Nb_TotalBlocks, Nb_RecursBlocks, Nb_SimulBlocks;
|
||||
BlockType Btype;
|
||||
int count_Block, count_Equ;
|
||||
bool *SIM0, *SIM00;
|
||||
|
||||
|
||||
SIM0 = (bool *) malloc(n * n * sizeof(bool));
|
||||
SIM0 = (bool *) malloc(n * n * sizeof(bool));
|
||||
memcpy(SIM0, IM_0, n*n*sizeof(bool));
|
||||
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM, SIM0);
|
||||
free(SIM0);
|
||||
|
||||
int counted = 0;
|
||||
if (prologue+epilogue < n)
|
||||
{
|
||||
|
@ -956,7 +965,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
memset(SIM00, 0, n*n*sizeof(bool));
|
||||
for (map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++)
|
||||
{
|
||||
if (fabs(iter->second) > bi)
|
||||
if (fabs(iter->second) > max(bi, cutoff))
|
||||
{
|
||||
SIM0[iter->first.first*n+iter->first.second] = 1;
|
||||
if (!IM_0[iter->first.first*n+iter->first.second])
|
||||
|
@ -974,7 +983,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
}
|
||||
free(SIM0);
|
||||
if (suppress != suppressed)
|
||||
OK = Compute_Normalization(IM, n, prologue, epilogue, false, SIM00, Index_Equ_IM);
|
||||
OK = Compute_Normalization(IM, n, prologue, epilogue, 0, SIM00, Index_Equ_IM);
|
||||
suppressed = suppress;
|
||||
if (!OK)
|
||||
//bi/=1.07;
|
||||
|
@ -984,15 +993,23 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
free(SIM00);
|
||||
}
|
||||
if (!OK)
|
||||
Compute_Normalization(IM, n, prologue, epilogue, true, SIM00, Index_Equ_IM);
|
||||
{
|
||||
Compute_Normalization(IM, n, prologue, epilogue, 1, SIM00, Index_Equ_IM);
|
||||
Compute_Normalization(IM, n, prologue, epilogue, 2, IM_0, Index_Equ_IM);
|
||||
}
|
||||
}
|
||||
|
||||
V_Equation_Type = Equation_Type_determination(equations, first_order_endo_derivatives, Index_Var_IM, Index_Equ_IM);
|
||||
V_Equation_Type = Equation_Type_determination(equations, first_order_endo_derivatives, Index_Var_IM, Index_Equ_IM, mfs);
|
||||
|
||||
cout << "Finding the optimal block decomposition of the model ...\n";
|
||||
vector<pair<int, int> > blocks;
|
||||
if (prologue+epilogue < n)
|
||||
Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(IM, n, prologue, epilogue, Index_Equ_IM, Index_Var_IM, blocks, V_Equation_Type, false);
|
||||
{
|
||||
if(dynamic)
|
||||
Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(IM, n, prologue, epilogue, Index_Equ_IM, Index_Var_IM, blocks, V_Equation_Type, false, true, mfs);
|
||||
else
|
||||
Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(IM, n, prologue, epilogue, Index_Equ_IM, Index_Var_IM, blocks, V_Equation_Type, false, false, mfs);
|
||||
}
|
||||
|
||||
t_type Type = Reduce_Blocks_and_type_determination(prologue, epilogue, blocks, equations, V_Equation_Type, Index_Var_IM, Index_Equ_IM);
|
||||
|
||||
|
@ -1049,7 +1066,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
|
|||
// normalize each equation of the dynamic model
|
||||
// and find the optimal block triangular decomposition of the static model
|
||||
void
|
||||
BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives)
|
||||
BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, int mfs, double cutoff)
|
||||
{
|
||||
bool *SIM, *SIM_0;
|
||||
bool *Cur_IM;
|
||||
|
@ -1091,7 +1108,7 @@ BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vec
|
|||
SIM_0 = (bool *) malloc(symbol_table.endo_nbr() * symbol_table.endo_nbr() * sizeof(*SIM_0));
|
||||
for (i = 0; i < symbol_table.endo_nbr()*symbol_table.endo_nbr(); i++)
|
||||
SIM_0[i] = Cur_IM[i];
|
||||
Normalize_and_BlockDecompose(SIM, ModelBlock, symbol_table.endo_nbr(), prologue, epilogue, Index_Var_IM, Index_Equ_IM, SIM_0, j_m, equations, equation_simulation_type, first_order_endo_derivatives);
|
||||
Normalize_and_BlockDecompose(SIM, ModelBlock, symbol_table.endo_nbr(), prologue, epilogue, Index_Var_IM, Index_Equ_IM, SIM_0, j_m, equations, equation_simulation_type, first_order_endo_derivatives, true, mfs, cutoff);
|
||||
free(SIM_0);
|
||||
free(SIM);
|
||||
}
|
||||
|
|
|
@ -97,11 +97,11 @@ private:
|
|||
//! Allocates and fills the Model structure describing the content of each block
|
||||
void Allocate_Block(int size, int *count_Equ, int count_Block, BlockType type, BlockSimulationType SimType, Model_Block *ModelBlock, t_etype &Equation_Type, int recurs_Size, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM);
|
||||
//! Finds a matching between equations and endogenous variables
|
||||
bool Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, bool verbose, bool *IM0, vector<int> &Index_Var_IM) const;
|
||||
bool Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, int verbose, bool *IM0, vector<int> &Index_Var_IM) const;
|
||||
//! Decomposes into recurive blocks the non purely recursive equations and determines for each block the minimum feedback variables
|
||||
void Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_) const;
|
||||
void Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs) const;
|
||||
//! determines the type of each equation of the model (could be evaluated or need to be solved)
|
||||
t_etype Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM);
|
||||
t_etype Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, int mfs);
|
||||
//! Tries to merge the consecutive blocks in a single block and determine the type of each block: recursive, simultaneous, ...
|
||||
t_type Reduce_Blocks_and_type_determination(int prologue, int epilogue, vector<pair<int, int> > &blocks, vector<BinaryOpNode *> &equations, t_etype &Equation_Type, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM);
|
||||
//! Compute for each variable its maximum lead and lag in its block
|
||||
|
@ -121,8 +121,8 @@ public:
|
|||
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> get_Derivatives(Model_Block *ModelBlock, int Blck);
|
||||
|
||||
|
||||
void Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives);
|
||||
void Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool* IM_0 , jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives);
|
||||
void Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, int mfs, double cutoff);
|
||||
void Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool* IM_0 , jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, bool dynamic, int mfs, double cutoff);
|
||||
vector<int> Index_Equ_IM;
|
||||
vector<int> Index_Var_IM;
|
||||
int prologue, epilogue;
|
||||
|
@ -187,11 +187,10 @@ public:
|
|||
};
|
||||
inline static std::string c_Equation_Type(int type)
|
||||
{
|
||||
char c_Equation_Type[5][13]=
|
||||
char c_Equation_Type[4][13]=
|
||||
{
|
||||
"E_UNKNOWN ",
|
||||
"E_EVALUATE ",
|
||||
//"E_EVALUATE_R",
|
||||
"E_EVALUATE_S",
|
||||
"E_SOLVE "
|
||||
};
|
||||
|
|
|
@ -40,6 +40,15 @@ const char FDIMT=16;
|
|||
const char FEND=17;
|
||||
const char FOK=18;
|
||||
const char FENDEQU=19;
|
||||
const char FLDSV=20;
|
||||
const char FSTPSV=21;
|
||||
const char FLDSU=22;
|
||||
const char FSTPSU=23;
|
||||
const char FLDST=24;
|
||||
const char FSTPST=25;
|
||||
const char FDIMST=26;
|
||||
|
||||
|
||||
|
||||
enum BlockType
|
||||
{
|
||||
|
@ -53,7 +62,6 @@ enum EquationType
|
|||
{
|
||||
E_UNKNOWN, //!< Unknown equation type
|
||||
E_EVALUATE, //!< Simple evaluation, normalized variable on left-hand side
|
||||
//E_EVALUATE_R, //!< Simple evaluation, normalized variable on right-hand side
|
||||
E_EVALUATE_S, //!< Simple evaluation, normalize using the first order derivative
|
||||
E_SOLVE //!< No simple evaluation of the equation, it has to be solved
|
||||
};
|
||||
|
|
|
@ -27,8 +27,8 @@ using namespace std;
|
|||
#include "ComputingTasks.hh"
|
||||
#include "Statement.hh"
|
||||
|
||||
SteadyStatement::SteadyStatement(const OptionsList &options_list_arg) :
|
||||
options_list(options_list_arg)
|
||||
SteadyStatement::SteadyStatement(const OptionsList &options_list_arg, StaticDllModel::mode_t mode_arg) :
|
||||
options_list(options_list_arg), mode(mode_arg)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,17 @@ SteadyStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
{
|
||||
if (options_list.num_options.find("block_mfs") != options_list.num_options.end())
|
||||
mod_file_struct.steady_block_mfs_option = true;
|
||||
else if (options_list.num_options.find("block_mfs_dll") != options_list.num_options.end())
|
||||
mod_file_struct.steady_block_mfs_dll_option = true;
|
||||
}
|
||||
|
||||
void
|
||||
SteadyStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
options_list.writeOutput(output);
|
||||
/*if (mode == StaticDllModel::eSparseDLLMode)
|
||||
output << "oo_.steady_state=simulate('steady');" << endl;
|
||||
else*/
|
||||
output << "steady;\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,9 @@ class SteadyStatement : public Statement
|
|||
{
|
||||
private:
|
||||
const OptionsList options_list;
|
||||
const StaticDllModel::mode_t mode;
|
||||
public:
|
||||
SteadyStatement(const OptionsList &options_list_arg);
|
||||
SteadyStatement(const OptionsList &options_list_arg, StaticDllModel::mode_t mode_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
|
661
DynamicModel.cc
661
DynamicModel.cc
File diff suppressed because it is too large
Load Diff
|
@ -25,6 +25,7 @@ using namespace std;
|
|||
#include <fstream>
|
||||
|
||||
#include "StaticModel.hh"
|
||||
#include "StaticDllModel.hh"
|
||||
#include "BlockTriangular.hh"
|
||||
|
||||
//! Stores a dynamic model
|
||||
|
@ -100,7 +101,7 @@ private:
|
|||
- computes the jacobian for the model w.r. to contemporaneous variables
|
||||
- removes edges of the incidence matrix when derivative w.r. to the corresponding variable is too close to zero (below the cutoff)
|
||||
*/
|
||||
void evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m);
|
||||
void evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m, bool dynamic);
|
||||
void BlockLinear(Model_Block *ModelBlock);
|
||||
string reform(string name) const;
|
||||
map_idx_type map_idx;
|
||||
|
@ -152,8 +153,15 @@ public:
|
|||
virtual NodeID AddVariable(const string &name, int lag = 0);
|
||||
//! Absolute value under which a number is considered to be zero
|
||||
double cutoff;
|
||||
//! The weight of the Markowitz criteria to determine the pivot in the linear solver (simul_NG1 from simulate.cc)
|
||||
//! The weight of the Markowitz criteria to determine the pivot in the linear solver (simul_NG1 and simul_NG from simulate.cc)
|
||||
double markowitz;
|
||||
//! Compute the minimum feedback set in the dynamic model:
|
||||
/*! 0 : all endogenous variables are considered as feedback variables
|
||||
1 : the variables belonging to non normalized equation are considered as feedback variables
|
||||
2 : the variables belonging to a non linear equation are considered as feedback variables
|
||||
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
|
||||
default value = 0 */
|
||||
int mfs;
|
||||
//! the file containing the model and the derivatives code
|
||||
ofstream code_file;
|
||||
//! Execute computations (variable sorting + derivation)
|
||||
|
@ -184,6 +192,8 @@ public:
|
|||
/*! It assumes that the static model given in argument has just been allocated */
|
||||
void toStatic(StaticModel &static_model) const;
|
||||
|
||||
void toStaticDll(StaticDllModel &static_model) const;
|
||||
|
||||
//! Writes LaTeX file with the equations of the dynamic model
|
||||
void writeLatexFile(const string &basename) const;
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class ParsingDriver;
|
|||
%}
|
||||
|
||||
%token AR AUTOCORR
|
||||
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK_MFS
|
||||
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK_MFS BLOCK_MFS_DLL
|
||||
%token BVAR_DENSITY BVAR_FORECAST
|
||||
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
|
||||
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
|
||||
|
@ -106,7 +106,7 @@ class ParsingDriver;
|
|||
%token KALMAN_ALGO KALMAN_TOL
|
||||
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LU
|
||||
%token MARKOWITZ MARGINAL_DENSITY MAX
|
||||
%token METHOD MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
|
||||
%token METHOD MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
|
||||
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS
|
||||
%token MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER
|
||||
%token <string_val> NAME
|
||||
|
@ -449,6 +449,7 @@ model_sparse_options_list : model_sparse_options_list COMMA model_sparse_options
|
|||
|
||||
model_sparse_options : o_cutoff
|
||||
| o_markowitz
|
||||
| o_mfs
|
||||
;
|
||||
|
||||
model : MODEL ';' { driver.begin_model(); }
|
||||
|
@ -641,6 +642,10 @@ steady_options : o_solve_algo
|
|||
| o_homotopy_mode
|
||||
| o_homotopy_steps
|
||||
| o_block_mfs
|
||||
| o_block_mfs_dll
|
||||
| o_cutoff
|
||||
| o_markowitz
|
||||
| o_mfs
|
||||
;
|
||||
|
||||
check : CHECK ';'
|
||||
|
@ -1496,6 +1501,7 @@ o_method : METHOD EQUAL INT_NUMBER { driver.option_num("simulation_method",$3);}
|
|||
| METHOD EQUAL GMRES { driver.option_num("simulation_method", "2"); }
|
||||
| METHOD EQUAL BICGSTAB { driver.option_num("simulation_method", "3"); };
|
||||
o_markowitz : MARKOWITZ EQUAL number { driver.option_num("markowitz", $3); };
|
||||
o_mfs : MFS EQUAL number { driver.option_num("mfs", $3); };
|
||||
o_simul : SIMUL { driver.option_num("simul", "1"); };
|
||||
o_simul_seed : SIMUL_SEED EQUAL INT_NUMBER { driver.option_num("simul_seed", $3); } ;
|
||||
o_qz_criterium : QZ_CRITERIUM EQUAL number { driver.option_num("qz_criterium", $3); };
|
||||
|
@ -1602,6 +1608,8 @@ o_gsa_trans_ident : TRANS_IDENT EQUAL INT_NUMBER { driver.option_num("trans_iden
|
|||
o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); };
|
||||
o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); };
|
||||
o_block_mfs : BLOCK_MFS { driver.option_num("block_mfs", "1"); }
|
||||
o_block_mfs_dll : BLOCK_MFS_DLL { driver.option_num("block_mfs_dll", "1"); }
|
||||
|
||||
o_parameters : PARAMETERS EQUAL symbol {driver.option_str("parameters",$3);};
|
||||
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
|
||||
o_labels : LABELS EQUAL '(' symbol_list ')' { driver.option_symbol_list("labels"); };
|
||||
|
|
|
@ -210,6 +210,7 @@ int sigma_e = 0;
|
|||
<DYNARE_STATEMENT>periods {return token::PERIODS;}
|
||||
<DYNARE_STATEMENT>cutoff {return token::CUTOFF;}
|
||||
<DYNARE_STATEMENT>markowitz {return token::MARKOWITZ;}
|
||||
<DYNARE_STATEMENT>mfs {return token::MFS;}
|
||||
<DYNARE_STATEMENT>marginal_density {return token::MARGINAL_DENSITY;}
|
||||
<DYNARE_STATEMENT>laplace {return token::LAPLACE;}
|
||||
<DYNARE_STATEMENT>modifiedharmonicmean {return token::MODIFIEDHARMONICMEAN;}
|
||||
|
@ -220,6 +221,8 @@ int sigma_e = 0;
|
|||
<DYNARE_STATEMENT>diffuse_filter {return token::DIFFUSE_FILTER;}
|
||||
<DYNARE_STATEMENT>plot_priors {return token::PLOT_PRIORS;}
|
||||
<DYNARE_STATEMENT>block_mfs {return token::BLOCK_MFS;}
|
||||
<DYNARE_STATEMENT>block_mfs_dll {return token::BLOCK_MFS_DLL;}
|
||||
|
||||
<DYNARE_STATEMENT>freq {return token::FREQ;}
|
||||
<DYNARE_STATEMENT>initial_year {return token::INITIAL_YEAR;}
|
||||
<DYNARE_STATEMENT>initial_subperiod {return token::INITIAL_SUBPERIOD;}
|
||||
|
@ -302,6 +305,7 @@ int sigma_e = 0;
|
|||
<DYNARE_BLOCK>periods {return token::PERIODS;}
|
||||
<DYNARE_BLOCK>cutoff {return token::CUTOFF;}
|
||||
<DYNARE_BLOCK>markowitz {return token::MARKOWITZ;}
|
||||
<DYNARE_BLOCK>mfs {return token::MFS;}
|
||||
<DYNARE_BLOCK>gamma_pdf {return token::GAMMA_PDF;}
|
||||
<DYNARE_BLOCK>beta_pdf {return token::BETA_PDF;}
|
||||
<DYNARE_BLOCK>normal_pdf {return token::NORMAL_PDF;}
|
||||
|
|
490
ExprNode.cc
490
ExprNode.cc
|
@ -131,6 +131,13 @@ ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
|||
}
|
||||
|
||||
|
||||
pair<int, NodeID >
|
||||
ExprNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
return(make_pair(0, (NodeID)NULL));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExprNode::writeOutput(ostream &output)
|
||||
{
|
||||
|
@ -184,13 +191,10 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
|||
}
|
||||
|
||||
void
|
||||
NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||
NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
||||
{
|
||||
CompileCode.write(&FLDC, sizeof(FLDC));
|
||||
double vard = datatree.num_constants.getDouble(id);
|
||||
#ifdef DEBUGC
|
||||
cout << "FLDC " << vard << "\n";
|
||||
#endif
|
||||
CompileCode.write(reinterpret_cast<char *>(&vard),sizeof(vard));
|
||||
}
|
||||
|
||||
|
@ -199,10 +203,10 @@ NumConstNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result
|
|||
{
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
NumConstNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
pair<int, NodeID >
|
||||
NumConstNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
return(make_pair(false, datatree.AddNumConstant(datatree.num_constants.get(id))));
|
||||
return(make_pair(0, datatree.AddNumConstant(datatree.num_constants.get(id))));
|
||||
}
|
||||
|
||||
NodeID
|
||||
|
@ -295,9 +299,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
const temporary_terms_type &temporary_terms) const
|
||||
{
|
||||
// If node is a temporary term
|
||||
#ifdef DEBUGC
|
||||
cout << "write_ouput Variable output_type=" << output_type << "\n";
|
||||
#endif
|
||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
|
@ -464,19 +465,22 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
|||
}
|
||||
|
||||
void
|
||||
VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||
VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
||||
{
|
||||
int i, lagl;
|
||||
#ifdef DEBUGC
|
||||
cout << "output_type=" << output_type << "\n";
|
||||
#endif
|
||||
if (!lhs_rhs)
|
||||
{
|
||||
CompileCode.write(&FLDV, sizeof(FLDV));
|
||||
if(dynamic)
|
||||
CompileCode.write(&FLDV, sizeof(FLDV));
|
||||
else
|
||||
CompileCode.write(&FLDSV, sizeof(FLDSV));
|
||||
}
|
||||
else
|
||||
{
|
||||
CompileCode.write(&FSTPV, sizeof(FSTPV));
|
||||
if(dynamic)
|
||||
CompileCode.write(&FSTPV, sizeof(FSTPV));
|
||||
else
|
||||
CompileCode.write(&FSTPSV, sizeof(FSTPSV));
|
||||
}
|
||||
char typel=(char)type;
|
||||
CompileCode.write(&typel, sizeof(typel));
|
||||
|
@ -487,35 +491,41 @@ VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
|||
//cout << "Parameter=" << tsid << "\n";
|
||||
i = tsid;
|
||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||
#ifdef DEBUGC
|
||||
cout << "FLD Param[ " << i << ", symb_id=" << symb_id << "]\n";
|
||||
#endif
|
||||
break;
|
||||
case eEndogenous :
|
||||
//cout << "Endogenous=" << symb_id << "\n";
|
||||
i = tsid;//symb_id;
|
||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||
lagl=lag;
|
||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||
if(dynamic)
|
||||
{
|
||||
lagl=lag;
|
||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||
}
|
||||
break;
|
||||
case eExogenous :
|
||||
//cout << "Exogenous=" << tsid << "\n";
|
||||
i = tsid;
|
||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||
lagl=lag;
|
||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||
if(dynamic)
|
||||
{
|
||||
lagl=lag;
|
||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||
}
|
||||
break;
|
||||
case eExogenousDet:
|
||||
i = tsid + datatree.symbol_table.exo_nbr();
|
||||
//cout << "ExogenousDet=" << i << "\n";
|
||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||
lagl=lag;
|
||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||
if(dynamic)
|
||||
{
|
||||
lagl=lag;
|
||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||
}
|
||||
break;
|
||||
case eModelLocalVariable:
|
||||
case eModFileLocalVariable:
|
||||
//cout << "eModelLocalVariable=" << symb_id << "\n";
|
||||
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
break;
|
||||
case eUnknownFunction:
|
||||
cerr << "Impossible case: eUnknownFuncion" << endl;
|
||||
|
@ -545,22 +555,22 @@ VariableNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result
|
|||
datatree.local_variables_table[symb_id]->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
pair<int, NodeID>
|
||||
VariableNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
if (type ==eEndogenous)
|
||||
{
|
||||
if (datatree.symbol_table.getTypeSpecificID(symb_id)==var_endo && lag==0)
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
else
|
||||
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag)));
|
||||
return(make_pair(0, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type == eParameter)
|
||||
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), 0)));
|
||||
return(make_pair(0, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), 0) ));
|
||||
else
|
||||
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag)));
|
||||
return(make_pair(0, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag) ));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -581,9 +591,19 @@ VariableNode::getChainRuleDerivative(int deriv_id_arg, const map<int, NodeID> &r
|
|||
map<int, NodeID>::const_iterator it = recursive_variables.find(deriv_id);
|
||||
if (it != recursive_variables.end())
|
||||
{
|
||||
map<int, NodeID> recursive_vars2(recursive_variables);
|
||||
recursive_vars2.erase(it->first);
|
||||
return datatree.AddUMinus(it->second->getChainRuleDerivative(deriv_id_arg, recursive_vars2));
|
||||
map<int, NodeID>::const_iterator it2 = derivatives.find(deriv_id_arg);
|
||||
if (it2 != derivatives.end())
|
||||
return it2->second;
|
||||
else
|
||||
{
|
||||
map<int, NodeID> recursive_vars2(recursive_variables);
|
||||
recursive_vars2.erase(it->first);
|
||||
//NodeID c = datatree.AddNumConstant("1");
|
||||
NodeID d = datatree.AddUMinus(it->second->getChainRuleDerivative(deriv_id_arg, recursive_vars2));
|
||||
//d = datatree.AddTimes(c, d);
|
||||
derivatives[deriv_id_arg] = d;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
else
|
||||
return datatree.Zero;
|
||||
|
@ -997,17 +1017,20 @@ UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcept
|
|||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||
UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
||||
{
|
||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
CompileCode.write(&FLDT, sizeof(FLDT));
|
||||
if(dynamic)
|
||||
CompileCode.write(&FLDT, sizeof(FLDT));
|
||||
else
|
||||
CompileCode.write(&FLDST, sizeof(FLDST));
|
||||
int var=map_idx[idx];
|
||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||
return;
|
||||
}
|
||||
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
CompileCode.write(&FUNARY, sizeof(FUNARY));
|
||||
UnaryOpcode op_codel=op_code;
|
||||
CompileCode.write(reinterpret_cast<char *>(&op_codel), sizeof(op_codel));
|
||||
|
@ -1019,53 +1042,101 @@ UnaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result)
|
|||
arg->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
UnaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
pair<int, NodeID>
|
||||
UnaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
pair<bool, NodeID> res = arg->normalizeLinearInEndoEquation(var_endo, Derivative);
|
||||
bool is_endogenous_present = res.first;
|
||||
pair<bool, NodeID > res = arg->normalizeEquation(var_endo, List_of_Op_RHS);
|
||||
int is_endogenous_present = res.first;
|
||||
NodeID New_NodeID = res.second;
|
||||
if (!is_endogenous_present)
|
||||
/*if(res.second.second)*/
|
||||
if(is_endogenous_present==2)
|
||||
return(make_pair(2, (NodeID)NULL));
|
||||
else if (is_endogenous_present)
|
||||
{
|
||||
switch (op_code)
|
||||
{
|
||||
case oUminus:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddUMinus(New_NodeID)));
|
||||
List_of_Op_RHS.push_back(make_pair(oUminus, make_pair((NodeID)NULL, (NodeID)NULL)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oExp:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddExp(New_NodeID)));
|
||||
List_of_Op_RHS.push_back(make_pair(oLog, make_pair((NodeID)NULL, (NodeID)NULL)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oLog:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddLog(New_NodeID)));
|
||||
List_of_Op_RHS.push_back(make_pair(oExp, make_pair((NodeID)NULL, (NodeID)NULL)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oLog10:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddLog10(New_NodeID)));
|
||||
List_of_Op_RHS.push_back(make_pair(oPower, make_pair((NodeID)NULL, datatree.AddNumConstant("10"))));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oCos:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddCos(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oSin:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddSin(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oTan:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddTan(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oAcos:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddAcos(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oAsin:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddAsin(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oAtan:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddAtan(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oCosh:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddCosh(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oSinh:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddSinh(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oTanh:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddTanh(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oAcosh:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddAcosh(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oAsinh:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddAsinh(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oAtanh:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddAtanh(New_NodeID)));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
case oSqrt:
|
||||
return(make_pair(false, /*tmp_*/datatree.AddSqrt(New_NodeID)));
|
||||
List_of_Op_RHS.push_back(make_pair(oPower, make_pair((NodeID)NULL, datatree.AddNumConstant("2"))));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
}
|
||||
}
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
else
|
||||
{
|
||||
switch (op_code)
|
||||
{
|
||||
case oUminus:
|
||||
return(make_pair(0, datatree.AddUMinus(New_NodeID)));
|
||||
case oExp:
|
||||
return(make_pair(0, datatree.AddExp(New_NodeID)));
|
||||
case oLog:
|
||||
return(make_pair(0, datatree.AddLog(New_NodeID)));
|
||||
case oLog10:
|
||||
return(make_pair(0, datatree.AddLog10(New_NodeID)));
|
||||
case oCos:
|
||||
return(make_pair(0, datatree.AddCos(New_NodeID)));
|
||||
case oSin:
|
||||
return(make_pair(0, datatree.AddSin(New_NodeID)));
|
||||
case oTan:
|
||||
return(make_pair(0, datatree.AddTan(New_NodeID)));
|
||||
case oAcos:
|
||||
return(make_pair(0, datatree.AddAcos(New_NodeID)));
|
||||
case oAsin:
|
||||
return(make_pair(0, datatree.AddAsin(New_NodeID)));
|
||||
case oAtan:
|
||||
return(make_pair(0, datatree.AddAtan(New_NodeID)));
|
||||
case oCosh:
|
||||
return(make_pair(0, datatree.AddCosh(New_NodeID)));
|
||||
case oSinh:
|
||||
return(make_pair(0, datatree.AddSinh(New_NodeID)));
|
||||
case oTanh:
|
||||
return(make_pair(0, datatree.AddTanh(New_NodeID)));
|
||||
case oAcosh:
|
||||
return(make_pair(0, datatree.AddAcosh(New_NodeID)));
|
||||
case oAsinh:
|
||||
return(make_pair(0, datatree.AddAsinh(New_NodeID)));
|
||||
case oAtanh:
|
||||
return(make_pair(0, datatree.AddAtanh(New_NodeID)));
|
||||
case oSqrt:
|
||||
return(make_pair(0, datatree.AddSqrt(New_NodeID)));
|
||||
}
|
||||
}
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1435,19 +1506,22 @@ BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
|||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||
BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
CompileCode.write(&FLDT, sizeof(FLDT));
|
||||
if(dynamic)
|
||||
CompileCode.write(&FLDT, sizeof(FLDT));
|
||||
else
|
||||
CompileCode.write(&FLDST, sizeof(FLDST));
|
||||
int var=map_idx[idx];
|
||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||
return;
|
||||
}
|
||||
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
CompileCode.write(&FBINARY, sizeof(FBINARY));
|
||||
BinaryOpcode op_codel=op_code;
|
||||
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
|
||||
|
@ -1636,129 +1710,272 @@ BinaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result
|
|||
arg2->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
NodeID
|
||||
BinaryOpNode::Compute_RHS(NodeID arg1, NodeID arg2, int op, int op_type) const
|
||||
{
|
||||
temporary_terms_type temp;
|
||||
switch(op_type)
|
||||
{
|
||||
case 0: /*Unary Operator*/
|
||||
switch(op)
|
||||
{
|
||||
case oUminus:
|
||||
return(datatree.AddUMinus(arg1));
|
||||
break;
|
||||
case oExp:
|
||||
return(datatree.AddExp(arg1));
|
||||
break;
|
||||
case oLog:
|
||||
return(datatree.AddLog(arg1));
|
||||
break;
|
||||
case oLog10:
|
||||
return(datatree.AddLog10(arg1));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1: /*Binary Operator*/
|
||||
switch(op)
|
||||
{
|
||||
case oPlus:
|
||||
return(datatree.AddPlus(arg1, arg2));
|
||||
break;
|
||||
case oMinus:
|
||||
return(datatree.AddMinus(arg1, arg2));
|
||||
break;
|
||||
case oTimes:
|
||||
return(datatree.AddTimes(arg1, arg2));
|
||||
break;
|
||||
case oDivide:
|
||||
return(datatree.AddDivide(arg1, arg2));
|
||||
break;
|
||||
case oPower:
|
||||
return(datatree.AddPower(arg1, arg2));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return((NodeID)NULL);
|
||||
}
|
||||
|
||||
pair<int, NodeID>
|
||||
BinaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
pair<bool, NodeID> res = arg1->normalizeLinearInEndoEquation(var_endo, Derivative);
|
||||
bool is_endogenous_present_1 = res.first;
|
||||
NodeID NodeID_1 = res.second;
|
||||
res = arg2->normalizeLinearInEndoEquation(var_endo, Derivative);
|
||||
bool is_endogenous_present_2 = res.first;
|
||||
NodeID NodeID_2 = res.second;
|
||||
vector<pair<int, pair<NodeID, NodeID> > > List_of_Op_RHS1, List_of_Op_RHS2;
|
||||
int is_endogenous_present_1, is_endogenous_present_2;
|
||||
pair<int, NodeID> res;
|
||||
NodeID NodeID_1, NodeID_2;
|
||||
res = arg1->normalizeEquation(var_endo, List_of_Op_RHS1);
|
||||
is_endogenous_present_1 = res.first;
|
||||
NodeID_1 = res.second;
|
||||
|
||||
res = arg2->normalizeEquation(var_endo, List_of_Op_RHS2);
|
||||
is_endogenous_present_2 = res.first;
|
||||
NodeID_2 = res.second;
|
||||
if(is_endogenous_present_1==2 || is_endogenous_present_2==2)
|
||||
return(make_pair(2,(NodeID)NULL));
|
||||
else if(is_endogenous_present_1 && is_endogenous_present_2)
|
||||
return(make_pair(2,(NodeID)NULL));
|
||||
else if(is_endogenous_present_1)
|
||||
{
|
||||
if(op_code==oEqual)
|
||||
{
|
||||
pair<int, pair<NodeID, NodeID> > it;
|
||||
int oo=List_of_Op_RHS1.size();
|
||||
for(int i=0;i<oo;i++)
|
||||
{
|
||||
it = List_of_Op_RHS1.back();
|
||||
List_of_Op_RHS1.pop_back();
|
||||
if(it.second.first && !it.second.second) /*Binary operator*/
|
||||
NodeID_2 = Compute_RHS(NodeID_2, (BinaryOpNode*)it.second.first, it.first, 1);
|
||||
else if(it.second.second && !it.second.first) /*Binary operator*/
|
||||
NodeID_2 = Compute_RHS(it.second.second, NodeID_2, it.first, 1);
|
||||
else if(it.second.second && it.second.first) /*Binary operator*/
|
||||
NodeID_2 = Compute_RHS(it.second.first, it.second.second, it.first, 1);
|
||||
else /*Unary operator*/
|
||||
NodeID_2 = Compute_RHS((UnaryOpNode*)NodeID_2, (UnaryOpNode*)it.second.first, it.first, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
List_of_Op_RHS = List_of_Op_RHS1;
|
||||
}
|
||||
else if(is_endogenous_present_2)
|
||||
{
|
||||
if(op_code==oEqual)
|
||||
{
|
||||
int oo=List_of_Op_RHS2.size();
|
||||
for(int i=0;i<oo;i++)
|
||||
{
|
||||
pair<int, pair<NodeID, NodeID> > it;
|
||||
it = List_of_Op_RHS2.back();
|
||||
List_of_Op_RHS2.pop_back();
|
||||
if(it.second.first && !it.second.second) /*Binary operator*/
|
||||
NodeID_1 = Compute_RHS((BinaryOpNode*)NodeID_1, (BinaryOpNode*)it.second.first, it.first, 1);
|
||||
else if(it.second.second && !it.second.first) /*Binary operator*/
|
||||
NodeID_1 = Compute_RHS((BinaryOpNode*)it.second.second, (BinaryOpNode*)NodeID_1, it.first, 1);
|
||||
else if(it.second.second && it.second.first) /*Binary operator*/
|
||||
NodeID_1 = Compute_RHS(it.second.first, it.second.second, it.first, 1);
|
||||
else
|
||||
NodeID_1 = Compute_RHS((UnaryOpNode*)NodeID_1, (UnaryOpNode*)it.second.first, it.first, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
List_of_Op_RHS =List_of_Op_RHS2;
|
||||
}
|
||||
switch (op_code)
|
||||
{
|
||||
case oPlus:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddPlus(NodeID_1, NodeID_2)));
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(datatree.AddPlus(NodeID_1, NodeID_2), (NodeID)NULL)));
|
||||
return(make_pair(0, datatree.AddPlus(NodeID_1, NodeID_2)));
|
||||
}
|
||||
else if (is_endogenous_present_1 && is_endogenous_present_2)
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
else if (!is_endogenous_present_1 && is_endogenous_present_2)
|
||||
return(make_pair(false, NodeID_1));
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(NodeID_1, (NodeID)NULL)));
|
||||
return(make_pair(1, NodeID_1));
|
||||
}
|
||||
else if (is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, NodeID_2));
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(NodeID_2, (NodeID)NULL) ));
|
||||
return(make_pair(1, NodeID_2));
|
||||
}
|
||||
break;
|
||||
case oMinus:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddMinus(NodeID_1, NodeID_2)));
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(datatree.AddMinus(NodeID_1, NodeID_2), (NodeID)NULL) ));
|
||||
return(make_pair(0, datatree.AddMinus(NodeID_1, NodeID_2)));
|
||||
}
|
||||
else if (is_endogenous_present_1 && is_endogenous_present_2)
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
else if (!is_endogenous_present_1 && is_endogenous_present_2)
|
||||
return(make_pair(false, NodeID_1));
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oUminus, make_pair((NodeID)NULL, (NodeID)NULL)));
|
||||
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(NodeID_1, (NodeID)NULL) ));
|
||||
return(make_pair(1, NodeID_1));
|
||||
}
|
||||
else if (is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddUMinus(NodeID_2)));
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oPlus, make_pair(NodeID_2, (NodeID) NULL) ));
|
||||
return(make_pair(1, datatree.AddUMinus(NodeID_2)));
|
||||
}
|
||||
break;
|
||||
case oTimes:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddTimes(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddTimes(NodeID_1, NodeID_2)));
|
||||
else if(!is_endogenous_present_1 && is_endogenous_present_2)
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oDivide, make_pair(NodeID_1, (NodeID)NULL) ));
|
||||
return(make_pair(1, NodeID_1));
|
||||
}
|
||||
else if(is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oDivide, make_pair(NodeID_2, (NodeID)NULL) ));
|
||||
return(make_pair(1, NodeID_2));
|
||||
}
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
break;
|
||||
case oDivide:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, datatree.AddDivide(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddDivide(NodeID_1, NodeID_2)));
|
||||
else if(!is_endogenous_present_1 && is_endogenous_present_2)
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oDivide, make_pair((NodeID)NULL, NodeID_1) ));
|
||||
return(make_pair(1, NodeID_1));
|
||||
}
|
||||
else if(is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oTimes, make_pair(NodeID_2, (NodeID)NULL) ));
|
||||
return(make_pair(1, NodeID_2));
|
||||
}
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
break;
|
||||
case oPower:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, datatree.AddPower(NodeID_1, NodeID_2)));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(0, datatree.AddPower(NodeID_1, NodeID_2)));
|
||||
else if(is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
{
|
||||
List_of_Op_RHS.push_back(make_pair(oPower, make_pair(datatree.AddDivide( datatree.AddNumConstant("1"), NodeID_2), (NodeID)NULL) ));
|
||||
return(make_pair(1, (NodeID)NULL));
|
||||
}
|
||||
break;
|
||||
case oEqual:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
{
|
||||
if (Derivative!=datatree.One)
|
||||
return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddMinus(NodeID_2, NodeID_1), Derivative))) );
|
||||
else
|
||||
return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddMinus(NodeID_2, NodeID_1))) );
|
||||
return( make_pair(0,
|
||||
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddMinus(NodeID_2, NodeID_1))
|
||||
));
|
||||
}
|
||||
else if (is_endogenous_present_1 && is_endogenous_present_2)
|
||||
{
|
||||
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.Zero)));
|
||||
return(make_pair(0,
|
||||
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.Zero)
|
||||
));
|
||||
}
|
||||
else if (!is_endogenous_present_1 && is_endogenous_present_2)
|
||||
{
|
||||
if (Derivative!=datatree.One)
|
||||
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddUMinus(NodeID_1), Derivative))));
|
||||
else
|
||||
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddUMinus(NodeID_1))));
|
||||
return(make_pair(0,
|
||||
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), /*datatree.AddUMinus(NodeID_1)*/NodeID_1)
|
||||
));
|
||||
}
|
||||
else if (is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
{
|
||||
if (Derivative!=datatree.One)
|
||||
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(NodeID_2, Derivative))));
|
||||
else
|
||||
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), NodeID_2)));
|
||||
return(make_pair(0,
|
||||
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), NodeID_2)
|
||||
));
|
||||
}
|
||||
break;
|
||||
case oMax:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, datatree.AddMax(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddMax(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oMin:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, datatree.AddMin(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddMin(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oLess:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddLess(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddLess(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oGreater:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddGreater(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddGreater(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oLessEqual:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddLessEqual(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddLessEqual(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oGreaterEqual:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddGreaterEqual(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddGreaterEqual(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oEqualEqual:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddEqualEqual(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddEqualEqual(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
case oDifferent:
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddDifferent(NodeID_1, NodeID_2)));
|
||||
return(make_pair(0, datatree.AddDifferent(NodeID_1, NodeID_2) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
break;
|
||||
}
|
||||
// Suppress GCC warning
|
||||
|
@ -2023,20 +2240,23 @@ TrinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExce
|
|||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||
TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
CompileCode.write(&FLDT, sizeof(FLDT));
|
||||
if(dynamic)
|
||||
CompileCode.write(&FLDT, sizeof(FLDT));
|
||||
else
|
||||
CompileCode.write(&FLDST, sizeof(FLDST));
|
||||
int var=map_idx[idx];
|
||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||
return;
|
||||
}
|
||||
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
||||
CompileCode.write(&FBINARY, sizeof(FBINARY));
|
||||
TrinaryOpcode op_codel=op_code;
|
||||
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
|
||||
|
@ -2094,22 +2314,22 @@ TrinaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &resul
|
|||
arg3->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
TrinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
pair<int, NodeID>
|
||||
TrinaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
pair<bool, NodeID> res = arg1->normalizeLinearInEndoEquation(var_endo, Derivative);
|
||||
pair<int, NodeID> res = arg1->normalizeEquation(var_endo, List_of_Op_RHS);
|
||||
bool is_endogenous_present_1 = res.first;
|
||||
NodeID NodeID_1 = res.second;
|
||||
res = arg2->normalizeLinearInEndoEquation(var_endo, Derivative);
|
||||
res = arg2->normalizeEquation(var_endo, List_of_Op_RHS);
|
||||
bool is_endogenous_present_2 = res.first;
|
||||
NodeID NodeID_2 = res.second;
|
||||
res = arg3->normalizeLinearInEndoEquation(var_endo, Derivative);
|
||||
res = arg3->normalizeEquation(var_endo, List_of_Op_RHS);
|
||||
bool is_endogenous_present_3 = res.first;
|
||||
NodeID NodeID_3 = res.second;
|
||||
if (!is_endogenous_present_1 && !is_endogenous_present_2 && !is_endogenous_present_3)
|
||||
return(make_pair(false, /*tmp_*/datatree.AddNormcdf(NodeID_1, NodeID_2, NodeID_3)));
|
||||
return(make_pair(0, datatree.AddNormcdf(NodeID_1, NodeID_2, NodeID_3) ));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
}
|
||||
|
||||
NodeID
|
||||
|
@ -2226,14 +2446,14 @@ UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (Ev
|
|||
}
|
||||
|
||||
void
|
||||
UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||
UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
||||
{
|
||||
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
UnknownFunctionNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
pair<int, NodeID>
|
||||
UnknownFunctionNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
|
||||
{
|
||||
vector<pair<bool, NodeID> > V_arguments;
|
||||
vector<NodeID> V_NodeID;
|
||||
|
@ -2241,14 +2461,14 @@ UnknownFunctionNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivati
|
|||
for (vector<NodeID>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
{
|
||||
V_arguments.push_back((*it)->normalizeLinearInEndoEquation(var_endo, Derivative));
|
||||
V_arguments.push_back((*it)->normalizeEquation(var_endo, List_of_Op_RHS));
|
||||
present = present || V_arguments[V_arguments.size()-1].first;
|
||||
V_NodeID.push_back(V_arguments[V_arguments.size()-1].second);
|
||||
}
|
||||
if (!present)
|
||||
return(make_pair(false, datatree.AddUnknownFunction(datatree.symbol_table.getName(symb_id), V_NodeID)));
|
||||
return(make_pair(0, datatree.AddUnknownFunction(datatree.symbol_table.getName(symb_id), V_NodeID)));
|
||||
else
|
||||
return(make_pair(true, (NodeID)NULL));
|
||||
return(make_pair(1, (NodeID)NULL ));
|
||||
}
|
||||
|
||||
NodeID
|
||||
|
|
30
ExprNode.hh
30
ExprNode.hh
|
@ -94,6 +94,7 @@ class ExprNode
|
|||
{
|
||||
friend class DataTree;
|
||||
friend class DynamicModel;
|
||||
friend class StaticDllModel;
|
||||
friend class ExprNodeLess;
|
||||
friend class NumConstNode;
|
||||
friend class VariableNode;
|
||||
|
@ -200,7 +201,7 @@ public:
|
|||
};
|
||||
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const = 0;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const = 0;
|
||||
//! Creates a static version of this node
|
||||
/*!
|
||||
This method duplicates the current node by creating a similar node from which all leads/lags have been stripped,
|
||||
|
@ -208,7 +209,7 @@ public:
|
|||
*/
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const = 0;
|
||||
//! Try to normalize an equation linear in its endogenous variable
|
||||
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const = 0;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const = 0;
|
||||
};
|
||||
|
||||
//! Object used to compare two nodes (using their indexes)
|
||||
|
@ -234,9 +235,9 @@ public:
|
|||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||
};
|
||||
|
||||
|
@ -264,10 +265,10 @@ public:
|
|||
map_idx_type &map_idx) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
int get_symb_id() const { return symb_id; };
|
||||
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||
};
|
||||
|
||||
|
@ -296,13 +297,13 @@ public:
|
|||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
||||
//! Returns operand
|
||||
NodeID get_arg() const { return(arg); };
|
||||
//! Returns op code
|
||||
UnaryOpcode get_op_code() const { return(op_code); };
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||
};
|
||||
|
||||
|
@ -333,7 +334,8 @@ public:
|
|||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
static double eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
||||
virtual NodeID Compute_RHS(NodeID arg1, NodeID arg2, int op, int op_type) const;
|
||||
//! Returns first operand
|
||||
NodeID get_arg1() const { return(arg1); };
|
||||
//! Returns second operand
|
||||
|
@ -341,7 +343,7 @@ public:
|
|||
//! Returns op code
|
||||
BinaryOpcode get_op_code() const { return(op_code); };
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||
};
|
||||
|
||||
|
@ -373,9 +375,9 @@ public:
|
|||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||
};
|
||||
|
||||
|
@ -401,9 +403,9 @@ public:
|
|||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
|
||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ MAIN_OBJS = \
|
|||
ComputingTasks.o \
|
||||
ModelTree.o \
|
||||
StaticModel.o \
|
||||
StaticDllModel.o \
|
||||
DynamicModel.o \
|
||||
NumericalConstants.o \
|
||||
NumericalInitialization.o \
|
||||
|
|
|
@ -382,6 +382,7 @@ namespace MFS
|
|||
{
|
||||
bool something_has_been_done = true;
|
||||
int cut_ = 0;
|
||||
feed_back_vertices.clear();
|
||||
AdjacencyList_type G(G1);
|
||||
while (num_vertices(G) > 0)
|
||||
{
|
||||
|
|
24
ModFile.cc
24
ModFile.cc
|
@ -25,6 +25,7 @@
|
|||
|
||||
ModFile::ModFile() : expressions_tree(symbol_table, num_constants),
|
||||
static_model(symbol_table, num_constants),
|
||||
static_dll_model(symbol_table, num_constants),
|
||||
dynamic_model(symbol_table, num_constants),
|
||||
linear(false)
|
||||
{
|
||||
|
@ -143,9 +144,16 @@ ModFile::computingPass(bool no_tmp_terms)
|
|||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
// Compute static model and its derivatives
|
||||
dynamic_model.toStatic(static_model);
|
||||
static_model.computingPass(mod_file_struct.steady_block_mfs_option, false, no_tmp_terms);
|
||||
|
||||
if(mod_file_struct.steady_block_mfs_dll_option)
|
||||
{
|
||||
dynamic_model.toStaticDll(static_dll_model);
|
||||
static_dll_model.computingPass(global_eval_context, no_tmp_terms);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_model.toStatic(static_model);
|
||||
static_model.computingPass(mod_file_struct.steady_block_mfs_option, false, no_tmp_terms);
|
||||
}
|
||||
// Set things to compute for dynamic model
|
||||
|
||||
if (mod_file_struct.simul_present)
|
||||
|
@ -228,7 +236,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
|||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
dynamic_model.writeOutput(mOutputFile, basename);
|
||||
static_model.writeOutput(mOutputFile);
|
||||
if(mod_file_struct.steady_block_mfs_dll_option)
|
||||
static_dll_model.writeOutput(mOutputFile, basename);
|
||||
else
|
||||
static_model.writeOutput(mOutputFile);
|
||||
}
|
||||
|
||||
// Print statements
|
||||
|
@ -248,7 +259,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
|||
// Create static and dynamic files
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
static_model.writeStaticFile(basename);
|
||||
if(mod_file_struct.steady_block_mfs_dll_option)
|
||||
static_dll_model.writeStaticFile(basename);
|
||||
else
|
||||
static_model.writeStaticFile(basename);
|
||||
dynamic_model.writeDynamicFile(basename);
|
||||
dynamic_model.writeParamsDerivativesFile(basename);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ using namespace std;
|
|||
#include "NumericalConstants.hh"
|
||||
#include "NumericalInitialization.hh"
|
||||
#include "StaticModel.hh"
|
||||
#include "StaticDllModel.hh"
|
||||
#include "DynamicModel.hh"
|
||||
#include "Statement.hh"
|
||||
|
||||
|
@ -46,6 +47,8 @@ public:
|
|||
DataTree expressions_tree;
|
||||
//! Static model
|
||||
StaticModel static_model;
|
||||
//! Static Dll model
|
||||
StaticDllModel static_dll_model;
|
||||
//! Dynamic model
|
||||
DynamicModel dynamic_model;
|
||||
//! Option linear
|
||||
|
|
|
@ -586,7 +586,7 @@ ParsingDriver::add_to_row(NodeID v)
|
|||
void
|
||||
ParsingDriver::steady()
|
||||
{
|
||||
mod_file->addStatement(new SteadyStatement(options_list));
|
||||
mod_file->addStatement(new SteadyStatement(options_list, mod_file->static_dll_model.mode));
|
||||
options_list.clear();
|
||||
}
|
||||
|
||||
|
@ -620,7 +620,17 @@ ParsingDriver::option_num(const string &name_option, const string &opt)
|
|||
if ((name_option == "periods") && (mod_file->dynamic_model.mode == DynamicModel::eSparseDLLMode || mod_file->dynamic_model.mode == DynamicModel::eSparseMode))
|
||||
mod_file->dynamic_model.block_triangular.periods = atoi(opt.c_str());
|
||||
else if (name_option == "cutoff")
|
||||
mod_file->dynamic_model.cutoff = atof(opt.c_str());
|
||||
{
|
||||
mod_file->dynamic_model.cutoff = atof(opt.c_str());
|
||||
mod_file->static_dll_model.cutoff = atof(opt.c_str());
|
||||
}
|
||||
else if (name_option == "mfs")
|
||||
{
|
||||
mod_file->dynamic_model.mfs = atoi(opt.c_str());
|
||||
mod_file->static_dll_model.mfs = atoi(opt.c_str());
|
||||
}
|
||||
else if (name_option == "block_mfs_dll")
|
||||
mod_file->static_dll_model.mode = (StaticDllModel::mode_t)DynamicModel::eSparseDLLMode;
|
||||
|
||||
options_list.num_options[name_option] = opt;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ ModFileStructure::ModFileStructure() :
|
|||
bvar_density_present(false),
|
||||
bvar_forecast_present(false),
|
||||
identification_present(false),
|
||||
steady_block_mfs_option(false)
|
||||
steady_block_mfs_option(false),
|
||||
steady_block_mfs_dll_option(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
bool identification_present;
|
||||
//! Whether the option "block_mfs" is used on steady statement
|
||||
bool steady_block_mfs_option;
|
||||
//! Whether the option "block_mfs_dll" is used on steady statement
|
||||
bool steady_block_mfs_dll_option;
|
||||
};
|
||||
|
||||
class Statement
|
||||
|
|
Loading…
Reference in New Issue