Commit 8507409d authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Allow ranges in lags/periods specification of {irf,moment}_calibration.

Ref #267
parent 42487be4
......@@ -175,6 +175,7 @@ class ParsingDriver;
%type <string_val> filename symbol vec_of_vec_value vec_value_list date_expr
%type <string_val> vec_value_1 vec_value signed_inf signed_number_w_inf
%type <string_val> range vec_value_w_inf vec_value_1_w_inf named_var
%type <string_val> integer_range signed_integer_range
%type <symbol_type_val> change_type_arg
%type <vector_string_val> change_type_var_list subsamples_eq_opt prior_eq_opt options_eq_opt calibration_range
%type <vector_int_val> vec_int_elem vec_int_1 vec_int vec_int_number
......@@ -2367,6 +2368,8 @@ moment_calibration_item : symbol COMMA symbol COMMA calibration_range ';'
{ driver.add_moment_calibration_item($1, $3, new string("0"), $5); }
| symbol COMMA symbol '(' signed_integer ')' COMMA calibration_range ';'
{ driver.add_moment_calibration_item($1, $3, $5, $8); }
| symbol COMMA symbol '(' signed_integer_range ')' COMMA calibration_range ';'
{ driver.add_moment_calibration_item($1, $3, $5, $8); }
;
irf_calibration : IRF_CALIBRATION ';' irf_calibration_list END ';'
......@@ -2381,6 +2384,8 @@ irf_calibration_item : symbol COMMA symbol COMMA calibration_range ';'
{ driver.add_irf_calibration_item($1, new string("1"), $3, $5); }
| symbol '(' INT_NUMBER ')' COMMA symbol COMMA calibration_range ';'
{ driver.add_irf_calibration_item($1, $3, $6, $8); }
| symbol '(' integer_range ')' COMMA symbol COMMA calibration_range ';'
{ driver.add_irf_calibration_item($1, $3, $6, $8); }
;
o_dr_algo : DR_ALGO EQUAL INT_NUMBER {
......@@ -2842,6 +2847,31 @@ range : symbol ':' symbol
$$ = $1;
};
integer_range : INT_NUMBER ':' INT_NUMBER
{
$1->append(":");
$1->append(*$3);
delete $3;
$$ = $1;
};
signed_integer_range : signed_integer ':' signed_integer
{
$1->append(":");
$1->append(*$3);
delete $3;
$$ = $1;
}
| MINUS '(' signed_integer ':' signed_integer ')'
{
$3->insert(0, "-(");
$3->append(":");
$3->append(*$5);
delete $5;
$3->append(")");
$$ = $3;
};
vec_int_number : INT_NUMBER { $$ = new vector<int>(); $$->push_back(atoi((*$1).c_str())); delete $1; };
vec_int_elem : vec_int_number
......
......@@ -2606,7 +2606,7 @@ ParsingDriver::add_parallel_local_file(string *filename)
}
void
ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string *lag, vector<string *> *range)
ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string *lags, vector<string *> *range)
{
MomentCalibration::Constraint c;
......@@ -2622,8 +2622,8 @@ ParsingDriver::add_moment_calibration_item(string *endo1, string *endo2, string
error("Variable " + *endo2 + " is not an endogenous.");
delete endo2;
c.lag = abs(atoi(lag->c_str()));
delete lag;
c.lags = *lags;
delete lags;
assert(range->size() == 2);
c.lower_bound = *((*range)[0]);
......@@ -2643,7 +2643,7 @@ void ParsingDriver::end_moment_calibration()
}
void
ParsingDriver::add_irf_calibration_item(string *endo, string *period, string *exo, vector<string *> *range)
ParsingDriver::add_irf_calibration_item(string *endo, string *periods, string *exo, vector<string *> *range)
{
IrfCalibration::Constraint c;
......@@ -2653,8 +2653,8 @@ ParsingDriver::add_irf_calibration_item(string *endo, string *period, string *ex
error("Variable " + *endo + " is not an endogenous.");
delete endo;
c.period = atoi(period->c_str());
delete period;
c.periods = *periods;
delete periods;
check_symbol_existence(*exo);
c.exo = mod_file->symbol_table.getID(*exo);
......
......@@ -658,11 +658,11 @@ public:
//! Processing the parallel_local_files option
void add_parallel_local_file(string *filename);
//! Add an item of a moment_calibration statement
void add_moment_calibration_item(string *endo1, string *endo2, string *lag, vector<string *> *range);
void add_moment_calibration_item(string *endo1, string *endo2, string *lags, vector<string *> *range);
//! End a moment_calibration statement
void end_moment_calibration();
//! Add an item of an irf_calibration statement
void add_irf_calibration_item(string *endo, string *period, string *exo, vector<string *> *range);
void add_irf_calibration_item(string *endo, string *periods, string *exo, vector<string *> *range);
//! End a moment_calibration statement
void end_irf_calibration();
};
......
......@@ -402,7 +402,7 @@ MomentCalibration::writeOutput(ostream &output, const string &basename) const
const Constraint &c = constraints[i];
output << "'" << symbol_table.getName(c.endo1) << "', "
<< "'" << symbol_table.getName(c.endo2) << "', "
<< c.lag << ", "
<< c.lags << ", "
<< "[ " << c.lower_bound << ", " << c.upper_bound << " ];"
<< endl;
}
......@@ -424,7 +424,7 @@ IrfCalibration::writeOutput(ostream &output, const string &basename) const
const Constraint &c = constraints[i];
output << "'" << symbol_table.getName(c.endo) << "', "
<< "'" << symbol_table.getName(c.exo) << "', "
<< c.period << ", "
<< c.periods << ", "
<< "[ " << c.lower_bound << ", " << c.upper_bound << " ];"
<< endl;
}
......
......@@ -103,7 +103,7 @@ public:
struct Constraint
{
int endo1, endo2;
int lag;
string lags;
string lower_bound, upper_bound;
};
typedef vector<Constraint> constraints_t;
......@@ -121,9 +121,9 @@ class IrfCalibration : public Statement
public:
struct Constraint
{
int endo, period;
int endo;
int exo;
string lower_bound, upper_bound;
string periods, lower_bound, upper_bound;
};
typedef vector<Constraint> constraints_t;
private:
......
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