Commit 0e9ab2eb authored by ferhat's avatar ferhat
Browse files

- Bugs corrections in deterministic simulation with sparse option

- Check allowed with sparse option
- New command "MODEL_INFO" providing informations about the block structure of the model
- Memory leak corrections

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1993 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 43c5fd18
This diff is collapsed.
......@@ -68,6 +68,23 @@ CheckStatement::checkPass(ModFileStructure &mod_file_struct)
mod_file_struct.check_present = true;
}
Model_InfoStatement::Model_InfoStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
{
}
void Model_InfoStatement::checkPass(ModFileStructure &mod_file_struct)
{
//mod_file_struct.model_info_present = true;
}
void Model_InfoStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
output << "model_info();\n";
}
SimulStatement::SimulStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
{
......
......@@ -183,6 +183,7 @@ statement : declaration
| dynatype
| dynasave
| model_comparison
| model_info
| planner_objective
| ramsey_policy
| bvar_density
......@@ -612,6 +613,10 @@ check_options_list : check_options_list COMMA check_options
check_options : o_solve_algo;
model_info : MODEL_INFO ';'
{ driver.model_info(); }
;
simul : SIMUL ';'
{ driver.simulate(); }
| SIMUL '(' simul_options_list ')' ';'
......
......@@ -104,6 +104,7 @@ int sigma_e = 0;
<INITIAL>periods {BEGIN DYNARE_STATEMENT; return token::PERIODS;}
<INITIAL>cutoff {BEGIN DYNARE_STATEMENT; return token::CUTOFF;}
<INITIAL>markowitz {BEGIN DYNARE_STATEMENT; return token::MARKOWITZ;}
<INITIAL>model_info {BEGIN DYNARE_STATEMENT; return token::MODEL_INFO;}
<INITIAL>estimation {BEGIN DYNARE_STATEMENT; return token::ESTIMATION;}
<INITIAL>prior_analysis {BEGIN DYNARE_STATEMENT; return token::PRIOR_ANALYSIS;}
<INITIAL>posterior_analysis {BEGIN DYNARE_STATEMENT; return token::POSTERIOR_ANALYSIS;}
......
......@@ -86,6 +86,7 @@ main(int argc, char** argv)
}
// Do the rest
main2(macro_output, basename, debug, clear_all);
return 0;
......
......@@ -28,10 +28,10 @@ void
main2(stringstream &in, string &basename, bool debug, bool clear_all)
{
ParsingDriver p;
//cout << "OK\n";
// Do parsing and construct internal representation of mod file
ModFile *mod_file = p.parse(in, debug);
//cout << "OK1\n";
// Run checking pass
mod_file->checkPass();
......
......@@ -150,6 +150,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
<< "warning warning_old_state" << endl;
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
mOutputFile << "diary " << basename << ".log" << endl;
mOutputFile << "options_.model_mode = " << model_tree.mode << ";\n";
if (model_tree.equation_number() > 0)
......
......@@ -207,6 +207,9 @@ Blocks::sc(Equation_set *g)
void
Blocks::block_result_free(block_result_t *r)
{
#ifdef DEBUG
cout << "block_result_free\n";
#endif
free(r->vertices);
free(r->sets_s);
free(r->sets_f);
......
......@@ -283,9 +283,23 @@ void
Normalization::Gr_to_IM_basic(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation, bool transpose)
{
int i, j, edges, n;
Edge *e1;
Edge *e1, *e2;
n = n0 - prologue - epilogue;
Equation->size = n;
if(Equation->Number)
{
for(i = 0;i < n;i++)
{
e1 = Equation->Number[i].First_Edge;
while(e1 != NULL)
{
e2 = e1->next;
free(e1);
e1 = e2;
}
}
free(Equation->Number);
}
Equation->Number = (Equation_vertex*)malloc(n * sizeof(Equation_vertex));
edges = 0;
if(transpose)
......@@ -382,8 +396,12 @@ Normalization::Gr_to_IM(int n0, int prologue, int epilogue, bool* IM, simple* In
}
free(SIM);
free(Index_Equ_IM_tmp);
//cout << "mixing=" << mixing << "\n";
if(mixing)
Gr_to_IM_basic(n0, prologue, epilogue, IM, Equation, true);
{
//Free_Equation(n,Equation);
Gr_to_IM_basic(n0, prologue, epilogue, IM, Equation, true);
}
else
{
// In this step we :
......@@ -453,17 +471,21 @@ Normalization::Free_Equation(int n, Equation_set* Equation)
while(e1 != NULL)
{
e2 = e1->next;
free(e1);
e1 = e2;
}
}
free(Equation->Number);
free(Equation);
//free(Equation);
}
void
Normalization::Free_Other(Variable_set* Variable)
{
//free unused space
#ifdef DEBUG
cout << "Free_Other\n";
#endif
free(Local_Heap);
free(Variable->Number);
free(Variable);
......@@ -526,6 +548,7 @@ Normalization::Normalize(int n, int prologue, int epilogue, bool* IM, simple* In
}
}
Free_Other(Variable);
//Free_All(n,Equation,Variable);
#ifdef DEBUG
cout << "end of Normalize\n";
#endif
......
This diff is collapsed.
......@@ -729,6 +729,15 @@ ParsingDriver::simul()
options_list.clear();
}
void
ParsingDriver::model_info()
{
mod_file->addStatement(new Model_InfoStatement(options_list));
options_list.clear();
}
void
ParsingDriver::check()
{
......
......@@ -57,14 +57,14 @@ public:
void unfill_IM(int equation, int variable_endo, int lead_lag);
void init_incidence_matrix(int nb_endo);
void Print_IM(int n) const;
void Free_IM(List_IM* First_IM);
void Free_IM(List_IM* First_IM) const;
void Print_SIM(bool* IM, int n) const;
void Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_m);
bool Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int* prologue, int* epilogue, simple* Index_Var_IM, simple* Index_Equ_IM, bool Do_Normalization, bool mixing, bool* IM_0 , jacob_map j_m);
void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM);
void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM, bool* IM0);
void swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Index_Var_IM, simple* Index_Equ_IM, int n);
void Allocate_Block(int size, int *count_Equ, int *count_Block, int type, Model_Block * ModelBlock);
void Free_Block(Model_Block* ModelBlock);
void Free_Block(Model_Block* ModelBlock) const;
List_IM *First_IM ;
List_IM *Last_IM ;
simple *Index_Equ_IM;
......
......@@ -76,6 +76,16 @@ public:
virtual void writeOutput(ostream &output, const string &basename) const;
};
class Model_InfoStatement : public Statement
{
private:
const OptionsList options_list;
public:
Model_InfoStatement(const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const;
};
class StochSimulStatement : public Statement
{
private:
......
......@@ -73,6 +73,7 @@ public:
void Gr_to_IM_basic(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation,bool transpose);
const SymbolTable &symbol_table;
void Set_fp_verbose(bool ok);
void Free_Equation(int n, Equation_set* Equation);
private:
void IM_to_Gr(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation, Variable_set *Variable );
void Inits(Equation_set *Equation);
......@@ -83,7 +84,6 @@ private:
int MeasureMatching(Equation_set *Equation);
void OutputMatching(Equation_set* Equation);
void Gr_to_IM(int n0, int prologue, int epilogue, bool* IM, simple* Index_Var_IM, Equation_set *Equation,bool mixing, bool* IM_s);
void Free_Equation(int n, Equation_set* Equation);
void Free_Other(Variable_set* Variable);
void Free_All(int n, Equation_set* Equation, Variable_set* Variable);
int eq, eex;
......
......@@ -46,6 +46,7 @@ using namespace std;
# undef yyFlexLexer
#endif
//! The lexer class
/*! Actually it was necessary to subclass the DynareFlexLexer class generated by Flex,
since the prototype for DynareFlexLexer::yylex() was not convenient.
......@@ -53,7 +54,7 @@ using namespace std;
class DynareFlex : public DynareFlexLexer
{
public:
DynareFlex(istream* in = 0, ostream* out = 0);
DynareFlex(std::istream* in = 0, ostream* out = 0);
//! The main lexing function
Dynare::parser::token_type lex(Dynare::parser::semantic_type *yylval,
......@@ -145,7 +146,7 @@ public:
//! Starts parsing, and constructs the MOD file representation
/*! The returned pointer should be deleted after use */
ModFile *parse(istream &in, bool debug);
ModFile *parse(std::istream &in, bool debug);
//! Reference to the lexer
class DynareFlex *lexer;
......@@ -282,6 +283,8 @@ public:
void simul();
//! Writes check command
void check();
//! Writes model_info command
void model_info();
//! Writes estimated params command
void estimated_params();
//! Writes estimated params init command
......
......@@ -53,12 +53,12 @@ private:
class ScanContext
{
public:
istream *input;
std::istream *input;
struct yy_buffer_state *buffer;
const Macro::parser::location_type yylloc;
const string for_body;
const Macro::parser::location_type for_body_loc;
ScanContext(istream *input_arg, struct yy_buffer_state *buffer_arg,
ScanContext(std::istream *input_arg, struct yy_buffer_state *buffer_arg,
Macro::parser::location_type &yylloc_arg, const string &for_body_arg,
Macro::parser::location_type &for_body_loc_arg) :
input(input_arg), buffer(buffer_arg), yylloc(yylloc_arg), for_body(for_body_arg),
......@@ -70,7 +70,7 @@ private:
//! Input stream used for initialization of current scanning context
/*! Kept for deletion at end of current scanning buffer */
istream *input;
std::istream *input;
//! If current context is the body of a loop, contains the string of the loop body. Empty otherwise.
string for_body;
......@@ -125,7 +125,7 @@ private:
and initialise a new scanning context with the loop body */
bool iter_loop(MacroDriver &driver, Macro::parser::location_type *yylloc);
public:
MacroFlex(istream* in = 0, ostream* out = 0);
MacroFlex(std::istream* in = 0, ostream* out = 0);
//! The main lexing function
Macro::parser::token_type lex(Macro::parser::semantic_type *yylval,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment