Commit 5bbd779b authored by sebastien's avatar sebastien
Browse files

v4 parser:

* added planner_objective statement, which triggers the creation of filename_objective_static.m
* added computing pass
* added the possibility of writing the hessian in static output file



git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1126 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 0f9ed33f
...@@ -18,7 +18,7 @@ SteadyStatement::SteadyStatement(const OptionsList &options_list_arg) : ...@@ -18,7 +18,7 @@ SteadyStatement::SteadyStatement(const OptionsList &options_list_arg) :
} }
void void
SteadyStatement::writeOutput(ostream &output) const SteadyStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
output << "steady;\n"; output << "steady;\n";
...@@ -30,7 +30,7 @@ CheckStatement::CheckStatement(const OptionsList &options_list_arg) : ...@@ -30,7 +30,7 @@ CheckStatement::CheckStatement(const OptionsList &options_list_arg) :
} }
void void
CheckStatement::writeOutput(ostream &output) const CheckStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
output << "check;\n"; output << "check;\n";
...@@ -54,7 +54,7 @@ SimulStatement::checkPass(ModFileStructure &mod_file_struct) ...@@ -54,7 +54,7 @@ SimulStatement::checkPass(ModFileStructure &mod_file_struct)
} }
void void
SimulStatement::writeOutput(ostream &output) const SimulStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
output << "simul(oo_.dr);\n"; output << "simul(oo_.dr);\n";
...@@ -74,7 +74,7 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct) ...@@ -74,7 +74,7 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct)
} }
void void
StochSimulStatement::writeOutput(ostream &output) const StochSimulStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -95,7 +95,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct) ...@@ -95,7 +95,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct)
} }
void void
EstimationStatement::writeOutput(ostream &output) const EstimationStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -110,7 +110,7 @@ PriorAnalysisStatement::PriorAnalysisStatement(const TmpSymbolTable &tmp_symbol_ ...@@ -110,7 +110,7 @@ PriorAnalysisStatement::PriorAnalysisStatement(const TmpSymbolTable &tmp_symbol_
} }
void void
PriorAnalysisStatement::writeOutput(ostream &output) const PriorAnalysisStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -125,7 +125,7 @@ PosteriorAnalysisStatement::PosteriorAnalysisStatement(const TmpSymbolTable &tmp ...@@ -125,7 +125,7 @@ PosteriorAnalysisStatement::PosteriorAnalysisStatement(const TmpSymbolTable &tmp
} }
void void
PosteriorAnalysisStatement::writeOutput(ostream &output) const PosteriorAnalysisStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -140,7 +140,7 @@ RplotStatement::RplotStatement(const TmpSymbolTable &tmp_symbol_table_arg, ...@@ -140,7 +140,7 @@ RplotStatement::RplotStatement(const TmpSymbolTable &tmp_symbol_table_arg,
} }
void void
RplotStatement::writeOutput(ostream &output) const RplotStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -153,7 +153,7 @@ UnitRootVarsStatement::UnitRootVarsStatement(const TmpSymbolTable &tmp_symbol_ta ...@@ -153,7 +153,7 @@ UnitRootVarsStatement::UnitRootVarsStatement(const TmpSymbolTable &tmp_symbol_ta
} }
void void
UnitRootVarsStatement::writeOutput(ostream &output) const UnitRootVarsStatement::writeOutput(ostream &output, const string &basename) const
{ {
tmp_symbol_table.writeOutput("options_.unit_root_vars", output); tmp_symbol_table.writeOutput("options_.unit_root_vars", output);
} }
...@@ -163,7 +163,7 @@ PeriodsStatement::PeriodsStatement(int periods_arg) : periods(periods_arg) ...@@ -163,7 +163,7 @@ PeriodsStatement::PeriodsStatement(int periods_arg) : periods(periods_arg)
} }
void void
PeriodsStatement::writeOutput(ostream &output) const PeriodsStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << "options_.periods = " << periods << ";" << endl; output << "options_.periods = " << periods << ";" << endl;
output << "options_.simul = 1;" << endl; output << "options_.simul = 1;" << endl;
...@@ -178,7 +178,7 @@ DsampleStatement::DsampleStatement(int val1_arg, int val2_arg) : val1(val1_arg), ...@@ -178,7 +178,7 @@ DsampleStatement::DsampleStatement(int val1_arg, int val2_arg) : val1(val1_arg),
} }
void void
DsampleStatement::writeOutput(ostream &output) const DsampleStatement::writeOutput(ostream &output, const string &basename) const
{ {
if (val2 < 0) if (val2 < 0)
output << "options_.dsample = " << val1 << ";" << endl; output << "options_.dsample = " << val1 << ";" << endl;
...@@ -192,7 +192,7 @@ VarobsStatement::VarobsStatement(const TmpSymbolTable &tmp_symbol_table_arg) : ...@@ -192,7 +192,7 @@ VarobsStatement::VarobsStatement(const TmpSymbolTable &tmp_symbol_table_arg) :
} }
void void
VarobsStatement::writeOutput(ostream &output) const VarobsStatement::writeOutput(ostream &output, const string &basename) const
{ {
tmp_symbol_table.writeOutput("options_.varobs", output); tmp_symbol_table.writeOutput("options_.varobs", output);
} }
...@@ -205,7 +205,7 @@ EstimatedParamsStatement::EstimatedParamsStatement(const vector<EstimationParams ...@@ -205,7 +205,7 @@ EstimatedParamsStatement::EstimatedParamsStatement(const vector<EstimationParams
} }
void void
EstimatedParamsStatement::writeOutput(ostream &output) const EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << "global estim_params_\n"; output << "global estim_params_\n";
output << "var_list_ = [];\n"; output << "var_list_ = [];\n";
...@@ -262,7 +262,7 @@ EstimatedParamsInitStatement::EstimatedParamsInitStatement(const vector<Estimati ...@@ -262,7 +262,7 @@ EstimatedParamsInitStatement::EstimatedParamsInitStatement(const vector<Estimati
} }
void void
EstimatedParamsInitStatement::writeOutput(ostream &output) const EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename) const
{ {
vector<EstimationParams>::const_iterator it; vector<EstimationParams>::const_iterator it;
...@@ -312,7 +312,7 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector<Esti ...@@ -312,7 +312,7 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector<Esti
} }
void void
EstimatedParamsBoundsStatement::writeOutput(ostream &output) const EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename) const
{ {
vector<EstimationParams>::const_iterator it; vector<EstimationParams>::const_iterator it;
...@@ -367,7 +367,7 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_type ...@@ -367,7 +367,7 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_type
} }
void void
ObservationTrendsStatement::writeOutput(ostream &output) const ObservationTrendsStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << "options_.trend_coeff_ = {};" << endl; output << "options_.trend_coeff_ = {};" << endl;
...@@ -398,7 +398,7 @@ CalibVarStatement::CalibVarStatement(const calib_var_type &calib_var_arg, ...@@ -398,7 +398,7 @@ CalibVarStatement::CalibVarStatement(const calib_var_type &calib_var_arg,
} }
void void
CalibVarStatement::writeOutput(ostream &output) const CalibVarStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << interfaces::comment() << "\n" << interfaces::comment() << "CALIB_VAR \n" output << interfaces::comment() << "\n" << interfaces::comment() << "CALIB_VAR \n"
...@@ -495,7 +495,7 @@ CalibStatement::CalibStatement(int covar_arg) : covar(covar_arg) ...@@ -495,7 +495,7 @@ CalibStatement::CalibStatement(int covar_arg) : covar(covar_arg)
} }
void void
CalibStatement::writeOutput(ostream &output) const CalibStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << "M_.Sigma_e=calib(calib_var_index,calib_targets,calib_weights," << covar << ",Sigma_e_);\n"; output << "M_.Sigma_e=calib(calib_var_index,calib_targets,calib_weights," << covar << ",Sigma_e_);\n";
} }
...@@ -506,7 +506,7 @@ OsrParamsStatement::OsrParamsStatement(const TmpSymbolTable &tmp_symbol_table_ar ...@@ -506,7 +506,7 @@ OsrParamsStatement::OsrParamsStatement(const TmpSymbolTable &tmp_symbol_table_ar
} }
void void
OsrParamsStatement::writeOutput(ostream &output) const OsrParamsStatement::writeOutput(ostream &output, const string &basename) const
{ {
tmp_symbol_table.writeOutput("osr_params_", output); tmp_symbol_table.writeOutput("osr_params_", output);
} }
...@@ -525,7 +525,7 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct) ...@@ -525,7 +525,7 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct)
} }
void void
OsrStatement::writeOutput(ostream &output) const OsrStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -538,7 +538,7 @@ OlrInstStatement::OlrInstStatement(const TmpSymbolTable &tmp_symbol_table_arg) : ...@@ -538,7 +538,7 @@ OlrInstStatement::OlrInstStatement(const TmpSymbolTable &tmp_symbol_table_arg) :
} }
void void
OlrInstStatement::writeOutput(ostream &output) const OlrInstStatement::writeOutput(ostream &output, const string &basename) const
{ {
tmp_symbol_table.writeOutput("options_.olr_inst", output); tmp_symbol_table.writeOutput("options_.olr_inst", output);
} }
...@@ -558,7 +558,7 @@ OlrStatement::checkPass(ModFileStructure &mod_file_struct) ...@@ -558,7 +558,7 @@ OlrStatement::checkPass(ModFileStructure &mod_file_struct)
} }
void void
OlrStatement::writeOutput(ostream &output) const OlrStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
...@@ -578,7 +578,7 @@ OptimWeightsStatement::OptimWeightsStatement(const var_weights_type &var_weights ...@@ -578,7 +578,7 @@ OptimWeightsStatement::OptimWeightsStatement(const var_weights_type &var_weights
} }
void void
OptimWeightsStatement::writeOutput(ostream &output) const OptimWeightsStatement::writeOutput(ostream &output, const string &basename) const
{ {
output << interfaces::comment() << "OPTIM_WEIGHTS\n\n"; output << interfaces::comment() << "OPTIM_WEIGHTS\n\n";
output << "optim_weights_ = sparse(M_.endo_nbr,M_.endo_nbr);\n"; output << "optim_weights_ = sparse(M_.endo_nbr,M_.endo_nbr);\n";
...@@ -616,7 +616,7 @@ DynaSaveStatement::DynaSaveStatement(const TmpSymbolTable &tmp_symbol_table_arg, ...@@ -616,7 +616,7 @@ DynaSaveStatement::DynaSaveStatement(const TmpSymbolTable &tmp_symbol_table_arg,
} }
void void
DynaSaveStatement::writeOutput(ostream &output) const DynaSaveStatement::writeOutput(ostream &output, const string &basename) const
{ {
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
output << "dynasave(" << filename; output << "dynasave(" << filename;
...@@ -634,7 +634,7 @@ DynaTypeStatement::DynaTypeStatement(const TmpSymbolTable &tmp_symbol_table_arg, ...@@ -634,7 +634,7 @@ DynaTypeStatement::DynaTypeStatement(const TmpSymbolTable &tmp_symbol_table_arg,
} }
void void
DynaTypeStatement::writeOutput(ostream &output) const DynaTypeStatement::writeOutput(ostream &output, const string &basename) const
{ {
tmp_symbol_table.writeOutput("var_list_", output); tmp_symbol_table.writeOutput("var_list_", output);
output << "dynatype(" << filename; output << "dynatype(" << filename;
...@@ -651,7 +651,7 @@ ModelComparisonStatement::ModelComparisonStatement(const filename_list_type &fil ...@@ -651,7 +651,7 @@ ModelComparisonStatement::ModelComparisonStatement(const filename_list_type &fil
} }
void void
ModelComparisonStatement::writeOutput(ostream &output) const ModelComparisonStatement::writeOutput(ostream &output, const string &basename) const
{ {
options_list.writeOutput(output); options_list.writeOutput(output);
...@@ -666,3 +666,32 @@ ModelComparisonStatement::writeOutput(ostream &output) const ...@@ -666,3 +666,32 @@ ModelComparisonStatement::writeOutput(ostream &output) const
} }
output << "model_comparison(ModelNames_,ModelPriors_);\n"; output << "model_comparison(ModelNames_,ModelPriors_);\n";
} }
PlannerObjectiveStatement::PlannerObjectiveStatement(ModelTree *model_tree_arg) :
model_tree(model_tree_arg)
{
}
PlannerObjectiveStatement::~PlannerObjectiveStatement()
{
delete model_tree;
}
void
PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct)
{
model_tree->checkPass();
}
void
PlannerObjectiveStatement::computingPass()
{
model_tree->computeStaticHessian = true;
model_tree->computingPass();
}
void
PlannerObjectiveStatement::writeOutput(ostream &output, const string &basename) const
{
model_tree->writeStaticFile(basename + "_objective");
}
...@@ -44,7 +44,7 @@ typedef pair<int, Type> ExpObj; ...@@ -44,7 +44,7 @@ typedef pair<int, Type> ExpObj;
%token DATAFILE DIAGNOSTIC DIFFUSE_D DOLLAR DR_ALGO DROP DSAMPLE DYN2VEC DYNASAVE DYNATYPE %token DATAFILE DIAGNOSTIC DIFFUSE_D DOLLAR DR_ALGO DROP DSAMPLE DYN2VEC DYNASAVE DYNATYPE
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token PRIOR_ANALYSIS POSTERIOR_ANALYSIS %token PRIOR_ANALYSIS POSTERIOR_ANALYSIS
%token FILTERED_VARS FIRST_OBS %token FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token <string_val> FLOAT_NUMBER %token <string_val> FLOAT_NUMBER
%token FORECAST FUNCTIONS %token FORECAST FUNCTIONS
%token GAMMA_PDF GRAPH %token GAMMA_PDF GRAPH
...@@ -59,7 +59,7 @@ typedef pair<int, Type> ExpObj; ...@@ -59,7 +59,7 @@ typedef pair<int, Type> ExpObj;
%token NOBS NOCORR NODIAGNOSTIC NOFUNCTIONS NOGRAPH XLS_SHEET XLS_RANGE %token NOBS NOCORR NODIAGNOSTIC NOFUNCTIONS NOGRAPH XLS_SHEET XLS_RANGE
%token NOMOMENTS NOPRINT NORMAL_PDF %token NOMOMENTS NOPRINT NORMAL_PDF
%token OBSERVATION_TRENDS OLR OLR_INST OLR_BETA OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS %token OBSERVATION_TRENDS OLR OLR_INST OLR_BETA OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS
%token PARAMETERS PERIODS PREFILTER PRESAMPLE PRINT PRIOR_TRUNC FILTER_STEP_AHEAD %token PARAMETERS PERIODS PLANNER_OBJECTIVE PREFILTER PRESAMPLE PRINT PRIOR_TRUNC
%token QZ_CRITERIUM %token QZ_CRITERIUM
%token RELATIVE_IRF REPLIC RESOL RPLOT %token RELATIVE_IRF REPLIC RESOL RPLOT
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO STDERR STEADY STOCH_SIMUL %token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO STDERR STEADY STOCH_SIMUL
...@@ -129,6 +129,7 @@ typedef pair<int, Type> ExpObj; ...@@ -129,6 +129,7 @@ typedef pair<int, Type> ExpObj;
| olr | olr
| olr_inst | olr_inst
| model_comparison | model_comparison
| planner_objective
; ;
...@@ -330,10 +331,10 @@ typedef pair<int, Type> ExpObj; ...@@ -330,10 +331,10 @@ typedef pair<int, Type> ExpObj;
; ;
model model
: MODEL ';' equation_list END : MODEL ';' { driver.begin_model(); } equation_list END
| MODEL '(' o_linear ')' ';' | MODEL '(' o_linear ')' ';' { driver.begin_model(); }
equation_list END equation_list END
| MODEL '(' USE_DLL ')' ';' {driver.use_dll();} | MODEL '(' USE_DLL ')' ';' { driver.begin_model(); driver.use_dll(); }
equation_list END equation_list END
; ;
...@@ -1037,6 +1038,8 @@ typedef pair<int, Type> ExpObj; ...@@ -1037,6 +1038,8 @@ typedef pair<int, Type> ExpObj;
| o_noprint | o_noprint
; ;
planner_objective : PLANNER_OBJECTIVE { driver.begin_planner_objective(); } hand_side { driver.end_planner_objective($3); } ';'
filename_list : filename {driver.add_mc_filename($1);} filename_list : filename {driver.add_mc_filename($1);}
| filename_list COMMA filename {driver.add_mc_filename($3);} | filename_list COMMA filename {driver.add_mc_filename($3);}
| filename '(' value ')' {driver.add_mc_filename($1, $3);} | filename '(' value ')' {driver.add_mc_filename($1, $3);}
......
...@@ -80,6 +80,7 @@ int sigma_e = 0; ...@@ -80,6 +80,7 @@ int sigma_e = 0;
<INITIAL>dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;} <INITIAL>dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;}
<INITIAL>Sigma_e {BEGIN DYNARE_STATEMENT; sigma_e = 1; return token::SIGMA_E;} <INITIAL>Sigma_e {BEGIN DYNARE_STATEMENT; sigma_e = 1; return token::SIGMA_E;}
<INITIAL>calib {BEGIN DYNARE_STATEMENT; return token::CALIB;} <INITIAL>calib {BEGIN DYNARE_STATEMENT; return token::CALIB;}
<INITIAL>planner_objective {BEGIN DYNARE_STATEMENT; return token::PLANNER_OBJECTIVE;}
/* End of a Dynare statement */ /* End of a Dynare statement */
<DYNARE_STATEMENT>; { <DYNARE_STATEMENT>; {
......
...@@ -56,6 +56,10 @@ ModFile::computingPass() ...@@ -56,6 +56,10 @@ ModFile::computingPass()
} }
model_tree.computingPass(); model_tree.computingPass();
for(vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++)
(*it)->computingPass();
} }
void void
...@@ -140,7 +144,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) ...@@ -140,7 +144,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all)
// Print statements // Print statements
for(vector<Statement *>::iterator it = statements.begin(); for(vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++) it != statements.end(); it++)
(*it)->writeOutput(mOutputFile); (*it)->writeOutput(mOutputFile, basename);
mOutputFile << "save('" << basename << "_results', 'oo_');" << endl; mOutputFile << "save('" << basename << "_results', 'oo_');" << endl;
mOutputFile << "diary off" << endl; mOutputFile << "diary off" << endl;
......
...@@ -39,7 +39,8 @@ ModelTree::ModelTree(SymbolTable &symbol_table_arg, ...@@ -39,7 +39,8 @@ ModelTree::ModelTree(SymbolTable &symbol_table_arg,
num_constants(num_constants_arg), num_constants(num_constants_arg),
computeJacobian(false), computeJacobian(false),
computeJacobianExo(false), computeJacobianExo(false),
computeHessian(false) computeHessian(false),
computeStaticHessian(false)
{ {
} }
...@@ -56,7 +57,7 @@ ModelTree::writeStaticMFile(const string &static_basename) ...@@ -56,7 +57,7 @@ ModelTree::writeStaticMFile(const string &static_basename)
exit(-1); exit(-1);
} }
// Writing comments and function definition command // Writing comments and function definition command
mStaticModelFile << "function [residual, g1] = " << static_basename << "( y, x )\n"; mStaticModelFile << "function [residual, g1, g2] = " << static_basename << "( y, x )\n";
mStaticModelFile << interfaces::comment()+"\n"+interfaces::comment(); mStaticModelFile << interfaces::comment()+"\n"+interfaces::comment();
mStaticModelFile << "Status : Computes static model for Dynare\n" << interfaces::comment() << "\n"; mStaticModelFile << "Status : Computes static model for Dynare\n" << interfaces::comment() << "\n";
mStaticModelFile << interfaces::comment(); mStaticModelFile << interfaces::comment();
...@@ -630,13 +631,10 @@ inline NodeID ModelTree::DeriveArgument(NodeID iArg, Type iType, int iVarID) ...@@ -630,13 +631,10 @@ inline NodeID ModelTree::DeriveArgument(NodeID iArg, Type iType, int iVarID)
void void
ModelTree::writeStaticModel(ostream &StaticOutput) ModelTree::writeStaticModel(ostream &StaticOutput)
{ {
TreeIterator tree_it;
int lEquationNBR = 0;
ostringstream model_output; // Used for storing model equations ostringstream model_output; // Used for storing model equations
ostringstream model_tmp_output;// Used for storing tmp expressions for model equations
ostringstream jacobian_output; // Used for storing jacobian equations ostringstream jacobian_output; // Used for storing jacobian equations
// Used for storing tmp expressions for jacobian equations ostringstream hessian_output;
ostringstream jacobian_tmp_output; ostringstream lsymetric; // For symmetric elements in hessian
int d = current_order; // Minimum number of times a temparary expression apears in equations int d = current_order; // Minimum number of times a temparary expression apears in equations
// Reference count of token "0=0" is set to 0 // Reference count of token "0=0" is set to 0
...@@ -645,23 +643,24 @@ ModelTree::writeStaticModel(ostream &StaticOutput) ...@@ -645,23 +643,24 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
ZeroEqZero->reference_count.end(),0); ZeroEqZero->reference_count.end(),0);
// Writing model Equations // Writing model Equations
current_order = 1; current_order = 1;
tree_it = BeginModel; TreeIterator tree_it = BeginModel;
int lEquationNBR = 0;
for (; tree_it != mModelTree.end(); tree_it++) for (; tree_it != mModelTree.end(); tree_it++)
{ {
if ((*tree_it)->op_code == token::EQUAL || (*tree_it)->op_code == token::ASSIGN ) if ((*tree_it)->op_code == token::EQUAL || (*tree_it)->op_code == token::ASSIGN )
{ {
if ((*tree_it)->id1->type1 == eLocalParameter) if ((*tree_it)->id1->type1 == eLocalParameter)
{ {
model_output << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR); model_output << getExpression((*tree_it)->id1, eStaticEquations);
model_output << " = "; model_output << " = ";
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl; model_output << getExpression((*tree_it)->id2, eStaticEquations) << ";" << endl;
} }
else if (lEquationNBR < eq_nbr) else if (lEquationNBR < eq_nbr)
{ {
model_output << "lhs ="; model_output << "lhs =";
model_output << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR) << ";" << endl; model_output << getExpression((*tree_it)->id1, eStaticEquations) << ";" << endl;
model_output << "rhs ="; model_output << "rhs =";
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl; model_output << getExpression((*tree_it)->id2, eStaticEquations) << ";" << endl;
model_output << "residual" << lpar << lEquationNBR+1 << rpar << "= lhs-rhs;" << endl; model_output << "residual" << lpar << lEquationNBR+1 << rpar << "= lhs-rhs;" << endl;
lEquationNBR++; lEquationNBR++;
} }
...@@ -672,7 +671,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput) ...@@ -672,7 +671,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
{ {
if (optimize(*tree_it)) if (optimize(*tree_it))
{ {
model_output << "T" << (*tree_it)->idx << "=" << getExpression(*tree_it, eStaticEquations, lEquationNBR) << ";" << endl; model_output << "T" << (*tree_it)->idx << "=" << getExpression(*tree_it, eStaticEquations) << ";" << endl;
(*tree_it)->tmp_status = 1; (*tree_it)->tmp_status = 1;
} }
else else
...@@ -682,7 +681,6 @@ ModelTree::writeStaticModel(ostream &StaticOutput) ...@@ -682,7 +681,6 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
} }
} }
// Writing Jacobian for endogenous variables without lag
for(; tree_it != mModelTree.end(); tree_it++) for(; tree_it != mModelTree.end(); tree_it++)
{ {
if ((*tree_it)->op_code != NoOpCode if ((*tree_it)->op_code != NoOpCode
...@@ -691,7 +689,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput) ...@@ -691,7 +689,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput)