Beautified preprocessor code (uncrustify + emacs + manual adjustments, in particular with templates in MacroValue)
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3249 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
c01a3c134b
commit
e6f1a53e60
File diff suppressed because it is too large
Load Diff
|
@ -67,18 +67,19 @@ ModelInfoStatement::ModelInfoStatement(const OptionsList &options_list_arg) :
|
|||
{
|
||||
}
|
||||
|
||||
void ModelInfoStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
void
|
||||
ModelInfoStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
//mod_file_struct.model_info_present = true;
|
||||
}
|
||||
|
||||
void ModelInfoStatement::writeOutput(ostream &output, const string &basename) const
|
||||
void
|
||||
ModelInfoStatement::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)
|
||||
{
|
||||
|
@ -112,7 +113,7 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
// Fill in option_order of mod_file_struct
|
||||
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
|
||||
if (it != options_list.num_options.end())
|
||||
mod_file_struct.order_option = max(mod_file_struct.order_option,atoi(it->second.c_str()));
|
||||
mod_file_struct.order_option = max(mod_file_struct.order_option, atoi(it->second.c_str()));
|
||||
|
||||
// Fill in mod_file_struct.partial_information
|
||||
it = options_list.num_options.find("partial_information");
|
||||
|
@ -211,7 +212,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
// Fill in option_order of mod_file_struct
|
||||
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
|
||||
if (it != options_list.num_options.end())
|
||||
mod_file_struct.order_option = max(mod_file_struct.order_option,atoi(it->second.c_str()));
|
||||
mod_file_struct.order_option = max(mod_file_struct.order_option, atoi(it->second.c_str()));
|
||||
|
||||
// Fill in mod_file_struct.partial_information
|
||||
it = options_list.num_options.find("partial_information");
|
||||
|
@ -274,7 +275,7 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
void
|
||||
DynareSensitivityStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
options_list.writeOutput(output,"options_gsa");
|
||||
options_list.writeOutput(output, "options_gsa");
|
||||
output << "dynare_sensitivity(options_gsa);" << endl;
|
||||
}
|
||||
|
||||
|
@ -362,12 +363,12 @@ EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) c
|
|||
|
||||
vector<EstimationParams>::const_iterator it;
|
||||
|
||||
for(it = estim_params_list.begin(); it != estim_params_list.end(); it++)
|
||||
for (it = estim_params_list.begin(); it != estim_params_list.end(); it++)
|
||||
{
|
||||
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1;
|
||||
SymbolType symb_type = symbol_table.getType(it->name);
|
||||
|
||||
switch(it->type)
|
||||
switch (it->type)
|
||||
{
|
||||
case 1:
|
||||
if (symb_type == eExogenous)
|
||||
|
@ -421,7 +422,7 @@ EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basenam
|
|||
{
|
||||
vector<EstimationParams>::const_iterator it;
|
||||
|
||||
for(it = estim_params_list.begin(); it != estim_params_list.end(); it++)
|
||||
for (it = estim_params_list.begin(); it != estim_params_list.end(); it++)
|
||||
{
|
||||
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1;
|
||||
SymbolType symb_type = symbol_table.getType(it->name);
|
||||
|
@ -482,7 +483,7 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
|
|||
{
|
||||
vector<EstimationParams>::const_iterator it;
|
||||
|
||||
for(it = estim_params_list.begin(); it != estim_params_list.end(); it++)
|
||||
for (it = estim_params_list.begin(); it != estim_params_list.end(); it++)
|
||||
{
|
||||
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1;
|
||||
SymbolType symb_type = symbol_table.getType(it->name);
|
||||
|
@ -570,7 +571,7 @@ ObservationTrendsStatement::writeOutput(ostream &output, const string &basename)
|
|||
|
||||
trend_elements_type::const_iterator it;
|
||||
|
||||
for(it = trend_elements.begin(); it != trend_elements.end(); it++)
|
||||
for (it = trend_elements.begin(); it != trend_elements.end(); it++)
|
||||
{
|
||||
SymbolType type = symbol_table.getType(it->first);
|
||||
if (type == eEndogenous)
|
||||
|
@ -604,7 +605,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "% CALIB_VAR" << endl
|
||||
<< "%" << endl;
|
||||
|
||||
for(int i = 1; i < 4 ; i++)
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
output << "calib_var_index{" << i << "} = [];\n";
|
||||
output << "calib_targets{" << i << "} = [];\n";
|
||||
|
@ -612,8 +613,8 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
}
|
||||
|
||||
// Print calibration variances
|
||||
for(calib_var_type::const_iterator it = calib_var.begin();
|
||||
it != calib_var.end(); it++)
|
||||
for (calib_var_type::const_iterator it = calib_var.begin();
|
||||
it != calib_var.end(); it++)
|
||||
{
|
||||
const string &name = it->first;
|
||||
const string &weight = it->second.first;
|
||||
|
@ -639,8 +640,8 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
}
|
||||
|
||||
// Print calibration covariances
|
||||
for(calib_covar_type::const_iterator it = calib_covar.begin();
|
||||
it != calib_covar.end(); it++)
|
||||
for (calib_covar_type::const_iterator it = calib_covar.begin();
|
||||
it != calib_covar.end(); it++)
|
||||
{
|
||||
const string &name1 = it->first.first;
|
||||
const string &name2 = it->first.second;
|
||||
|
@ -670,8 +671,8 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
// Print calibration autocorrelations
|
||||
int max_iar = 3;
|
||||
|
||||
for(calib_ac_type::const_iterator it = calib_ac.begin();
|
||||
it != calib_ac.end(); it++)
|
||||
for (calib_ac_type::const_iterator it = calib_ac.begin();
|
||||
it != calib_ac.end(); it++)
|
||||
{
|
||||
const string &name = it->first.first;
|
||||
int iar = it->first.second + 3;
|
||||
|
@ -683,7 +684,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
if (iar > max_iar)
|
||||
{
|
||||
// Create new variables
|
||||
for(int i = max_iar + 1; i <= iar; i++)
|
||||
for (int i = max_iar + 1; i <= iar; i++)
|
||||
{
|
||||
output << "calib_var_index{" << i << "} = [];\n";
|
||||
output << "calib_targets{" << i << "} = [];\n";
|
||||
|
@ -736,7 +737,7 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
// Fill in option_order of mod_file_struct
|
||||
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
|
||||
if (it != options_list.num_options.end())
|
||||
mod_file_struct.order_option = max(mod_file_struct.order_option,atoi(it->second.c_str()));
|
||||
mod_file_struct.order_option = max(mod_file_struct.order_option, atoi(it->second.c_str()));
|
||||
|
||||
// Fill in mod_file_struct.partial_information
|
||||
it = options_list.num_options.find("partial_information");
|
||||
|
@ -776,8 +777,8 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
|
|||
<< "optim_weights_ = sparse(M_.endo_nbr,M_.endo_nbr);" << endl
|
||||
<< "obj_var_ = [];" << endl << endl;
|
||||
|
||||
for(var_weights_type::const_iterator it = var_weights.begin();
|
||||
it != var_weights.end(); it++)
|
||||
for (var_weights_type::const_iterator it = var_weights.begin();
|
||||
it != var_weights.end(); it++)
|
||||
{
|
||||
const string &name = it->first;
|
||||
const NodeID value = it->second;
|
||||
|
@ -788,8 +789,8 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
|
|||
output << "obj_var_ = [obj_var_; " << id << "];\n";
|
||||
}
|
||||
|
||||
for(covar_weights_type::const_iterator it = covar_weights.begin();
|
||||
it != covar_weights.end(); it++)
|
||||
for (covar_weights_type::const_iterator it = covar_weights.begin();
|
||||
it != covar_weights.end(); it++)
|
||||
{
|
||||
const string &name1 = it->first.first;
|
||||
const string &name2 = it->first.second;
|
||||
|
@ -848,8 +849,8 @@ ModelComparisonStatement::writeOutput(ostream &output, const string &basename) c
|
|||
output << "ModelNames_ = {};" << endl;
|
||||
output << "ModelPriors_ = [];" << endl;
|
||||
|
||||
for(filename_list_type::const_iterator it = filename_list.begin();
|
||||
it != filename_list.end(); it++)
|
||||
for (filename_list_type::const_iterator it = filename_list.begin();
|
||||
it != filename_list.end(); it++)
|
||||
{
|
||||
output << "ModelNames_ = { ModelNames_{:} '" << (*it).first << "'};" << endl;
|
||||
output << "ModelPriors_ = [ ModelPriors_ ; " << (*it).second << "];" << endl;
|
||||
|
@ -959,8 +960,6 @@ MS_SBVARStatement::writeOutput(ostream &output, const string &basename) const
|
|||
output << "swz_sbvar(1,M_,options_);" << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
IdentificationStatement::IdentificationStatement(const OptionsList &options_list_arg) :
|
||||
options_list(options_list_arg)
|
||||
{
|
||||
|
@ -1002,7 +1001,7 @@ WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basen
|
|||
}
|
||||
|
||||
ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbol_list_arg,
|
||||
const OptionsList &options_list_arg) :
|
||||
const OptionsList &options_list_arg) :
|
||||
symbol_list(symbol_list_arg),
|
||||
options_list(options_list_arg)
|
||||
{
|
||||
|
@ -1104,7 +1103,7 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename
|
|||
int r = getMaxLag();
|
||||
int k = r*n+m;
|
||||
|
||||
if (k<1)
|
||||
if (k < 1)
|
||||
{
|
||||
cerr << "ERROR: lag = " << r
|
||||
<< ", number of endogenous variables = " << n
|
||||
|
@ -1113,7 +1112,7 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename
|
|||
<< " of the .mod file, please report it to the Dynare Team." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (n<1)
|
||||
if (n < 1)
|
||||
{
|
||||
cerr << "ERROR: Number of endogenous variables = " << n << "< 1. If this is not a logical "
|
||||
<< "error in the specification of the .mod file, please report it to the Dynare Team." << endl;
|
||||
|
@ -1128,7 +1127,7 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename
|
|||
{
|
||||
int j = it->second.at(h) + 1;
|
||||
int i = it->first.second;
|
||||
if (j < 1 || j > n || (int)h+1 > n || i < 1)
|
||||
if (j < 1 || j > n || (int) h+1 > n || i < 1)
|
||||
{
|
||||
cerr << "SvarIdentificationStatement::writeOutput() Should not arrive here (2). Please report this to the Dynare Team." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1186,12 +1185,12 @@ MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) c
|
|||
|
||||
itState = options_list.num_options.find("ms.state");
|
||||
itNOS = options_list.num_options.find("ms.number_of_states");
|
||||
if (itState != options_list.num_options.end() &&
|
||||
itNOS == options_list.num_options.end())
|
||||
if (itState != options_list.num_options.end()
|
||||
&& itNOS == options_list.num_options.end())
|
||||
output << "options_.ms.ms_chain(" << itChain->second << ").state(" << itState->second << ").duration = " << itDuration->second << ";" << endl;
|
||||
else if (itState == options_list.num_options.end() &&
|
||||
itNOS != options_list.num_options.end())
|
||||
for (int i=0; i<atoi(itNOS->second.c_str()); i++)
|
||||
else if (itState == options_list.num_options.end()
|
||||
&& itNOS != options_list.num_options.end())
|
||||
for (int i = 0; i < atoi(itNOS->second.c_str()); i++)
|
||||
output << "options_.ms.ms_chain(" << itChain->second << ").state(" << i+1 << ").duration = " << itDuration->second << ";" << endl;
|
||||
else
|
||||
{
|
||||
|
@ -1200,7 +1199,6 @@ MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) c
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
SvarStatement::SvarStatement(const OptionsList &options_list_arg) :
|
||||
options_list(options_list_arg)
|
||||
{
|
||||
|
@ -1224,17 +1222,17 @@ SvarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
it0 = options_list.string_options.find("ms.coefficients");
|
||||
it1 = options_list.string_options.find("ms.variances");
|
||||
it2 = options_list.string_options.find("ms.constants");
|
||||
if (it0 != options_list.string_options.end() &&
|
||||
it1 == options_list.string_options.end() &&
|
||||
it2 == options_list.string_options.end())
|
||||
if (it0 != options_list.string_options.end()
|
||||
&& it1 == options_list.string_options.end()
|
||||
&& it2 == options_list.string_options.end())
|
||||
output << "." << it0->second;
|
||||
else if (it0 == options_list.string_options.end() &&
|
||||
it1 != options_list.string_options.end() &&
|
||||
it2 == options_list.string_options.end())
|
||||
else if (it0 == options_list.string_options.end()
|
||||
&& it1 != options_list.string_options.end()
|
||||
&& it2 == options_list.string_options.end())
|
||||
output << "." << it1->second;
|
||||
else if (it0 == options_list.string_options.end() &&
|
||||
it1 == options_list.string_options.end() &&
|
||||
it2 != options_list.string_options.end())
|
||||
else if (it0 == options_list.string_options.end()
|
||||
&& it1 == options_list.string_options.end()
|
||||
&& it2 != options_list.string_options.end())
|
||||
output << "." << it2->second;
|
||||
else
|
||||
{
|
||||
|
@ -1249,8 +1247,8 @@ SvarStatement::writeOutput(ostream &output, const string &basename) const
|
|||
if (itv->second.size() > 1)
|
||||
{
|
||||
output << "[";
|
||||
for (vector<int>::const_iterator viit=itv->second.begin();
|
||||
viit!=itv->second.end(); viit++)
|
||||
for (vector<int>::const_iterator viit = itv->second.begin();
|
||||
viit != itv->second.end(); viit++)
|
||||
output << *viit << ";";
|
||||
output << "];" << endl;
|
||||
}
|
||||
|
|
|
@ -272,7 +272,8 @@ public:
|
|||
string name, name2, prior;
|
||||
NodeID init_val, low_bound, up_bound, mean, std, p3, p4, jscale;
|
||||
|
||||
void init(const DataTree &datatree)
|
||||
void
|
||||
init(const DataTree &datatree)
|
||||
{
|
||||
type = 0;
|
||||
name = "";
|
||||
|
@ -465,7 +466,7 @@ private:
|
|||
const OptionsList options_list;
|
||||
public:
|
||||
ShockDecompositionStatement(const SymbolList &symbol_list_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -265,7 +265,8 @@ DataTree::AddLog(NodeID iArg1)
|
|||
}
|
||||
}
|
||||
|
||||
NodeID DataTree::AddLog10(NodeID iArg1)
|
||||
NodeID
|
||||
DataTree::AddLog10(NodeID iArg1)
|
||||
{
|
||||
if (iArg1 != Zero && iArg1 != One)
|
||||
return AddUnaryOp(oLog10, iArg1);
|
||||
|
@ -459,8 +460,8 @@ DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> &
|
|||
bool
|
||||
DataTree::isSymbolUsed(int symb_id) const
|
||||
{
|
||||
for(variable_node_map_type::const_iterator it = variable_node_map.begin();
|
||||
it != variable_node_map.end(); it++)
|
||||
for (variable_node_map_type::const_iterator it = variable_node_map.begin();
|
||||
it != variable_node_map.end(); it++)
|
||||
if (it->first.first == symb_id)
|
||||
return true;
|
||||
|
||||
|
@ -485,8 +486,8 @@ DataTree::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException)
|
|||
bool
|
||||
DataTree::containsSteadyStateOperator() const
|
||||
{
|
||||
for(unary_op_node_map_type::const_iterator it = unary_op_node_map.begin();
|
||||
it != unary_op_node_map.end(); it++)
|
||||
for (unary_op_node_map_type::const_iterator it = unary_op_node_map.begin();
|
||||
it != unary_op_node_map.end(); it++)
|
||||
if (it->first.second == oSteadyState)
|
||||
return true;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ protected:
|
|||
unary_op_node_map_type unary_op_node_map;
|
||||
typedef map<pair<pair<NodeID, NodeID>, BinaryOpcode>, BinaryOpNode *> binary_op_node_map_type;
|
||||
binary_op_node_map_type binary_op_node_map;
|
||||
typedef map<pair<pair<pair<NodeID, NodeID>,NodeID>, TrinaryOpcode>, TrinaryOpNode *> trinary_op_node_map_type;
|
||||
typedef map<pair<pair<pair<NodeID, NodeID>, NodeID>, TrinaryOpcode>, TrinaryOpNode *> trinary_op_node_map_type;
|
||||
trinary_op_node_map_type trinary_op_node_map;
|
||||
|
||||
//! Stores local variables value (maps symbol ID to corresponding node)
|
||||
|
@ -94,7 +94,9 @@ public:
|
|||
{
|
||||
public:
|
||||
string name;
|
||||
LocalVariableException(const string &name_arg) : name(name_arg) {}
|
||||
LocalVariableException(const string &name_arg) : name(name_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//! Adds a numerical constant
|
||||
|
@ -190,7 +192,11 @@ public:
|
|||
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
|
||||
|
||||
//! Returns bool indicating whether DataTree represents a Dynamic Model (returns true in DynamicModel.hh)
|
||||
virtual bool isDynamic() const { return false; };
|
||||
virtual bool
|
||||
isDynamic() const
|
||||
{
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
inline NodeID
|
||||
|
@ -232,7 +238,7 @@ DataTree::AddUnaryOp(UnaryOpcode op_code, NodeID arg, int arg_exp_info_set)
|
|||
double val = UnaryOpNode::eval_opcode(op_code, argval);
|
||||
return AddPossiblyNegativeConstant(val);
|
||||
}
|
||||
catch(ExprNode::EvalException &e)
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +260,7 @@ DataTree::AddBinaryOp(NodeID arg1, BinaryOpcode op_code, NodeID arg2)
|
|||
double val = BinaryOpNode::eval_opcode(argval1, op_code, argval2);
|
||||
return AddPossiblyNegativeConstant(val);
|
||||
}
|
||||
catch(ExprNode::EvalException &e)
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
}
|
||||
return new BinaryOpNode(*this, arg1, op_code, arg2);
|
||||
|
@ -276,7 +282,7 @@ DataTree::AddTrinaryOp(NodeID arg1, TrinaryOpcode op_code, NodeID arg2, NodeID a
|
|||
double val = TrinaryOpNode::eval_opcode(argval1, op_code, argval2, argval3);
|
||||
return AddPossiblyNegativeConstant(val);
|
||||
}
|
||||
catch(ExprNode::EvalException &e)
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
}
|
||||
return new TrinaryOpNode(*this, arg1, op_code, arg2, arg3);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -143,7 +143,7 @@ private:
|
|||
|
||||
//! Helper for writing the sparse Hessian or third derivatives in MATLAB and C
|
||||
/*! If order=2, writes either v2(i+1,j+1) or v2[i+j*NNZDerivatives[1]]
|
||||
If order=3, writes either v3(i+1,j+1) or v3[i+j*NNZDerivatives[2]] */
|
||||
If order=3, writes either v3(i+1,j+1) or v3[i+j*NNZDerivatives[2]] */
|
||||
void sparseHelper(int order, ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
|
||||
|
||||
//! Write chain rule derivative of a recursive equation w.r. to a variable
|
||||
|
@ -152,12 +152,10 @@ private:
|
|||
//! Collecte the derivatives w.r. to endogenous of the block, to endogenous of previouys blocks and to exogenous
|
||||
void collect_block_first_order_derivatives();
|
||||
|
||||
|
||||
//! Factorized code for substitutions of leads/lags
|
||||
/*! \param[in] type determines which type of variables is concerned */
|
||||
void substituteLeadLagInternal(aux_var_t type);
|
||||
|
||||
|
||||
private:
|
||||
//! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true
|
||||
bool global_temporary_terms;
|
||||
|
@ -202,10 +200,10 @@ public:
|
|||
double cutoff;
|
||||
//! 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 */
|
||||
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;
|
||||
|
@ -241,7 +239,11 @@ public:
|
|||
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
|
||||
|
||||
//! Returns true indicating that this is a dynamic model
|
||||
virtual bool isDynamic() const { return true; };
|
||||
virtual bool
|
||||
isDynamic() const
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
//! Transforms the model by removing all leads greater or equal than 2 on endos
|
||||
/*! Note that this can create new lags on endos and exos */
|
||||
|
@ -266,38 +268,96 @@ public:
|
|||
//! Fills eval context with values of model local variables and auxiliary variables
|
||||
void fillEvalContext(eval_context_type &eval_context) const;
|
||||
|
||||
|
||||
//! Return the number of blocks
|
||||
virtual unsigned int getNbBlocks() const {return(block_type_firstequation_size_mfs.size());};
|
||||
virtual unsigned int
|
||||
getNbBlocks() const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs.size());
|
||||
};
|
||||
//! Determine the simulation type of each block
|
||||
virtual BlockSimulationType getBlockSimulationType(int block_number) const {return(block_type_firstequation_size_mfs[block_number].first.first);};
|
||||
virtual BlockSimulationType
|
||||
getBlockSimulationType(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].first.first);
|
||||
};
|
||||
//! Return the first equation number of a block
|
||||
virtual unsigned int getBlockFirstEquation(int block_number) const {return(block_type_firstequation_size_mfs[block_number].first.second);};
|
||||
virtual unsigned int
|
||||
getBlockFirstEquation(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].first.second);
|
||||
};
|
||||
//! Return the size of the block block_number
|
||||
virtual unsigned int getBlockSize(int block_number) const {return(block_type_firstequation_size_mfs[block_number].second.first);};
|
||||
virtual unsigned int
|
||||
getBlockSize(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].second.first);
|
||||
};
|
||||
//! Return the number of feedback variable of the block block_number
|
||||
virtual unsigned int getBlockMfs(int block_number) const {return(block_type_firstequation_size_mfs[block_number].second.second);};
|
||||
virtual unsigned int
|
||||
getBlockMfs(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].second.second);
|
||||
};
|
||||
//! Return the maximum lag in a block
|
||||
virtual unsigned int getBlockMaxLag(int block_number) const {return(block_lag_lead[block_number].first);};
|
||||
virtual unsigned int
|
||||
getBlockMaxLag(int block_number) const
|
||||
{
|
||||
return (block_lag_lead[block_number].first);
|
||||
};
|
||||
//! Return the maximum lead in a block
|
||||
virtual unsigned int getBlockMaxLead(int block_number) const {return(block_lag_lead[block_number].second);};
|
||||
virtual unsigned int
|
||||
getBlockMaxLead(int block_number) const
|
||||
{
|
||||
return (block_lag_lead[block_number].second);
|
||||
};
|
||||
//! Return the type of equation (equation_number) belonging to the block block_number
|
||||
virtual EquationType getBlockEquationType(int block_number, int equation_number) const {return( equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first);};
|
||||
virtual EquationType
|
||||
getBlockEquationType(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first);
|
||||
};
|
||||
//! Return true if the equation has been normalized
|
||||
virtual bool isBlockEquationRenormalized(int block_number, int equation_number) const {return( equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first == E_EVALUATE_S);};
|
||||
virtual bool
|
||||
isBlockEquationRenormalized(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first == E_EVALUATE_S);
|
||||
};
|
||||
//! Return the NodeID of the equation equation_number belonging to the block block_number
|
||||
virtual NodeID getBlockEquationNodeID(int block_number, int equation_number) const {return( equations[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]]);};
|
||||
virtual NodeID
|
||||
getBlockEquationNodeID(int block_number, int equation_number) const
|
||||
{
|
||||
return (equations[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]]);
|
||||
};
|
||||
//! Return the NodeID of the renormalized equation equation_number belonging to the block block_number
|
||||
virtual NodeID getBlockEquationRenormalizedNodeID(int block_number, int equation_number) const {return( equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].second);};
|
||||
virtual NodeID
|
||||
getBlockEquationRenormalizedNodeID(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].second);
|
||||
};
|
||||
//! Return the original number of equation equation_number belonging to the block block_number
|
||||
virtual int getBlockEquationID(int block_number, int equation_number) const {return( equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]);};
|
||||
virtual int
|
||||
getBlockEquationID(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]);
|
||||
};
|
||||
//! Return the original number of variable variable_number belonging to the block block_number
|
||||
virtual int getBlockVariableID(int block_number, int variable_number) const {return( variable_reordered[block_type_firstequation_size_mfs[block_number].first.second+variable_number]);};
|
||||
virtual int
|
||||
getBlockVariableID(int block_number, int variable_number) const
|
||||
{
|
||||
return (variable_reordered[block_type_firstequation_size_mfs[block_number].first.second+variable_number]);
|
||||
};
|
||||
//! Return the position of equation_number in the block number belonging to the block block_number
|
||||
virtual int getBlockInitialEquationID(int block_number, int equation_number) const {return((int)inv_equation_reordered[equation_number] - (int)block_type_firstequation_size_mfs[block_number].first.second);};
|
||||
virtual int
|
||||
getBlockInitialEquationID(int block_number, int equation_number) const
|
||||
{
|
||||
return ((int) inv_equation_reordered[equation_number] - (int) block_type_firstequation_size_mfs[block_number].first.second);
|
||||
};
|
||||
//! Return the position of variable_number in the block number belonging to the block block_number
|
||||
virtual int getBlockInitialVariableID(int block_number, int variable_number) const {return((int)inv_variable_reordered[variable_number] - (int)block_type_firstequation_size_mfs[block_number].first.second);};
|
||||
|
||||
virtual int
|
||||
getBlockInitialVariableID(int block_number, int variable_number) const
|
||||
{
|
||||
return ((int) inv_variable_reordered[variable_number] - (int) block_type_firstequation_size_mfs[block_number].first.second);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ using namespace std;
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#ifndef PACKAGE_VERSION
|
||||
#define PACKAGE_VERSION 4.
|
||||
# define PACKAGE_VERSION 4.
|
||||
#endif
|
||||
#include "macro/MacroDriver.hh"
|
||||
|
||||
|
@ -36,9 +36,9 @@ using namespace std;
|
|||
*/
|
||||
void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool warn_uninit
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
, bool cygwin, bool msvc
|
||||
, bool cygwin, bool msvc
|
||||
#endif
|
||||
);
|
||||
);
|
||||
|
||||
void
|
||||
usage()
|
||||
|
@ -52,7 +52,7 @@ usage()
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
@ -150,7 +150,7 @@ main(int argc, char** argv)
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
, cygwin, msvc
|
||||
#endif
|
||||
);
|
||||
);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
|
|||
// Write outputs
|
||||
mod_file->writeOutputFiles(basename, clear_all
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
, cygwin, msvc
|
||||
, cygwin, msvc
|
||||
#endif
|
||||
);
|
||||
);
|
||||
|
||||
delete mod_file;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -47,7 +47,7 @@ typedef set<NodeID, ExprNodeLess> temporary_terms_type;
|
|||
//! set of temporary terms used in a block
|
||||
typedef set<int> temporary_terms_inuse_type;
|
||||
|
||||
typedef map<int,int> map_idx_type;
|
||||
typedef map<int, int> map_idx_type;
|
||||
|
||||
//! Type for evaluation contexts
|
||||
/*! The key is a symbol id. Lags are assumed to be null */
|
||||
|
@ -63,11 +63,11 @@ enum ExprNodeOutputType
|
|||
oCDynamicModel, //!< C code, dynamic model declarations
|
||||
oMatlabOutsideModel, //!< Matlab code, outside model block (for example in initval)
|
||||
oLatexStaticModel, //!< LaTeX code, static model declarations
|
||||
oLatexDynamicModel, //!< LaTeX code, dynamic model declarations
|
||||
oLatexDynamicModel, //!< LaTeX code, dynamic model declarations
|
||||
oLatexDynamicSteadyStateOperator, //!< LaTeX code, dynamic model steady state declarations
|
||||
oMatlabDynamicSteadyStateOperator, //!< Matlab code, dynamic model steady state declarations
|
||||
oMatlabDynamicModelSparseSteadyStateOperator, //!< Matlab code, dynamic block decomposed model steady state declarations
|
||||
oMatlabDynamicModelSparseLocalTemporaryTerms //!< Matlab code, dynamic block decomposed model local temporary_terms
|
||||
oMatlabDynamicSteadyStateOperator, //!< Matlab code, dynamic model steady state declarations
|
||||
oMatlabDynamicModelSparseSteadyStateOperator, //!< Matlab code, dynamic block decomposed model steady state declarations
|
||||
oMatlabDynamicModelSparseLocalTemporaryTerms //!< Matlab code, dynamic block decomposed model local temporary_terms
|
||||
};
|
||||
|
||||
#define IS_MATLAB(output_type) ((output_type) == oMatlabStaticModel \
|
||||
|
@ -76,14 +76,14 @@ enum ExprNodeOutputType
|
|||
|| (output_type) == oMatlabStaticModelSparse \
|
||||
|| (output_type) == oMatlabDynamicModelSparse \
|
||||
|| (output_type) == oMatlabDynamicModelSparseLocalTemporaryTerms \
|
||||
|| (output_type) == oMatlabDynamicSteadyStateOperator \
|
||||
|| (output_type) == oMatlabDynamicModelSparseSteadyStateOperator)
|
||||
|| (output_type) == oMatlabDynamicSteadyStateOperator \
|
||||
|| (output_type) == oMatlabDynamicModelSparseSteadyStateOperator)
|
||||
|
||||
#define IS_C(output_type) ((output_type) == oCDynamicModel)
|
||||
|
||||
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|
||||
|| (output_type) == oLatexDynamicModel \
|
||||
|| (output_type) == oLatexDynamicSteadyStateOperator)
|
||||
|| (output_type) == oLatexDynamicModel \
|
||||
|| (output_type) == oLatexDynamicSteadyStateOperator)
|
||||
|
||||
/* Equal to 1 for Matlab langage, or to 0 for C language. Not defined for LaTeX.
|
||||
In Matlab, array indexes begin at 1, while they begin at 0 in C */
|
||||
|
@ -278,7 +278,7 @@ public:
|
|||
- if this expr is not in the table, then it will create an auxiliary endogenous variable, add the substitution in the table and return the substituted expression
|
||||
|
||||
\return A new equivalent expression where sub-expressions with max endo lead >= 2 have been replaced by auxiliary variables
|
||||
*/
|
||||
*/
|
||||
virtual NodeID substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const = 0;
|
||||
|
||||
//! Constructs a new expression where endo variables with max endo lag >= 2 have been replaced by auxiliary variables
|
||||
|
@ -316,7 +316,8 @@ public:
|
|||
//! Object used to compare two nodes (using their indexes)
|
||||
struct ExprNodeLess
|
||||
{
|
||||
bool operator()(NodeID arg1, NodeID arg2) const
|
||||
bool
|
||||
operator()(NodeID arg1, NodeID arg2) const
|
||||
{
|
||||
return arg1->idx < arg2->idx;
|
||||
}
|
||||
|
@ -332,7 +333,11 @@ private:
|
|||
virtual NodeID computeDerivative(int deriv_id);
|
||||
public:
|
||||
NumConstNode(DataTree &datatree_arg, int id_arg);
|
||||
int get_id() const { return id; };
|
||||
int
|
||||
get_id() const
|
||||
{
|
||||
return id;
|
||||
};
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
|
@ -377,7 +382,11 @@ public:
|
|||
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, bool dynamic, bool steady_dynamic) const;
|
||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||
int get_symb_id() const { return symb_id; };
|
||||
int
|
||||
get_symb_id() const
|
||||
{
|
||||
return symb_id;
|
||||
};
|
||||
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);
|
||||
virtual int maxEndoLead() const;
|
||||
|
@ -420,9 +429,17 @@ public:
|
|||
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, bool dynamic, bool steady_dynamic) const;
|
||||
//! Returns operand
|
||||
NodeID get_arg() const { return(arg); };
|
||||
NodeID
|
||||
get_arg() const
|
||||
{
|
||||
return (arg);
|
||||
};
|
||||
//! Returns op code
|
||||
UnaryOpcode get_op_code() const { return(op_code); };
|
||||
UnaryOpcode
|
||||
get_op_code() const
|
||||
{
|
||||
return (op_code);
|
||||
};
|
||||
virtual NodeID toStatic(DataTree &static_datatree) 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);
|
||||
|
@ -469,11 +486,23 @@ public:
|
|||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_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); };
|
||||
NodeID
|
||||
get_arg1() const
|
||||
{
|
||||
return (arg1);
|
||||
};
|
||||
//! Returns second operand
|
||||
NodeID get_arg2() const { return(arg2); };
|
||||
NodeID
|
||||
get_arg2() const
|
||||
{
|
||||
return (arg2);
|
||||
};
|
||||
//! Returns op code
|
||||
BinaryOpcode get_op_code() const { return(op_code); };
|
||||
BinaryOpcode
|
||||
get_op_code() const
|
||||
{
|
||||
return (op_code);
|
||||
};
|
||||
virtual NodeID toStatic(DataTree &static_datatree) 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);
|
||||
|
@ -503,7 +532,7 @@ private:
|
|||
NodeID composeDerivatives(NodeID darg1, NodeID darg2, NodeID darg3);
|
||||
public:
|
||||
TrinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
||||
TrinaryOpcode op_code_arg, const NodeID arg2_arg, const NodeID arg3_arg);
|
||||
TrinaryOpcode op_code_arg, const NodeID arg2_arg, const NodeID arg3_arg);
|
||||
virtual void prepareForDerivation();
|
||||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||
|
|
|
@ -22,477 +22,470 @@
|
|||
#include "MinimumFeedbackSet.hh"
|
||||
|
||||
namespace MFS
|
||||
{
|
||||
void
|
||||
Suppress(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type &G)
|
||||
{
|
||||
void
|
||||
Suppress(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type& G)
|
||||
{
|
||||
clear_vertex(vertex_to_eliminate, G);
|
||||
remove_vertex(vertex_to_eliminate, G);
|
||||
}
|
||||
clear_vertex(vertex_to_eliminate, G);
|
||||
remove_vertex(vertex_to_eliminate, G);
|
||||
}
|
||||
|
||||
void
|
||||
Suppress(int vertex_num, AdjacencyList_type &G)
|
||||
{
|
||||
Suppress(vertex(vertex_num, G), G);
|
||||
}
|
||||
|
||||
void
|
||||
Suppress(int vertex_num, AdjacencyList_type& G)
|
||||
{
|
||||
Suppress(vertex(vertex_num, G), G);
|
||||
}
|
||||
void
|
||||
Eliminate(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type &G)
|
||||
{
|
||||
if (in_degree(vertex_to_eliminate, G) > 0 && out_degree(vertex_to_eliminate, G) > 0)
|
||||
{
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
for (tie(it_in, in_end) = in_edges(vertex_to_eliminate, G); it_in != in_end; ++it_in)
|
||||
for (tie(it_out, out_end) = out_edges(vertex_to_eliminate, G); it_out != out_end; ++it_out)
|
||||
{
|
||||
AdjacencyList_type::edge_descriptor ed;
|
||||
bool exist;
|
||||
tie(ed, exist) = edge(source(*it_in, G), target(*it_out, G), G);
|
||||
if (!exist)
|
||||
add_edge(source(*it_in, G), target(*it_out, G), G);
|
||||
}
|
||||
}
|
||||
Suppress(vertex_to_eliminate, G);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Eliminate(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type& G)
|
||||
{
|
||||
if (in_degree (vertex_to_eliminate, G) > 0 && out_degree (vertex_to_eliminate, G) > 0)
|
||||
bool
|
||||
has_cycle_dfs(AdjacencyList_type &g, AdjacencyList_type::vertex_descriptor u, color_type &color, vector<int> &circuit_stack)
|
||||
{
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, g);
|
||||
color[u] = gray_color;
|
||||
graph_traits<AdjacencyList_type>::out_edge_iterator vi, vi_end;
|
||||
for (tie(vi, vi_end) = out_edges(u, g); vi != vi_end; ++vi)
|
||||
if (color[target(*vi, g)] == white_color && has_cycle_dfs(g, target(*vi, g), color, circuit_stack))
|
||||
{
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
for (tie(it_in, in_end) = in_edges(vertex_to_eliminate, G); it_in != in_end; ++it_in)
|
||||
for (tie(it_out, out_end) = out_edges(vertex_to_eliminate, G); it_out != out_end; ++it_out)
|
||||
// cycle detected, return immediately
|
||||
circuit_stack.push_back(v_index[target(*vi, g)]);
|
||||
return true;
|
||||
}
|
||||
else if (color[target(*vi, g)] == gray_color)
|
||||
{
|
||||
// *vi is an ancestor!
|
||||
circuit_stack.push_back(v_index[target(*vi, g)]);
|
||||
return true;
|
||||
}
|
||||
color[u] = black_color;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
has_cycle(vector<int> &circuit_stack, AdjacencyList_type &g)
|
||||
{
|
||||
// Initialize color map to white
|
||||
color_type color;
|
||||
graph_traits<AdjacencyList_type>::vertex_iterator vi, vi_end;
|
||||
for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
|
||||
color[*vi] = white_color;
|
||||
|
||||
// Perform depth-first search
|
||||
for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
|
||||
if (color[*vi] == white_color && has_cycle_dfs(g, *vi, color, circuit_stack))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Print(AdjacencyList_type &G)
|
||||
{
|
||||
AdjacencyList_type::vertex_iterator it, it_end;
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "Graph\n";
|
||||
cout << "-----\n";
|
||||
for (tie(it, it_end) = vertices(G); it != it_end; ++it)
|
||||
{
|
||||
cout << "vertex[" << v_index[*it] + 1 << "] <-";
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
for (tie(it_in, in_end) = in_edges(*it, G); it_in != in_end; ++it_in)
|
||||
cout << v_index[source(*it_in, G)] + 1 << " ";
|
||||
cout << "\n ->";
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
for (tie(it_out, out_end) = out_edges(*it, G); it_out != out_end; ++it_out)
|
||||
cout << v_index[target(*it_out, G)] + 1 << " ";
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
AdjacencyList_type
|
||||
AM_2_AdjacencyList(bool *AM, unsigned int n)
|
||||
{
|
||||
AdjacencyList_type G(n);
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
{
|
||||
put(v_index, vertex(i, G), i);
|
||||
put(v_index1, vertex(i, G), i);
|
||||
}
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
for (unsigned int j = 0; j < n; j++)
|
||||
if (AM[i*n+j])
|
||||
add_edge(vertex(j, G), vertex(i, G), G);
|
||||
return G;
|
||||
}
|
||||
|
||||
void
|
||||
Print(GraphvizDigraph &G)
|
||||
{
|
||||
GraphvizDigraph::vertex_iterator it, it_end;
|
||||
property_map<GraphvizDigraph, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "Graph\n";
|
||||
cout << "-----\n";
|
||||
for (tie(it, it_end) = vertices(G); it != it_end; ++it)
|
||||
{
|
||||
cout << "vertex[" << v_index[*it] + 1 << "] ->";
|
||||
GraphvizDigraph::out_edge_iterator it_out, out_end;
|
||||
for (tie(it_out, out_end) = out_edges(*it, G); it_out != out_end; ++it_out)
|
||||
cout << v_index[target(*it_out, G)] + 1 << " ";
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
GraphvizDigraph
|
||||
AM_2_GraphvizDigraph(bool *AM, unsigned int n)
|
||||
{
|
||||
GraphvizDigraph G(n);
|
||||
property_map<GraphvizDigraph, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
/*for (unsigned int i = 0;i < n;i++)
|
||||
cout << "v_index[" << i << "] = " << v_index[i] << "\n";*/
|
||||
//put(v_index, vertex(i, G), i);
|
||||
//v_index[/*vertex(i,G)*/i]["v_index"]=i;
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
for (unsigned int j = 0; j < n; j++)
|
||||
if (AM[i*n+j])
|
||||
add_edge(vertex(j, G), vertex(i, G), G);
|
||||
return G;
|
||||
}
|
||||
|
||||
AdjacencyList_type
|
||||
GraphvizDigraph_2_AdjacencyList(GraphvizDigraph &G1, set<int> select_index)
|
||||
{
|
||||
unsigned int n = select_index.size();
|
||||
AdjacencyList_type G(n);
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
property_map<GraphvizDigraph, vertex_index_t>::type v1_index = get(vertex_index, G1);
|
||||
set<int>::iterator it = select_index.begin();
|
||||
map<int, int> reverse_index;
|
||||
for (unsigned int i = 0; i < n; i++, ++it)
|
||||
{
|
||||
reverse_index[v1_index[*it]] = i;
|
||||
put(v_index, vertex(i, G), v1_index[*it]);
|
||||
put(v_index1, vertex(i, G), i);
|
||||
}
|
||||
unsigned int i;
|
||||
for (it = select_index.begin(), i = 0; i < n; i++, ++it)
|
||||
{
|
||||
GraphvizDigraph::out_edge_iterator it_out, out_end;
|
||||
GraphvizDigraph::vertex_descriptor vi = vertex(*it, G1);
|
||||
for (tie(it_out, out_end) = out_edges(vi, G1); it_out != out_end; ++it_out)
|
||||
{
|
||||
int ii = target(*it_out, G1);
|
||||
if (select_index.find(ii) != select_index.end())
|
||||
add_edge(vertex(reverse_index[source(*it_out, G1)], G), vertex(reverse_index[target(*it_out, G1)], G), G);
|
||||
}
|
||||
}
|
||||
return G;
|
||||
}
|
||||
|
||||
vector_vertex_descriptor
|
||||
Collect_Doublet(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type &G)
|
||||
{
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
vector<AdjacencyList_type::vertex_descriptor> Doublet;
|
||||
if (in_degree(vertex, G) > 0 && out_degree(vertex, G) > 0)
|
||||
for (tie(it_in, in_end) = in_edges(vertex, G); it_in != in_end; ++it_in)
|
||||
for (tie(it_out, out_end) = out_edges(vertex, G); it_out != out_end; ++it_out)
|
||||
if (source(*it_in, G) == target(*it_out, G) && source(*it_in, G) != target(*it_in, G)) // not a loop
|
||||
Doublet.push_back(source(*it_in, G));
|
||||
return Doublet;
|
||||
}
|
||||
|
||||
bool
|
||||
Vertex_Belong_to_a_Clique(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type &G)
|
||||
{
|
||||
vector<AdjacencyList_type::vertex_descriptor> liste;
|
||||
bool agree = true;
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
tie(it_in, in_end) = in_edges(vertex, G);
|
||||
tie(it_out, out_end) = out_edges(vertex, G);
|
||||
while (it_in != in_end && it_out != out_end && agree)
|
||||
{
|
||||
agree = (source(*it_in, G) == target(*it_out, G) && source(*it_in, G) != target(*it_in, G)); //not a loop
|
||||
liste.push_back(source(*it_in, G));
|
||||
++it_in;
|
||||
++it_out;
|
||||
}
|
||||
if (agree)
|
||||
{
|
||||
if (it_in != in_end || it_out != out_end)
|
||||
agree = false;
|
||||
unsigned int i = 1;
|
||||
while (i < liste.size() && agree)
|
||||
{
|
||||
unsigned int j = i + 1;
|
||||
while (j < liste.size() && agree)
|
||||
{
|
||||
AdjacencyList_type::edge_descriptor ed;
|
||||
bool exist;
|
||||
tie(ed, exist) = edge(source(*it_in, G) , target(*it_out, G), G);
|
||||
if (!exist)
|
||||
add_edge(source(*it_in, G) , target(*it_out, G), G);
|
||||
bool exist1, exist2;
|
||||
tie(ed, exist1) = edge(liste[i], liste[j], G);
|
||||
tie(ed, exist2) = edge(liste[j], liste[i], G);
|
||||
agree = (exist1 && exist2);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
Suppress(vertex_to_eliminate, G);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
has_cycle_dfs(AdjacencyList_type& g, AdjacencyList_type::vertex_descriptor u, color_type& color, vector<int> &circuit_stack)
|
||||
{
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, g);
|
||||
color[u] = gray_color;
|
||||
graph_traits<AdjacencyList_type>::out_edge_iterator vi, vi_end;
|
||||
for (tie(vi, vi_end) = out_edges(u, g); vi != vi_end; ++vi)
|
||||
if (color[target(*vi, g)] == white_color && has_cycle_dfs(g, target(*vi, g), color, circuit_stack))
|
||||
{
|
||||
// cycle detected, return immediately
|
||||
circuit_stack.push_back(v_index[target(*vi, g)]);
|
||||
return true;
|
||||
i++;
|
||||
}
|
||||
else if (color[target(*vi, g)] == gray_color)
|
||||
{
|
||||
// *vi is an ancestor!
|
||||
circuit_stack.push_back(v_index[target(*vi, g)]);
|
||||
return true;
|
||||
}
|
||||
color[u] = black_color;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
has_cycle(vector<int> &circuit_stack, AdjacencyList_type& g)
|
||||
{
|
||||
// Initialize color map to white
|
||||
color_type color;
|
||||
graph_traits<AdjacencyList_type>::vertex_iterator vi, vi_end;
|
||||
for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
|
||||
color[*vi] = white_color;
|
||||
|
||||
// Perform depth-first search
|
||||
for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
|
||||
if (color[*vi] == white_color && has_cycle_dfs(g, *vi, color, circuit_stack))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Print(AdjacencyList_type& G)
|
||||
{
|
||||
AdjacencyList_type::vertex_iterator it, it_end;
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "Graph\n";
|
||||
cout << "-----\n";
|
||||
for (tie(it, it_end) = vertices(G);it != it_end; ++it)
|
||||
{
|
||||
cout << "vertex[" << v_index[*it] + 1 << "] <-";
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
for (tie(it_in, in_end) = in_edges(*it, G); it_in != in_end; ++it_in)
|
||||
cout << v_index[source(*it_in, G)] + 1 << " ";
|
||||
cout << "\n ->";
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
for (tie(it_out, out_end) = out_edges(*it, G); it_out != out_end; ++it_out)
|
||||
cout << v_index[target(*it_out, G)] + 1 << " ";
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AdjacencyList_type
|
||||
AM_2_AdjacencyList(bool* AM, unsigned int n)
|
||||
{
|
||||
AdjacencyList_type G(n);
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
for (unsigned int i = 0;i < n;i++)
|
||||
{
|
||||
put(v_index, vertex(i, G), i);
|
||||
put(v_index1, vertex(i, G), i);
|
||||
}
|
||||
for (unsigned int i = 0;i < n;i++)
|
||||
for (unsigned int j = 0;j < n;j++)
|
||||
if (AM[i*n+j])
|
||||
add_edge(vertex(j, G), vertex(i, G), G);
|
||||
return G;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Print(GraphvizDigraph& G)
|
||||
{
|
||||
GraphvizDigraph::vertex_iterator it, it_end;
|
||||
property_map<GraphvizDigraph, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "Graph\n";
|
||||
cout << "-----\n";
|
||||
for (tie(it, it_end) = vertices(G);it != it_end; ++it)
|
||||
{
|
||||
cout << "vertex[" << v_index[*it] + 1 << "] ->";
|
||||
GraphvizDigraph::out_edge_iterator it_out, out_end;
|
||||
for (tie(it_out, out_end) = out_edges(*it, G); it_out != out_end; ++it_out)
|
||||
cout << v_index[target(*it_out, G)] + 1 << " ";
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GraphvizDigraph
|
||||
AM_2_GraphvizDigraph(bool* AM, unsigned int n)
|
||||
{
|
||||
GraphvizDigraph G(n);
|
||||
property_map<GraphvizDigraph, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
/*for (unsigned int i = 0;i < n;i++)
|
||||
cout << "v_index[" << i << "] = " << v_index[i] << "\n";*/
|
||||
//put(v_index, vertex(i, G), i);
|
||||
//v_index[/*vertex(i,G)*/i]["v_index"]=i;
|
||||
for (unsigned int i = 0;i < n;i++)
|
||||
for (unsigned int j = 0;j < n;j++)
|
||||
if (AM[i*n+j])
|
||||
add_edge(vertex(j, G), vertex(i, G), G);
|
||||
return G;
|
||||
}
|
||||
|
||||
|
||||
AdjacencyList_type
|
||||
GraphvizDigraph_2_AdjacencyList(GraphvizDigraph& G1, set<int> select_index)
|
||||
{
|
||||
unsigned int n = select_index.size();
|
||||
AdjacencyList_type G(n);
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
property_map<GraphvizDigraph, vertex_index_t>::type v1_index = get(vertex_index, G1);
|
||||
set<int>::iterator it = select_index.begin();
|
||||
map<int,int> reverse_index;
|
||||
for (unsigned int i = 0;i < n;i++, ++it)
|
||||
{
|
||||
reverse_index[v1_index[*it]]=i;
|
||||
put(v_index, vertex(i, G), v1_index[*it]);
|
||||
put(v_index1, vertex(i, G), i);
|
||||
}
|
||||
unsigned int i;
|
||||
for (it = select_index.begin(), i = 0;i < n;i++, ++it)
|
||||
{
|
||||
GraphvizDigraph::out_edge_iterator it_out, out_end;
|
||||
GraphvizDigraph::vertex_descriptor vi = vertex(*it, G1);
|
||||
for (tie(it_out, out_end) = out_edges(vi, G1); it_out != out_end; ++it_out)
|
||||
{
|
||||
int ii = target(*it_out, G1);
|
||||
if (select_index.find(ii) != select_index.end())
|
||||
add_edge( vertex(reverse_index[source(*it_out, G1)],G), vertex(reverse_index[target(*it_out, G1)], G), G);
|
||||
}
|
||||
}
|
||||
return G;
|
||||
}
|
||||
|
||||
vector_vertex_descriptor
|
||||
Collect_Doublet(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type& G)
|
||||
{
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
vector<AdjacencyList_type::vertex_descriptor> Doublet;
|
||||
if (in_degree(vertex, G) > 0 && out_degree(vertex, G) > 0)
|
||||
for (tie(it_in, in_end) = in_edges(vertex, G); it_in != in_end; ++it_in)
|
||||
for (tie(it_out, out_end) = out_edges(vertex, G); it_out != out_end; ++it_out)
|
||||
if (source(*it_in, G) == target(*it_out, G) && source(*it_in, G) != target(*it_in, G)) // not a loop
|
||||
Doublet.push_back(source(*it_in, G));
|
||||
return Doublet;
|
||||
}
|
||||
|
||||
bool
|
||||
Vertex_Belong_to_a_Clique(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type& G)
|
||||
{
|
||||
vector<AdjacencyList_type::vertex_descriptor> liste;
|
||||
bool agree = true;
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
AdjacencyList_type::out_edge_iterator it_out, out_end;
|
||||
tie(it_in, in_end) = in_edges(vertex, G);
|
||||
tie(it_out, out_end) = out_edges(vertex, G);
|
||||
while (it_in != in_end && it_out != out_end && agree)
|
||||
{
|
||||
agree = (source(*it_in, G) == target(*it_out, G) && source(*it_in, G) != target(*it_in, G)); //not a loop
|
||||
liste.push_back(source(*it_in, G));
|
||||
++it_in;
|
||||
++it_out;
|
||||
}
|
||||
if (agree)
|
||||
{
|
||||
if (it_in != in_end || it_out != out_end)
|
||||
agree = false;
|
||||
unsigned int i = 1;
|
||||
while (i < liste.size() && agree)
|
||||
{
|
||||
unsigned int j = i + 1;
|
||||
while (j < liste.size() && agree)
|
||||
{
|
||||
AdjacencyList_type::edge_descriptor ed;
|
||||
bool exist1, exist2;
|
||||
tie(ed, exist1) = edge(liste[i], liste[j] , G);
|
||||
tie(ed, exist2) = edge(liste[j], liste[i] , G);
|
||||
agree = (exist1 && exist2);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return agree;
|
||||
}
|
||||
|
||||
bool
|
||||
Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(AdjacencyList_type& G)
|
||||
{
|
||||
bool something_has_been_done = false;
|
||||
bool not_a_loop;
|
||||
int i;
|
||||
AdjacencyList_type::vertex_iterator it, it1, ita, it_end;
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
for (tie(it, it_end) = vertices(G), i = 0; it != it_end; ++it, i++)
|
||||
{
|
||||
int in_degree_n = in_degree(*it, G);
|
||||
int out_degree_n = out_degree(*it, G);
|
||||
if (in_degree_n <= 1 || out_degree_n <= 1)
|
||||
{
|
||||
not_a_loop = true;
|
||||
if (in_degree_n >= 1 && out_degree_n >= 1) // Do not eliminate a vertex if it loops on itself!
|
||||
{
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
for (tie(it_in, in_end) = in_edges(*it, G); it_in != in_end; ++it_in)
|
||||
if (source(*it_in, G) == target(*it_in, G))
|
||||
{
|
||||
#ifdef verbose
|
||||
cout << v_index[source(*it_in, G)] << " == " << v_index[target(*it_in, G)] << "\n";
|
||||
#endif
|
||||
not_a_loop = false;
|
||||
}
|
||||
}
|
||||
if (not_a_loop)
|
||||
{
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "->eliminate vertex[" << v_index[*it] + 1 << "]\n";
|
||||
#endif
|
||||
Eliminate(*it, G);
|
||||
#ifdef verbose
|
||||
Print(G);
|
||||
#endif
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
return something_has_been_done;
|
||||
}
|
||||
|
||||
bool
|
||||
Elimination_of_Vertex_belonging_to_a_clique_Step(AdjacencyList_type& G)
|
||||
{
|
||||
AdjacencyList_type::vertex_iterator it, it1, ita, it_end;
|
||||
bool something_has_been_done = false;
|
||||
int i;
|
||||
for (tie(it, it_end) = vertices(G), i = 0; it != it_end; ++it, i++)
|
||||
{
|
||||
if (Vertex_Belong_to_a_Clique(*it, G))
|
||||
{
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "eliminate vertex[" << v_index[*it] + 1 << "]\n";
|
||||
#endif
|
||||
Eliminate(*it, G);
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
return something_has_been_done;
|
||||
}
|
||||
|
||||
bool
|
||||
Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(set<int> &feed_back_vertices, AdjacencyList_type& G)
|
||||
{
|
||||
bool something_has_been_done = false;
|
||||
AdjacencyList_type::vertex_iterator it, it_end, ita;
|
||||
int i = 0;
|
||||
for (tie(it, it_end) = vertices(G); it != it_end; ++it, i++)
|
||||
{
|
||||
AdjacencyList_type::edge_descriptor ed;
|
||||
bool exist;
|
||||
tie(ed, exist) = edge(*it, *it , G);
|
||||
if (exist)
|
||||
{
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "store v[*it] = " << v_index[*it]+1 << "\n";
|
||||
#endif
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
feed_back_vertices.insert(v_index1[*it] );
|
||||
/*property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
feed_back_vertices.insert(v_index[*it] );*/
|
||||
Suppress(*it, G);
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
return something_has_been_done;
|
||||
}
|
||||
|
||||
|
||||
AdjacencyList_type
|
||||
Minimal_set_of_feedback_vertex(set<int> &feed_back_vertices,const AdjacencyList_type& G1)
|
||||
{
|
||||
bool something_has_been_done = true;
|
||||
int cut_ = 0;
|
||||
feed_back_vertices.clear();
|
||||
AdjacencyList_type G(G1);
|
||||
while (num_vertices(G) > 0)
|
||||
{
|
||||
while (something_has_been_done && num_vertices(G) > 0)
|
||||
{
|
||||
//Rule 1
|
||||
something_has_been_done = (Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(G) /*or something_has_been_done*/);
|
||||
#ifdef verbose
|
||||
cout << "1 something_has_been_done=" << something_has_been_done << "\n";
|
||||
#endif
|
||||
|
||||
//Rule 2
|
||||
something_has_been_done = (Elimination_of_Vertex_belonging_to_a_clique_Step(G) || something_has_been_done);
|
||||
#ifdef verbose
|
||||
cout << "2 something_has_been_done=" << something_has_been_done << "\n";
|
||||
#endif
|
||||
|
||||
//Rule 3
|
||||
something_has_been_done = (Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(feed_back_vertices, G) || something_has_been_done);
|
||||
#ifdef verbose
|
||||
cout << "3 something_has_been_done=" << something_has_been_done << "\n";
|
||||
#endif
|
||||
}
|
||||
vector<int> circuit;
|
||||
if (!has_cycle(circuit, G))
|
||||
{
|
||||
#ifdef verbose
|
||||
cout << "has_cycle=false\n";
|
||||
#endif
|
||||
//sort(feed_back_vertices.begin(), feed_back_vertices.end());
|
||||
return G;
|
||||
}
|
||||
if (num_vertices(G) > 0)
|
||||
{
|
||||
/*if nothing has been done in the five previous rule then cut the vertex with the maximum in_degree+out_degree*/
|
||||
unsigned int max_degree = 0, num = 0;
|
||||
AdjacencyList_type::vertex_iterator it, it_end, max_degree_index;
|
||||
for (tie(it, it_end) = vertices(G);it != it_end; ++it, num++)
|
||||
{
|
||||
if (in_degree(*it, G) + out_degree(*it, G) > max_degree)
|
||||
{
|
||||
max_degree = in_degree(*it, G) + out_degree(*it, G);
|
||||
max_degree_index = it;
|
||||
}
|
||||
}
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
feed_back_vertices.insert(v_index1[*max_degree_index]);
|
||||
/*property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
feed_back_vertices.insert(v_index[*max_degree_index]);*/
|
||||
//cout << "v_index1[*max_degree_index] = " << v_index1[*max_degree_index] << "\n";
|
||||
cut_++;
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "--> cut vertex " << v_index[*max_degree_index] + 1 << "\n";
|
||||
#endif
|
||||
Suppress(*max_degree_index, G);
|
||||
something_has_been_done = true;
|
||||
}
|
||||
}
|
||||
#ifdef verbose
|
||||
cout << "cut_=" << cut_ << "\n";
|
||||
#endif
|
||||
//sort(feed_back_vertices.begin(), feed_back_vertices.end());
|
||||
return G;
|
||||
}
|
||||
|
||||
struct rev
|
||||
{
|
||||
bool operator()(const int a, const int b) const
|
||||
{
|
||||
return (a>b);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
Reorder_the_recursive_variables(const AdjacencyList_type& G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices)
|
||||
{
|
||||
AdjacencyList_type G(G1);
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
set<int>::iterator its, ita;
|
||||
set<int, rev> fv;
|
||||
for (its = feedback_vertices.begin(); its != feedback_vertices.end(); its++)
|
||||
fv.insert(*its);
|
||||
int i=0;
|
||||
for (its = fv.begin(); its != fv.end(); ++its, i++)
|
||||
Suppress(*its, G);
|
||||
bool something_has_been_done = true;
|
||||
while (something_has_been_done)
|
||||
{
|
||||
something_has_been_done = false;
|
||||
AdjacencyList_type::vertex_iterator it, it_end, ita;
|
||||
for (tie(it, it_end) = vertices(G), i = 0; it != it_end; ++it, i++)
|
||||
{
|
||||
if (in_degree(*it, G) == 0)
|
||||
{
|
||||
Reordered_Vertices.push_back(v_index[*it]);
|
||||
Suppress(*it, G);
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
}
|
||||
if (num_vertices(G))
|
||||
cout << "Error in the computation of feedback vertex set\n";
|
||||
}
|
||||
}
|
||||
return agree;
|
||||
}
|
||||
|
||||
bool
|
||||
Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(AdjacencyList_type &G)
|
||||
{
|
||||
bool something_has_been_done = false;
|
||||
bool not_a_loop;
|
||||
int i;
|
||||
AdjacencyList_type::vertex_iterator it, it1, ita, it_end;
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
for (tie(it, it_end) = vertices(G), i = 0; it != it_end; ++it, i++)
|
||||
{
|
||||
int in_degree_n = in_degree(*it, G);
|
||||
int out_degree_n = out_degree(*it, G);
|
||||
if (in_degree_n <= 1 || out_degree_n <= 1)
|
||||
{
|
||||
not_a_loop = true;
|
||||
if (in_degree_n >= 1 && out_degree_n >= 1) // Do not eliminate a vertex if it loops on itself!
|
||||
{
|
||||
AdjacencyList_type::in_edge_iterator it_in, in_end;
|
||||
for (tie(it_in, in_end) = in_edges(*it, G); it_in != in_end; ++it_in)
|
||||
if (source(*it_in, G) == target(*it_in, G))
|
||||
{
|
||||
#ifdef verbose
|
||||
cout << v_index[source(*it_in, G)] << " == " << v_index[target(*it_in, G)] << "\n";
|
||||
#endif
|
||||
not_a_loop = false;
|
||||
}
|
||||
}
|
||||
if (not_a_loop)
|
||||
{
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "->eliminate vertex[" << v_index[*it] + 1 << "]\n";
|
||||
#endif
|
||||
Eliminate(*it, G);
|
||||
#ifdef verbose
|
||||
Print(G);
|
||||
#endif
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
return something_has_been_done;
|
||||
}
|
||||
|
||||
bool
|
||||
Elimination_of_Vertex_belonging_to_a_clique_Step(AdjacencyList_type &G)
|
||||
{
|
||||
AdjacencyList_type::vertex_iterator it, it1, ita, it_end;
|
||||
bool something_has_been_done = false;
|
||||
int i;
|
||||
for (tie(it, it_end) = vertices(G), i = 0; it != it_end; ++it, i++)
|
||||
{
|
||||
if (Vertex_Belong_to_a_Clique(*it, G))
|
||||
{
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "eliminate vertex[" << v_index[*it] + 1 << "]\n";
|
||||
#endif
|
||||
Eliminate(*it, G);
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
return something_has_been_done;
|
||||
}
|
||||
|
||||
bool
|
||||
Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(set<int> &feed_back_vertices, AdjacencyList_type &G)
|
||||
{
|
||||
bool something_has_been_done = false;
|
||||
AdjacencyList_type::vertex_iterator it, it_end, ita;
|
||||
int i = 0;
|
||||
for (tie(it, it_end) = vertices(G); it != it_end; ++it, i++)
|
||||
{
|
||||
AdjacencyList_type::edge_descriptor ed;
|
||||
bool exist;
|
||||
tie(ed, exist) = edge(*it, *it, G);
|
||||
if (exist)
|
||||
{
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "store v[*it] = " << v_index[*it]+1 << "\n";
|
||||
#endif
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
feed_back_vertices.insert(v_index1[*it]);
|
||||
/*property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
feed_back_vertices.insert(v_index[*it] );*/
|
||||
Suppress(*it, G);
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
return something_has_been_done;
|
||||
}
|
||||
|
||||
AdjacencyList_type
|
||||
Minimal_set_of_feedback_vertex(set<int> &feed_back_vertices, const AdjacencyList_type &G1)
|
||||
{
|
||||
bool something_has_been_done = true;
|
||||
int cut_ = 0;
|
||||
feed_back_vertices.clear();
|
||||
AdjacencyList_type G(G1);
|
||||
while (num_vertices(G) > 0)
|
||||
{
|
||||
while (something_has_been_done && num_vertices(G) > 0)
|
||||
{
|
||||
//Rule 1
|
||||
something_has_been_done = (Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(G) /*or something_has_been_done*/);
|
||||
#ifdef verbose
|
||||
cout << "1 something_has_been_done=" << something_has_been_done << "\n";
|
||||
#endif
|
||||
|
||||
//Rule 2
|
||||
something_has_been_done = (Elimination_of_Vertex_belonging_to_a_clique_Step(G) || something_has_been_done);
|
||||
#ifdef verbose
|
||||
cout << "2 something_has_been_done=" << something_has_been_done << "\n";
|
||||
#endif
|
||||
|
||||
//Rule 3
|
||||
something_has_been_done = (Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(feed_back_vertices, G) || something_has_been_done);
|
||||
#ifdef verbose
|
||||
cout << "3 something_has_been_done=" << something_has_been_done << "\n";
|
||||
#endif
|
||||
}
|
||||
vector<int> circuit;
|
||||
if (!has_cycle(circuit, G))
|
||||
{
|
||||
#ifdef verbose
|
||||
cout << "has_cycle=false\n";
|
||||
#endif
|
||||
//sort(feed_back_vertices.begin(), feed_back_vertices.end());
|
||||
return G;
|
||||
}
|
||||
if (num_vertices(G) > 0)
|
||||
{
|
||||
/*if nothing has been done in the five previous rule then cut the vertex with the maximum in_degree+out_degree*/
|
||||
unsigned int max_degree = 0, num = 0;
|
||||
AdjacencyList_type::vertex_iterator it, it_end, max_degree_index;
|
||||
for (tie(it, it_end) = vertices(G); it != it_end; ++it, num++)
|
||||
{
|
||||
if (in_degree(*it, G) + out_degree(*it, G) > max_degree)
|
||||
{
|
||||
max_degree = in_degree(*it, G) + out_degree(*it, G);
|
||||
max_degree_index = it;
|
||||
}
|
||||
}
|
||||
property_map<AdjacencyList_type, vertex_index1_t>::type v_index1 = get(vertex_index1, G);
|
||||
feed_back_vertices.insert(v_index1[*max_degree_index]);
|
||||
/*property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
feed_back_vertices.insert(v_index[*max_degree_index]);*/
|
||||
//cout << "v_index1[*max_degree_index] = " << v_index1[*max_degree_index] << "\n";
|
||||
cut_++;
|
||||
#ifdef verbose
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
cout << "--> cut vertex " << v_index[*max_degree_index] + 1 << "\n";
|
||||
#endif
|
||||
Suppress(*max_degree_index, G);
|
||||
something_has_been_done = true;
|
||||
}
|
||||
}
|
||||
#ifdef verbose
|
||||
cout << "cut_=" << cut_ << "\n";
|
||||
#endif
|
||||
//sort(feed_back_vertices.begin(), feed_back_vertices.end());
|
||||
return G;
|
||||
}
|
||||
|
||||
struct rev
|
||||
{
|
||||
bool
|
||||
operator()(const int a, const int b) const
|
||||
{
|
||||
return (a > b);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
Reorder_the_recursive_variables(const AdjacencyList_type &G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices)
|
||||
{
|
||||
AdjacencyList_type G(G1);
|
||||
property_map<AdjacencyList_type, vertex_index_t>::type v_index = get(vertex_index, G);
|
||||
set<int>::iterator its, ita;
|
||||
set<int, rev> fv;
|
||||
for (its = feedback_vertices.begin(); its != feedback_vertices.end(); its++)
|
||||
fv.insert(*its);
|
||||
int i = 0;
|
||||
for (its = fv.begin(); its != fv.end(); ++its, i++)
|
||||
Suppress(*its, G);
|
||||
bool something_has_been_done = true;
|
||||
while (something_has_been_done)
|
||||
{
|
||||
something_has_been_done = false;
|
||||
AdjacencyList_type::vertex_iterator it, it_end, ita;
|
||||
for (tie(it, it_end) = vertices(G), i = 0; it != it_end; ++it, i++)
|
||||
{
|
||||
if (in_degree(*it, G) == 0)
|
||||
{
|
||||
Reordered_Vertices.push_back(v_index[*it]);
|
||||
Suppress(*it, G);
|
||||
something_has_been_done = true;
|
||||
if (i > 0)
|
||||
it = ita;
|
||||
else
|
||||
{
|
||||
tie(it, it_end) = vertices(G);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
ita = it;
|
||||
}
|
||||
}
|
||||
if (num_vertices(G))
|
||||
cout << "Error in the computation of feedback vertex set\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,49 +31,49 @@ using namespace boost;
|
|||
namespace MFS
|
||||
{
|
||||
typedef property<vertex_index_t, int,
|
||||
property<vertex_index1_t, int,
|
||||
property<vertex_degree_t, int,
|
||||
property<vertex_in_degree_t, int,
|
||||
property<vertex_out_degree_t, int > > > > > VertexProperty;
|
||||
property<vertex_index1_t, int,
|
||||
property<vertex_degree_t, int,
|
||||
property<vertex_in_degree_t, int,
|
||||
property<vertex_out_degree_t, int > > > > > VertexProperty;
|
||||
typedef adjacency_list<listS, listS, bidirectionalS, VertexProperty> AdjacencyList_type;
|
||||
typedef map<graph_traits<AdjacencyList_type>::vertex_descriptor,default_color_type> color_type;
|
||||
typedef map<graph_traits<AdjacencyList_type>::vertex_descriptor, default_color_type> color_type;
|
||||
typedef vector<AdjacencyList_type::vertex_descriptor> vector_vertex_descriptor;
|
||||
|
||||
//! Eliminate a vertex i
|
||||
/*! For a vertex i replace all edges e_k_i and e_i_j by a shorcut e_k_j and then Suppress the vertex i*/
|
||||
void Eliminate(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type& G);
|
||||
void Eliminate(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type &G);
|
||||
//! Collect all doublets (edges e_i_k such that there is an edge e_k_i with k!=i in the graph)
|
||||
/*! Returns the vector of doublets */
|
||||
vector_vertex_descriptor Collect_Doublet(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type& G);
|
||||
vector_vertex_descriptor Collect_Doublet(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type &G);
|
||||
//! Detect all the clique (all vertex in a clique are related to each other) in the graph
|
||||
bool Vertex_Belong_to_a_Clique(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type& G);
|
||||
bool Vertex_Belong_to_a_Clique(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type &G);
|
||||
//! Graph reduction: eliminating purely intermediate variables or variables outside of any circuit
|
||||
bool Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(AdjacencyList_type& G);
|
||||
bool Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(AdjacencyList_type &G);
|
||||
//! Graph reduction: elimination of a vertex inside a clique
|
||||
bool Elimination_of_Vertex_belonging_to_a_clique_Step(AdjacencyList_type& G);
|
||||
bool Elimination_of_Vertex_belonging_to_a_clique_Step(AdjacencyList_type &G);
|
||||
//! A vertex belong to the feedback vertex set if the vertex loops on itself.
|
||||
/*! We have to suppress this vertex and store it into the feedback set.*/
|
||||
bool Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(set<int> &feed_back_vertices, AdjacencyList_type& G1);
|
||||
bool Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(set<int> &feed_back_vertices, AdjacencyList_type &G1);
|
||||
//! Print the Graph
|
||||
void Print(GraphvizDigraph& G);
|
||||
void Print(AdjacencyList_type& G);
|
||||
void Print(GraphvizDigraph &G);
|
||||
void Print(AdjacencyList_type &G);
|
||||
//! Create a GraphvizDigraph from a Adjacency Matrix (an incidence Matrix without the diagonal terms)
|
||||
GraphvizDigraph AM_2_GraphvizDigraph(bool* AM, unsigned int n);
|
||||
GraphvizDigraph AM_2_GraphvizDigraph(bool *AM, unsigned int n);
|
||||
//! Create an adjacency graph from a Adjacency Matrix (an incidence Matrix without the diagonal terms)
|
||||
AdjacencyList_type AM_2_AdjacencyList(bool* AMp,unsigned int n);
|
||||
AdjacencyList_type AM_2_AdjacencyList(bool *AMp, unsigned int n);
|
||||
//! Create an adjacency graph from a GraphvizDigraph
|
||||
AdjacencyList_type GraphvizDigraph_2_AdjacencyList(GraphvizDigraph& G1, set<int> select_index);
|
||||
AdjacencyList_type GraphvizDigraph_2_AdjacencyList(GraphvizDigraph &G1, set<int> select_index);
|
||||
//! Check if the graph contains any cycle (true if the model contains at least one cycle, false otherwise)
|
||||
bool has_cycle(vector<int> &circuit_stack, AdjacencyList_type& g);
|
||||
bool has_cycle_dfs(AdjacencyList_type& g, AdjacencyList_type::vertex_descriptor u, color_type& color, vector<int> &circuit_stack);
|
||||
bool has_cycle(vector<int> &circuit_stack, AdjacencyList_type &g);
|
||||
bool has_cycle_dfs(AdjacencyList_type &g, AdjacencyList_type::vertex_descriptor u, color_type &color, vector<int> &circuit_stack);
|
||||
//! Return the feedback set
|
||||
AdjacencyList_type Minimal_set_of_feedback_vertex(set<int> &feed_back_vertices, const AdjacencyList_type& G);
|
||||
AdjacencyList_type Minimal_set_of_feedback_vertex(set<int> &feed_back_vertices, const AdjacencyList_type &G);
|
||||
//! Clear all in and out edges of vertex_to_eliminate and remove vertex_to_eliminate from the graph
|
||||
void Suppress(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type& G);
|
||||
void Suppress(int vertex_num, AdjacencyList_type& G);
|
||||
void Suppress(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type &G);
|
||||
void Suppress(int vertex_num, AdjacencyList_type &G);
|
||||
//! Reorder the recursive variables
|
||||
/*! They appear first in a quasi triangular form and they are followed by the feedback variables */
|
||||
void Reorder_the_recursive_variables(const AdjacencyList_type& G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices);
|
||||
void Reorder_the_recursive_variables(const AdjacencyList_type &G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices);
|
||||
};
|
||||
|
||||
#endif // _MINIMUMFEEDBACKSET_HH
|
||||
|
|
|
@ -33,8 +33,8 @@ ModFile::ModFile() : expressions_tree(symbol_table, num_constants),
|
|||
|
||||
ModFile::~ModFile()
|
||||
{
|
||||
for(vector<Statement *>::iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
for (vector<Statement *>::iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ ModFile::evalAllExpressions(bool warn_uninit)
|
|||
cout << "Evaluating expressions...";
|
||||
|
||||
// Loop over all statements, and fill global eval context if relevant
|
||||
for(vector<Statement *>::const_iterator it = statements.begin(); it != statements.end(); it++)
|
||||
for (vector<Statement *>::const_iterator it = statements.begin(); it != statements.end(); it++)
|
||||
{
|
||||
InitParamStatement *ips = dynamic_cast<InitParamStatement *>(*it);
|
||||
if (ips)
|
||||
|
@ -65,11 +65,11 @@ ModFile::evalAllExpressions(bool warn_uninit)
|
|||
cout << "done" << endl;
|
||||
|
||||
// Check if some symbols are not initialized, and give them a zero value then
|
||||
for(int id = 0; id <= symbol_table.maxID(); id++)
|
||||
for (int id = 0; id <= symbol_table.maxID(); id++)
|
||||
{
|
||||
SymbolType type = symbol_table.getType(id);
|
||||
if ((type == eEndogenous || type == eExogenous || type == eExogenousDet
|
||||
|| type == eParameter || type == eModelLocalVariable)
|
||||
|| type == eParameter || type == eModelLocalVariable)
|
||||
&& global_eval_context.find(id) == global_eval_context.end())
|
||||
{
|
||||
if (warn_uninit)
|
||||
|
@ -88,8 +88,8 @@ ModFile::addStatement(Statement *st)
|
|||
void
|
||||
ModFile::checkPass()
|
||||
{
|
||||
for(vector<Statement *>::iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
for (vector<Statement *>::iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
(*it)->checkPass(mod_file_struct);
|
||||
|
||||
// If order option has not been set, default to 2
|
||||
|
@ -181,7 +181,7 @@ ModFile::computingPass(bool no_tmp_terms)
|
|||
{
|
||||
// Mod file may have no equation (for example in a standalone BVAR estimation)
|
||||
bool dynamic_model_needed = mod_file_struct.simul_present || mod_file_struct.check_present || mod_file_struct.stoch_simul_present
|
||||
|| mod_file_struct.estimation_present|| mod_file_struct.osr_present
|
||||
|| mod_file_struct.estimation_present || mod_file_struct.osr_present
|
||||
|| mod_file_struct.ramsey_policy_present || mod_file_struct.identification_present;
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
|
@ -210,21 +210,21 @@ ModFile::computingPass(bool no_tmp_terms)
|
|||
dynamic_model.computingPass(true, true, false, false, global_eval_context, no_tmp_terms, false, false);
|
||||
}
|
||||
|
||||
for(vector<Statement *>::iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
for (vector<Statement *>::iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
(*it)->computingPass();
|
||||
}
|
||||
|
||||
void
|
||||
ModFile::writeOutputFiles(const string &basename, bool clear_all
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
, bool cygwin, bool msvc
|
||||
, bool cygwin, bool msvc
|
||||
#endif
|
||||
) const
|
||||
) const
|
||||
{
|
||||
ofstream mOutputFile;
|
||||
bool dynamic_model_needed = mod_file_struct.simul_present || mod_file_struct.check_present || mod_file_struct.stoch_simul_present
|
||||
|| mod_file_struct.estimation_present|| mod_file_struct.osr_present
|
||||
|| mod_file_struct.estimation_present || mod_file_struct.osr_present
|
||||
|| mod_file_struct.ramsey_policy_present || mod_file_struct.identification_present;
|
||||
|
||||
if (basename.size())
|
||||
|
@ -303,14 +303,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
|
|||
// Some mex commands are enclosed in an eval(), because otherwise it will make Octave fail
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
if (msvc)
|
||||
mOutputFile << " eval('mex -O LINKFLAGS=\"$LINKFLAGS /export:Dynamic\" " << basename << "_dynamic.c')" << endl; // MATLAB/Windows + Microsoft Visual C++
|
||||
mOutputFile << " eval('mex -O LINKFLAGS=\"$LINKFLAGS /export:Dynamic\" " << basename << "_dynamic.c')" << endl; // MATLAB/Windows + Microsoft Visual C++
|
||||
else if (cygwin)
|
||||
mOutputFile << " eval('mex -O PRELINK_CMDS1=\"echo EXPORTS > mex.def & echo mexFunction >> mex.def & echo Dynamic >> mex.def\" " << basename << "_dynamic.c')" << endl; // MATLAB/Windows + Cygwin g++
|
||||
mOutputFile << " eval('mex -O PRELINK_CMDS1=\"echo EXPORTS > mex.def & echo mexFunction >> mex.def & echo Dynamic >> mex.def\" " << basename << "_dynamic.c')" << endl; // MATLAB/Windows + Cygwin g++
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: When using the USE_DLL option, you must give either 'cygwin' or 'msvc' option to the 'dynare' command" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
{
|
||||
cerr << "ERROR: When using the USE_DLL option, you must give either 'cygwin' or 'msvc' option to the 'dynare' command" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#else
|
||||
# ifdef __linux__
|
||||
mOutputFile << " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_dynamic.c')" << endl; // MATLAB/Linux
|
||||
|
@ -319,8 +319,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
|
|||
# endif
|
||||
#endif
|
||||
mOutputFile << "else" << endl
|
||||
<< " mex " << basename << "_dynamic.c" << endl // Octave
|
||||
<< "end" << endl;
|
||||
<< " mex " << basename << "_dynamic.c" << endl // Octave
|
||||
<< "end" << endl;
|
||||
}
|
||||
|
||||
// Add path for block option with M-files
|
||||
|
@ -329,7 +329,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
|
|||
|
||||
if (dynamic_model.equation_number() > 0)
|
||||
{
|
||||
if(dynamic_model_needed)
|
||||
if (dynamic_model_needed)
|
||||
dynamic_model.writeOutput(mOutputFile, basename, block, byte_code, use_dll);
|
||||
else
|
||||
dynamic_model.writeOutput(mOutputFile, basename, false, false, false);
|
||||
|
@ -338,8 +338,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
|
|||
}
|
||||
|
||||
// Print statements
|
||||
for(vector<Statement *>::const_iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
for (vector<Statement *>::const_iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
{
|
||||
(*it)->writeOutput(mOutputFile, basename);
|
||||
|
||||
|
@ -372,7 +372,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
|
|||
{
|
||||
static_model.writeStaticFile(basename, block, byte_code);
|
||||
|
||||
if(dynamic_model_needed)
|
||||
if (dynamic_model_needed)
|
||||
{
|
||||
dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll);
|
||||
dynamic_model.writeParamsDerivativesFile(basename);
|
||||
|
|
|
@ -92,9 +92,9 @@ public:
|
|||
*/
|
||||
void writeOutputFiles(const string &basename, bool clear_all
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
, bool cygwin, bool msvc
|
||||
, bool cygwin, bool msvc
|
||||
#endif
|
||||
) const;
|
||||
) const;
|
||||
};
|
||||
|
||||
#endif // ! MOD_FILE_HH
|
||||
|
|
|
@ -50,7 +50,7 @@ ModelTree::computeNormalization(const set<pair<int, int> > &endo_eqs_incidence)
|
|||
// Fill in the graph
|
||||
set<pair<int, int> > endo;
|
||||
|
||||
for(set<pair<int, int> >::const_iterator it = endo_eqs_incidence.begin(); it != endo_eqs_incidence.end(); it++)
|
||||
for (set<pair<int, int> >::const_iterator it = endo_eqs_incidence.begin(); it != endo_eqs_incidence.end(); it++)
|
||||
add_edge(it->first + n, it->second, g);
|
||||
|
||||
// Compute maximum cardinality matching
|
||||
|
@ -64,7 +64,7 @@ ModelTree::computeNormalization(const set<pair<int, int> > &endo_eqs_incidence)
|
|||
multimap<int, int> natural_endo2eqs;
|
||||
computeNormalizedEquations(natural_endo2eqs);
|
||||
|
||||
for(int i = 0; i < symbol_table.endo_nbr(); i++)
|
||||
for (int i = 0; i < symbol_table.endo_nbr(); i++)
|
||||
{
|
||||
if (natural_endo2eqs.count(i) == 0)
|
||||
continue;
|
||||
|
@ -77,7 +77,7 @@ ModelTree::computeNormalization(const set<pair<int, int> > &endo_eqs_incidence)
|
|||
|
||||
edmonds_augmenting_path_finder<BipartiteGraph, size_t *, property_map<BipartiteGraph, vertex_index_t>::type> augmentor(g, &mate_map[0], get(vertex_index, g));
|
||||
bool not_maximum_yet = true;
|
||||
while(not_maximum_yet)
|
||||
while (not_maximum_yet)
|
||||
{
|
||||
not_maximum_yet = augmentor.augment_matching();
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ ModelTree::computeNormalization(const set<pair<int, int> > &endo_eqs_incidence)
|
|||
assert(check);
|
||||
|
||||
#ifdef DEBUG
|
||||
for(int i = 0; i < n; i++)
|
||||
for (int i = 0; i < n; i++)
|
||||
cout << "Endogenous " << symbol_table.getName(symbol_table.getID(eEndogenous, i))
|
||||
<< " matched with equation " << (mate_map[i]-n+1) << endl;
|
||||
#endif
|
||||
|
@ -104,7 +104,7 @@ ModelTree::computeNormalization(const set<pair<int, int> > &endo_eqs_incidence)
|
|||
|
||||
int n1 = 0, n2 = 0;
|
||||
|
||||
for(int i = 0; i < symbol_table.endo_nbr(); i++)
|
||||
for (int i = 0; i < symbol_table.endo_nbr(); i++)
|
||||
{
|
||||
if (natural_endo2eqs.count(i) == 0)
|
||||
continue;
|
||||
|
@ -128,7 +128,6 @@ ModelTree::computeNormalization(const set<pair<int, int> > &endo_eqs_incidence)
|
|||
throw NormalizationException(symbol_table.getID(eEndogenous, it - mate_map.begin()));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ModelTree::computePossiblySingularNormalization(const jacob_map &contemporaneous_jacobian, bool try_symbolic)
|
||||
{
|
||||
|
@ -136,8 +135,8 @@ ModelTree::computePossiblySingularNormalization(const jacob_map &contemporaneous
|
|||
|
||||
set<pair<int, int> > endo_eqs_incidence;
|
||||
|
||||
for(jacob_map::const_iterator it = contemporaneous_jacobian.begin();
|
||||
it != contemporaneous_jacobian.end(); it++)
|
||||
for (jacob_map::const_iterator it = contemporaneous_jacobian.begin();
|
||||
it != contemporaneous_jacobian.end(); it++)
|
||||
endo_eqs_incidence.insert(make_pair(it->first.first, it->first.second));
|
||||
|
||||
try
|
||||
|
@ -145,7 +144,7 @@ ModelTree::computePossiblySingularNormalization(const jacob_map &contemporaneous
|
|||
computeNormalization(endo_eqs_incidence);
|
||||
return;
|
||||
}
|
||||
catch(NormalizationException &e)
|
||||
catch (NormalizationException &e)
|
||||
{
|
||||
if (try_symbolic)
|
||||
cout << "Normalization failed with cutoff, trying symbolic normalization..." << endl;
|
||||
|
@ -163,11 +162,11 @@ ModelTree::computePossiblySingularNormalization(const jacob_map &contemporaneous
|
|||
{
|
||||
endo_eqs_incidence.clear();
|
||||
set<pair<int, int> > endo;
|
||||
for(int i = 0; i < equation_number(); i++)
|
||||
for (int i = 0; i < equation_number(); i++)
|
||||
{
|
||||
endo.clear();
|
||||
equations[i]->collectEndogenous(endo);
|
||||
for(set<pair<int, int> >::const_iterator it = endo.begin(); it != endo.end(); it++)
|
||||
for (set<pair<int, int> >::const_iterator it = endo.begin(); it != endo.end(); it++)
|
||||
endo_eqs_incidence.insert(make_pair(i, it->first));
|
||||
}
|
||||
|
||||
|
@ -175,7 +174,7 @@ ModelTree::computePossiblySingularNormalization(const jacob_map &contemporaneous
|
|||
{
|
||||
computeNormalization(endo_eqs_incidence);
|
||||
}
|
||||
catch(NormalizationException &e)
|
||||
catch (NormalizationException &e)
|
||||
{
|
||||
cerr << "ERROR: Could not normalize the model even with zero cutoff. Variable "
|
||||
<< symbol_table.getName(e.symb_id)
|
||||
|
@ -188,7 +187,7 @@ ModelTree::computePossiblySingularNormalization(const jacob_map &contemporaneous
|
|||
void
|
||||
ModelTree::computeNormalizedEquations(multimap<int, int> &endo2eqs) const
|
||||
{
|
||||
for(int i = 0; i < equation_number(); i++)
|
||||
for (int i = 0; i < equation_number(); i++)
|
||||
{
|
||||
VariableNode *lhs = dynamic_cast<VariableNode *>(equations[i]->get_arg1());
|
||||
if (lhs == NULL)
|
||||
|
@ -208,7 +207,6 @@ ModelTree::computeNormalizedEquations(multimap<int, int> &endo2eqs) const
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ModelTree::evaluateAndReduceJacobian(const eval_context_type &eval_context, jacob_map &contemporaneous_jacobian, jacob_map &static_jacobian, dynamic_jacob_map &dynamic_jacobian, double cutoff, bool verbose)
|
||||
{
|
||||
|
@ -249,7 +247,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_type &eval_context, jaco
|
|||
if (lag == 0)
|
||||
{
|
||||
nb_elements_contemparenous_Jacobian++;
|
||||
contemporaneous_jacobian[make_pair(eq,var)] = val;
|
||||
contemporaneous_jacobian[make_pair(eq, var)] = val;
|
||||
}
|
||||
if (static_jacobian.find(make_pair(eq, var)) != static_jacobian.end())
|
||||
static_jacobian[make_pair(eq, var)] += val;
|
||||
|
@ -261,10 +259,10 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_type &eval_context, jaco
|
|||
}
|
||||
|
||||
// Get rid of the elements of the Jacobian matrix below the cutoff
|
||||
for(set<pair<int, int> >::const_iterator it = jacobian_elements_to_delete.begin(); it != jacobian_elements_to_delete.end(); it++)
|
||||
for (set<pair<int, int> >::const_iterator it = jacobian_elements_to_delete.begin(); it != jacobian_elements_to_delete.end(); it++)
|
||||
first_derivatives.erase(*it);
|
||||
|
||||
if (jacobian_elements_to_delete.size()>0)
|
||||
if (jacobian_elements_to_delete.size() > 0)
|
||||
{
|
||||
cout << jacobian_elements_to_delete.size() << " elements among " << first_derivatives.size() << " in the incidence matrices are below the cutoff (" << cutoff << ") and are discarded" << endl
|
||||
<< "The contemporaneous incidence matrix has " << nb_elements_contemparenous_Jacobian << " elements" << endl;
|
||||
|
@ -274,20 +272,20 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_type &eval_context, jaco
|
|||
void
|
||||
ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector<int> &equation_reordered, vector<int> &variable_reordered, unsigned int &prologue, unsigned int &epilogue)
|
||||
{
|
||||
vector<int> eq2endo(equation_number(),0);
|
||||
vector<int> eq2endo(equation_number(), 0);
|
||||
equation_reordered.resize(equation_number());
|
||||
variable_reordered.resize(equation_number());
|
||||
bool *IM;
|
||||
int n = equation_number();
|
||||
IM = (bool*)calloc(n*n,sizeof(bool));
|
||||
IM = (bool *) calloc(n*n, sizeof(bool));
|
||||
int i = 0;
|
||||
for(vector<int>::const_iterator it=endo2eq.begin(); it != endo2eq.end(); it++, i++)
|
||||
for (vector<int>::const_iterator it = endo2eq.begin(); it != endo2eq.end(); it++, i++)
|
||||
{
|
||||
eq2endo[*it] = i;
|
||||
equation_reordered[i] = i;
|
||||
variable_reordered[*it] = i;
|
||||
}
|
||||
for (jacob_map::const_iterator it = static_jacobian_arg.begin(); it != static_jacobian_arg.end(); it ++)
|
||||
for (jacob_map::const_iterator it = static_jacobian_arg.begin(); it != static_jacobian_arg.end(); it++)
|
||||
IM[it->first.first * n + endo2eq[it->first.second]] = true;
|
||||
bool something_has_been_done = true;
|
||||
prologue = 0;
|
||||
|
@ -297,18 +295,18 @@ ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector<int
|
|||
{
|
||||
int tmp_prologue = prologue;
|
||||
something_has_been_done = false;
|
||||
for(int i = prologue;i < n; i++)
|
||||
for (int i = prologue; i < n; i++)
|
||||
{
|
||||
int nze = 0;
|
||||
for(int j = tmp_prologue; j < n; j++)
|
||||
if(IM[i * n + j])
|
||||
for (int j = tmp_prologue; j < n; j++)
|
||||
if (IM[i * n + j])
|
||||
{
|
||||
nze ++;
|
||||
nze++;
|
||||
k = j;
|
||||
}
|
||||
if(nze == 1)
|
||||
if (nze == 1)
|
||||
{
|
||||
for(int j = 0; j < n; j++)
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
bool tmp_bool = IM[tmp_prologue * n + j];
|
||||
IM[tmp_prologue * n + j] = IM[i * n + j];
|
||||
|
@ -317,7 +315,7 @@ ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector<int
|
|||
int tmp = equation_reordered[tmp_prologue];
|
||||
equation_reordered[tmp_prologue] = equation_reordered[i];
|
||||
equation_reordered[i] = tmp;
|
||||
for(int j = 0; j < n; j++)
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
bool tmp_bool = IM[j * n + tmp_prologue];
|
||||
IM[j * n + tmp_prologue] = IM[j * n + k];
|
||||
|
@ -340,18 +338,18 @@ ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector<int
|
|||
{
|
||||
int tmp_epilogue = epilogue;
|
||||
something_has_been_done = false;
|
||||
for(int i = prologue;i < n - (int) epilogue; i++)
|
||||
for (int i = prologue; i < n - (int) epilogue; i++)
|
||||
{
|
||||
int nze = 0;
|
||||
for(int j = prologue; j < n - tmp_epilogue; j++)
|
||||
if(IM[j * n + i])
|
||||
for (int j = prologue; j < n - tmp_epilogue; j++)
|
||||
if (IM[j * n + i])
|
||||
{
|
||||
nze ++;
|
||||
nze++;
|
||||
k = j;
|
||||
}
|
||||
if(nze == 1)
|
||||
if (nze == 1)
|
||||
{
|
||||
for(int j = 0; j < n; j++)
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
bool tmp_bool = IM[(n - 1 - tmp_epilogue) * n + j];
|
||||
IM[(n - 1 - tmp_epilogue) * n + j] = IM[k * n + j];
|
||||
|
@ -360,7 +358,7 @@ ModelTree::computePrologueAndEpilogue(jacob_map &static_jacobian_arg, vector<int
|
|||
int tmp = equation_reordered[n - 1 - tmp_epilogue];
|
||||
equation_reordered[n - 1 - tmp_epilogue] = equation_reordered[k];
|
||||
equation_reordered[k] = tmp;
|
||||
for(int j = 0; j < n; j++)
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
bool tmp_bool = IM[j * n + n - 1 - tmp_epilogue];
|
||||
IM[j * n + n - 1 - tmp_epilogue] = IM[j * n + i];
|
||||
|
@ -403,7 +401,7 @@ ModelTree::equationTypeDetermination(vector<BinaryOpNode *> &equations, map<pair
|
|||
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)));
|
||||
pair<bool, NodeID> res;
|
||||
if(derivative != first_order_endo_derivatives.end())
|
||||
if (derivative != first_order_endo_derivatives.end())
|
||||
{
|
||||
set<pair<int, int> > result;
|
||||
derivative->second->collectEndogenous(result);
|
||||
|
@ -411,22 +409,22 @@ ModelTree::equationTypeDetermination(vector<BinaryOpNode *> &equations, map<pair
|
|||
//Determine whether the equation could be evaluated rather than to be solved
|
||||
ostringstream tt("");
|
||||
derivative->second->writeOutput(tt, oMatlabDynamicModelSparse, temporary_terms);
|
||||
if (tmp_output.str() == tmp_s.str() and tt.str()=="1")
|
||||
if (tmp_output.str() == tmp_s.str() and tt.str() == "1")
|
||||
{
|
||||
Equation_Simulation_Type = E_EVALUATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<pair<int, pair<NodeID, NodeID> > > List_of_Op_RHS;
|
||||
vector<pair<int, pair<NodeID, NodeID> > > List_of_Op_RHS;
|
||||
res = equations[eq]->normalizeEquation(var, List_of_Op_RHS);
|
||||
if(mfs==2)
|
||||
if (mfs == 2)
|
||||
{
|
||||
if(d_endo_variable == result.end() && res.second)
|
||||
if (d_endo_variable == result.end() && res.second)
|
||||
Equation_Simulation_Type = E_EVALUATE_S;
|
||||
}
|
||||
else if(mfs==3)
|
||||
else if (mfs == 3)
|
||||
{
|
||||
if(res.second) // The equation could be solved analytically
|
||||
if (res.second) // The equation could be solved analytically
|
||||
Equation_Simulation_Type = E_EVALUATE_S;
|
||||
}
|
||||
}
|
||||
|
@ -440,8 +438,8 @@ void
|
|||
ModelTree::getVariableLeadLagByBlock(dynamic_jacob_map &dynamic_jacobian, vector<int > &components_set, int nb_blck_sim, int prologue, int epilogue, t_lag_lead_vector &equation_lead_lag, t_lag_lead_vector &variable_lead_lag, vector<int> equation_reordered, vector<int> variable_reordered) const
|
||||
{
|
||||
int nb_endo = symbol_table.endo_nbr();
|
||||
variable_lead_lag = t_lag_lead_vector(nb_endo , make_pair(0,0));
|
||||
equation_lead_lag = t_lag_lead_vector(nb_endo , make_pair(0,0));
|
||||
variable_lead_lag = t_lag_lead_vector(nb_endo, make_pair(0, 0));
|
||||
equation_lead_lag = t_lag_lead_vector(nb_endo, make_pair(0, 0));
|
||||
vector<int> variable_blck(nb_endo), equation_blck(nb_endo);
|
||||
for (int i = 0; i < nb_endo; i++)
|
||||
{
|
||||
|
@ -450,7 +448,7 @@ ModelTree::getVariableLeadLagByBlock(dynamic_jacob_map &dynamic_jacobian, vector
|
|||
variable_blck[variable_reordered[i]] = i;
|
||||
equation_blck[equation_reordered[i]] = i;
|
||||
}
|
||||
else if (i < (int)components_set.size() + prologue)
|
||||
else if (i < (int) components_set.size() + prologue)
|
||||
{
|
||||
variable_blck[variable_reordered[i]] = components_set[i-prologue] + prologue;
|
||||
equation_blck[equation_reordered[i]] = components_set[i-prologue] + prologue;
|
||||
|
@ -480,7 +478,6 @@ ModelTree::getVariableLeadLagByBlock(dynamic_jacob_map &dynamic_jacobian, vector
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &static_jacobian, dynamic_jacob_map &dynamic_jacobian, int prologue, int epilogue, vector<int> &equation_reordered, vector<int> &variable_reordered, vector<pair<int, int> > &blocks, t_equation_type_and_normalized_equation &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs, vector<int> &inv_equation_reordered, vector<int> &inv_variable_reordered) const
|
||||
{
|
||||
|
@ -492,17 +489,17 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &
|
|||
|
||||
vector<int> reverse_equation_reordered(nb_var), reverse_variable_reordered(nb_var);
|
||||
|
||||
for(int i=0; i<nb_var; i++)
|
||||
for (int i = 0; i < nb_var; i++)
|
||||
{
|
||||
reverse_equation_reordered[equation_reordered[i]] = i;
|
||||
reverse_variable_reordered[variable_reordered[i]] = i;
|
||||
}
|
||||
|
||||
for(jacob_map::const_iterator it = static_jacobian.begin(); it != static_jacobian.end(); it++)
|
||||
if( reverse_equation_reordered[it->first.first]>=prologue && reverse_equation_reordered[it->first.first]<nb_var - epilogue
|
||||
&& reverse_variable_reordered[it->first.second]>=prologue && reverse_variable_reordered[it->first.second]<nb_var - epilogue
|
||||
&& it->first.first != endo2eq[it->first.second])
|
||||
add_edge(reverse_equation_reordered[it->first.first]-prologue, reverse_equation_reordered[endo2eq[it->first.second]]-prologue, G2);
|
||||
for (jacob_map::const_iterator it = static_jacobian.begin(); it != static_jacobian.end(); it++)
|
||||
if (reverse_equation_reordered[it->first.first] >= prologue && reverse_equation_reordered[it->first.first] < nb_var - epilogue
|
||||
&& reverse_variable_reordered[it->first.second] >= prologue && reverse_variable_reordered[it->first.second] < nb_var - epilogue
|
||||
&& it->first.first != endo2eq[it->first.second])
|
||||
add_edge(reverse_equation_reordered[it->first.first]-prologue, reverse_equation_reordered[endo2eq[it->first.second]]-prologue, G2);
|
||||
|
||||
vector<int> endo2block(num_vertices(G2)), discover_time(num_vertices(G2));
|
||||
|
||||
|
@ -511,13 +508,11 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &
|
|||
|
||||
blocks = vector<pair<int, int> >(num, make_pair(0, 0));
|
||||
|
||||
|
||||
// Create directed acyclic graph associated to the strongly connected components
|
||||
typedef adjacency_list<vecS, vecS, directedS> DirectedGraph;
|
||||
DirectedGraph dag(num);
|
||||
|
||||
|
||||
for (unsigned int i = 0;i < num_vertices(G2);i++)
|
||||
for (unsigned int i = 0; i < num_vertices(G2); i++)
|
||||
{
|
||||
GraphvizDigraph::out_edge_iterator it_out, out_end;
|
||||
GraphvizDigraph::vertex_descriptor vi = vertex(i, G2);
|
||||
|
@ -536,10 +531,9 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &
|
|||
|
||||
// Construct mapping from unordered SCC to ordered SCC
|
||||
vector<int> unordered2ordered(num);
|
||||
for(int i = 0; i < num; i++)
|
||||
for (int i = 0; i < num; i++)
|
||||
unordered2ordered[ordered2unordered[i]] = i;
|
||||
|
||||
|
||||
//This vector contains for each block:
|
||||
// - first set = equations belonging to the block,
|
||||
// - second set = the feeback variables,
|
||||
|
@ -559,7 +553,7 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &
|
|||
vector<int> tmp_equation_reordered(equation_reordered), tmp_variable_reordered(variable_reordered);
|
||||
int order = prologue;
|
||||
//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
|
||||
if(select_feedback_variable)
|
||||
if (select_feedback_variable)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
if (Equation_Type[equation_reordered[i+prologue]].first == E_SOLVE
|
||||
|
@ -608,14 +602,15 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(jacob_map &
|
|||
}
|
||||
inv_equation_reordered = vector<int>(nb_var);
|
||||
inv_variable_reordered = vector<int>(nb_var);
|
||||
for(int i = 0; i < nb_var ; i++)
|
||||
for (int i = 0; i < nb_var; i++)
|
||||
{
|
||||
inv_variable_reordered[variable_reordered[i]] = i;
|
||||
inv_equation_reordered[equation_reordered[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
void ModelTree::printBlockDecomposition(vector<pair<int, int> > blocks)
|
||||
void
|
||||
ModelTree::printBlockDecomposition(vector<pair<int, int> > blocks)
|
||||
{
|
||||
int largest_block = 0;
|
||||
int Nb_SimulBlocks = 0;
|
||||
|
@ -636,7 +631,6 @@ void ModelTree::printBlockDecomposition(vector<pair<int, int> > blocks)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int Nb_RecursBlocks = Nb_TotalBlocks - Nb_SimulBlocks;
|
||||
cout << Nb_TotalBlocks << " block(s) found:" << endl
|
||||
<< " " << Nb_RecursBlocks << " recursive block(s) and " << Nb_SimulBlocks << " simultaneous block(s)." << endl
|
||||
|
@ -644,8 +638,6 @@ void ModelTree::printBlockDecomposition(vector<pair<int, int> > blocks)
|
|||
<< " and " << Nb_feedback_variable << " feedback variable(s)." << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
t_block_type_firstequation_size_mfs
|
||||
ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian, int prologue, int epilogue, vector<pair<int, int> > &blocks, vector<BinaryOpNode *> &equations, t_equation_type_and_normalized_equation &Equation_Type, vector<int> &variable_reordered, vector<int> &equation_reordered)
|
||||
{
|
||||
|
@ -678,7 +670,7 @@ ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian,
|
|||
|
||||
Lag = Lead = 0;
|
||||
set<pair<int, int> > endo;
|
||||
for(count_equ = first_count_equ; count_equ < Blck_Size+first_count_equ; count_equ++)
|
||||
for (count_equ = first_count_equ; count_equ < Blck_Size+first_count_equ; count_equ++)
|
||||
{
|
||||
endo.clear();
|
||||
equations[equation_reordered[count_equ]]->collectEndogenous(endo);
|
||||
|
@ -687,7 +679,7 @@ ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian,
|
|||
int curr_variable = it->first;
|
||||
int curr_lag = it->second;
|
||||
vector<int>::const_iterator it = find(variable_reordered.begin()+first_count_equ, variable_reordered.begin()+(first_count_equ+Blck_Size), curr_variable);
|
||||
if(it != variable_reordered.begin()+(first_count_equ+Blck_Size))
|
||||
if (it != variable_reordered.begin()+(first_count_equ+Blck_Size))
|
||||
if (dynamic_jacobian.find(make_pair(curr_lag, make_pair(equation_reordered[count_equ], curr_variable))) != dynamic_jacobian.end())
|
||||
{
|
||||
if (curr_lag > Lead)
|
||||
|
@ -737,9 +729,9 @@ ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian,
|
|||
int c_Size = (block_type_size_mfs[block_type_size_mfs.size()-1]).second.first;
|
||||
int first_equation = (block_type_size_mfs[block_type_size_mfs.size()-1]).first.second;
|
||||
block_type_size_mfs[block_type_size_mfs.size()-1] = make_pair(make_pair(c_Type, first_equation), make_pair(++c_Size, block_type_size_mfs[block_type_size_mfs.size()-1].second.second));
|
||||
if(block_lag_lead[block_type_size_mfs.size()-1].first > Lag)
|
||||
if (block_lag_lead[block_type_size_mfs.size()-1].first > Lag)
|
||||
Lag = block_lag_lead[block_type_size_mfs.size()-1].first;
|
||||
if(block_lag_lead[block_type_size_mfs.size()-1].second > Lead)
|
||||
if (block_lag_lead[block_type_size_mfs.size()-1].second > Lead)
|
||||
Lead = block_lag_lead[block_type_size_mfs.size()-1].second;
|
||||
block_lag_lead[block_type_size_mfs.size()-1] = make_pair(Lag, Lead);
|
||||
}
|
||||
|
@ -766,19 +758,18 @@ ModelTree::reduceBlocksAndTypeDetermination(dynamic_jacob_map &dynamic_jacobian,
|
|||
return (block_type_size_mfs);
|
||||
}
|
||||
|
||||
|
||||
vector<bool>
|
||||
ModelTree::BlockLinear(t_blocks_derivatives &blocks_derivatives, vector<int> &variable_reordered)
|
||||
{
|
||||
unsigned int nb_blocks = getNbBlocks();
|
||||
vector<bool> blocks_linear(nb_blocks, true);
|
||||
for (unsigned int block = 0;block < nb_blocks; block++)
|
||||
for (unsigned int block = 0; block < nb_blocks; block++)
|
||||
{
|
||||
BlockSimulationType simulation_type = getBlockSimulationType(block);
|
||||
int block_size = getBlockSize(block);
|
||||
t_block_derivatives_equation_variable_laglead_nodeid derivatives_block = blocks_derivatives[block];
|
||||
int first_variable_position = getBlockFirstEquation(block);
|
||||
if (simulation_type==SOLVE_BACKWARD_COMPLETE || simulation_type==SOLVE_FORWARD_COMPLETE)
|
||||
if (simulation_type == SOLVE_BACKWARD_COMPLETE || simulation_type == SOLVE_FORWARD_COMPLETE)
|
||||
{
|
||||
for (t_block_derivatives_equation_variable_laglead_nodeid::const_iterator it = derivatives_block.begin(); it != derivatives_block.end(); it++)
|
||||
{
|
||||
|
@ -790,7 +781,7 @@ ModelTree::BlockLinear(t_blocks_derivatives &blocks_derivatives, vector<int> &va
|
|||
Id->collectEndogenous(endogenous);
|
||||
if (endogenous.size() > 0)
|
||||
{
|
||||
for (int l=0;l<block_size;l++)
|
||||
for (int l = 0; l < block_size; l++)
|
||||
{
|
||||
if (endogenous.find(make_pair(variable_reordered[first_variable_position+l], 0)) != endogenous.end())
|
||||
{
|
||||
|
@ -802,17 +793,17 @@ ModelTree::BlockLinear(t_blocks_derivatives &blocks_derivatives, vector<int> &va
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (simulation_type==SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type==SOLVE_TWO_BOUNDARIES_SIMPLE)
|
||||
else if (simulation_type == SOLVE_TWO_BOUNDARIES_COMPLETE || simulation_type == SOLVE_TWO_BOUNDARIES_SIMPLE)
|
||||
{
|
||||
for (t_block_derivatives_equation_variable_laglead_nodeid::const_iterator it = derivatives_block.begin(); it != derivatives_block.end(); it++)
|
||||
{
|
||||
int lag = it->second.first;
|
||||
NodeID Id = it->second.second;//
|
||||
NodeID Id = it->second.second; //
|
||||
set<pair<int, int> > endogenous;
|
||||
Id->collectEndogenous(endogenous);
|
||||
if (endogenous.size() > 0)
|
||||
{
|
||||
for (int l=0;l<block_size;l++)
|
||||
for (int l = 0; l < block_size; l++)
|
||||
{
|
||||
if (endogenous.find(make_pair(variable_reordered[first_variable_position+l], lag)) != endogenous.end())
|
||||
{
|
||||
|
@ -823,25 +814,24 @@ ModelTree::BlockLinear(t_blocks_derivatives &blocks_derivatives, vector<int> &va
|
|||
}
|
||||
}
|
||||
}
|
||||
the_end:;
|
||||
the_end:
|
||||
;
|
||||
}
|
||||
return(blocks_linear);
|
||||
return (blocks_linear);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ModelTree::ModelTree(SymbolTable &symbol_table_arg,
|
||||
NumericalConstants &num_constants_arg) :
|
||||
DataTree(symbol_table_arg, num_constants_arg)
|
||||
{
|
||||
for(int i=0; i < 3; i++)
|
||||
for (int i = 0; i < 3; i++)
|
||||
NNZDerivatives[i] = 0;
|
||||
}
|
||||
|
||||
int
|
||||
ModelTree::equation_number() const
|
||||
{
|
||||
return(equations.size());
|
||||
return (equations.size());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -859,20 +849,18 @@ ModelTree::writeDerivative(ostream &output, int eq, int symb_id, int lag,
|
|||
void
|
||||
ModelTree::computeJacobian(const set<int> &vars)
|
||||
{
|
||||
for(set<int>::const_iterator it = vars.begin();
|
||||
it != vars.end(); it++)
|
||||
for (set<int>::const_iterator it = vars.begin();
|
||||
it != vars.end(); it++)
|
||||
for (int eq = 0; eq < (int) equations.size(); eq++)
|
||||
{
|
||||
NodeID d1 = equations[eq]->getDerivative(*it);
|
||||
if (d1 == Zero)
|
||||
continue;
|
||||
first_derivatives[make_pair(eq, *it)] = d1;
|
||||
++NNZDerivatives[0];
|
||||
++NNZDerivatives[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
ModelTree::computeHessian(const set<int> &vars)
|
||||
{
|
||||
|
@ -884,8 +872,8 @@ ModelTree::computeHessian(const set<int> &vars)
|
|||
NodeID d1 = it->second;
|
||||
|
||||
// Store only second derivatives with var2 <= var1
|
||||
for(set<int>::const_iterator it2 = vars.begin();
|
||||
it2 != vars.end(); it2++)
|
||||
for (set<int>::const_iterator it2 = vars.begin();
|
||||
it2 != vars.end(); it2++)
|
||||
{
|
||||
int var2 = *it2;
|
||||
if (var2 > var1)
|
||||
|
@ -895,10 +883,10 @@ ModelTree::computeHessian(const set<int> &vars)
|
|||
if (d2 == Zero)
|
||||
continue;
|
||||
second_derivatives[make_pair(eq, make_pair(var1, var2))] = d2;
|
||||
if (var2 == var1)
|
||||
++NNZDerivatives[1];
|
||||
else
|
||||
NNZDerivatives[1] += 2;
|
||||
if (var2 == var1)
|
||||
++NNZDerivatives[1];
|
||||
else
|
||||
NNZDerivatives[1] += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -918,8 +906,8 @@ ModelTree::computeThirdDerivatives(const set<int> &vars)
|
|||
NodeID d2 = it->second;
|
||||
|
||||
// Store only third derivatives such that var3 <= var2 <= var1
|
||||
for(set<int>::const_iterator it2 = vars.begin();
|
||||
it2 != vars.end(); it2++)
|
||||
for (set<int>::const_iterator it2 = vars.begin();
|
||||
it2 != vars.end(); it2++)
|
||||
{
|
||||
int var3 = *it2;
|
||||
if (var3 > var2)
|
||||
|
@ -929,12 +917,12 @@ ModelTree::computeThirdDerivatives(const set<int> &vars)
|
|||
if (d3 == Zero)
|
||||
continue;
|
||||
third_derivatives[make_pair(eq, make_pair(var1, make_pair(var2, var3)))] = d3;
|
||||
if (var3 == var2 && var2 == var1)
|
||||
++NNZDerivatives[2];
|
||||
else if (var3 == var2 || var2 == var1)
|
||||
NNZDerivatives[2] += 3;
|
||||
else
|
||||
NNZDerivatives[2] += 6;
|
||||
if (var3 == var2 && var2 == var1)
|
||||
++NNZDerivatives[2];
|
||||
else if (var3 == var2 || var2 == var1)
|
||||
NNZDerivatives[2] += 3;
|
||||
else
|
||||
NNZDerivatives[2] += 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1027,11 +1015,11 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
|
|||
{
|
||||
vrhs = rhs->eval(eval_context_type());
|
||||
}
|
||||
catch(ExprNode::EvalException &e)
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
}
|
||||
|
||||
if (vrhs!=0)// The right hand side of the equation is not empty ==> residual=lhs-rhs;
|
||||
if (vrhs != 0) // The right hand side of the equation is not empty ==> residual=lhs-rhs;
|
||||
{
|
||||
output << "lhs =";
|
||||
lhs->writeOutput(output, output_type, temporary_terms);
|
||||
|
@ -1041,19 +1029,19 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
|
|||
rhs->writeOutput(output, output_type, temporary_terms);
|
||||
output << ";" << endl;
|
||||
|
||||
output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type)
|
||||
output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< "= lhs-rhs;" << endl;
|
||||
}
|
||||
else// The right hand side of the equation is empty ==> residual=lhs;
|
||||
else // The right hand side of the equation is empty ==> residual=lhs;
|
||||
{
|
||||
output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< " = ";
|
||||
output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type)
|
||||
<< " = ";
|
||||
lhs->writeOutput(output, output_type, temporary_terms);
|
||||
output << ";" << endl;
|
||||
output << ";" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ using namespace std;
|
|||
|
||||
#include "DataTree.hh"
|
||||
|
||||
|
||||
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a NodeID on the new normalized equation
|
||||
typedef vector<pair<EquationType, NodeID > > t_equation_type_and_normalized_equation;
|
||||
|
||||
|
@ -38,10 +37,10 @@ typedef vector<pair<EquationType, NodeID > > t_equation_type_and_normalized_equa
|
|||
typedef vector<pair< int, int> > t_lag_lead_vector;
|
||||
|
||||
//! for each block contains pair< pair<Simulation_Type, first_equation>, pair < Block_Size, Recursive_part_Size > >
|
||||
typedef vector<pair< pair< BlockSimulationType, int> , pair<int, int> > > t_block_type_firstequation_size_mfs;
|
||||
typedef vector<pair< pair< BlockSimulationType, int>, pair<int, int> > > t_block_type_firstequation_size_mfs;
|
||||
|
||||
//! for a block contains derivatives pair< pair<block_equation_number, block_variable_number> , pair<lead_lag, NodeID> >
|
||||
typedef vector< pair<pair<int, int> , pair< int, NodeID > > > t_block_derivatives_equation_variable_laglead_nodeid;
|
||||
typedef vector< pair<pair<int, int>, pair< int, NodeID > > > t_block_derivatives_equation_variable_laglead_nodeid;
|
||||
|
||||
//! for all blocks derivatives description
|
||||
typedef vector<t_block_derivatives_equation_variable_laglead_nodeid> t_blocks_derivatives;
|
||||
|
@ -143,7 +142,9 @@ protected:
|
|||
public:
|
||||
//! A variable missing from the maximum cardinal matching
|
||||
int symb_id;
|
||||
NormalizationException(int symb_id_arg) : symb_id(symb_id_arg) { }
|
||||
NormalizationException(int symb_id_arg) : symb_id(symb_id_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//! Compute the matching between endogenous and variable using the jacobian contemporaneous_jacobian
|
||||
|
@ -172,7 +173,6 @@ protected:
|
|||
//! Determine for each block if it is linear or not
|
||||
vector<bool> BlockLinear(t_blocks_derivatives &blocks_derivatives, vector<int> &variable_reordered);
|
||||
|
||||
|
||||
virtual SymbolType getTypeByDerivID(int deriv_id) const throw (UnknownDerivIDException) = 0;
|
||||
virtual int getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException) = 0;
|
||||
virtual int getSymbIDByDerivID(int deriv_id) const throw (UnknownDerivIDException) = 0;
|
||||
|
@ -208,7 +208,6 @@ protected:
|
|||
//! Return the position of variable_number in the block number belonging to the block block_number
|
||||
virtual int getBlockInitialVariableID(int block_number, int variable_number) const = 0;
|
||||
|
||||
|
||||
public:
|
||||
ModelTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
|
||||
//! Declare a node as an equation of the model
|
||||
|
@ -220,73 +219,76 @@ public:
|
|||
//! Returns the number of equations in the model
|
||||
int equation_number() const;
|
||||
|
||||
inline static std::string c_Equation_Type(int type)
|
||||
{
|
||||
char c_Equation_Type[4][13]=
|
||||
{
|
||||
"E_UNKNOWN ",
|
||||
"E_EVALUATE ",
|
||||
"E_EVALUATE_S",
|
||||
"E_SOLVE "
|
||||
};
|
||||
return(c_Equation_Type[type]);
|
||||
};
|
||||
inline static std::string
|
||||
c_Equation_Type(int type)
|
||||
{
|
||||
char c_Equation_Type[4][13] =
|
||||
{
|
||||
"E_UNKNOWN ",
|
||||
"E_EVALUATE ",
|
||||
"E_EVALUATE_S",
|
||||
"E_SOLVE "
|
||||
};
|
||||
return (c_Equation_Type[type]);
|
||||
};
|
||||
|
||||
inline static std::string BlockType0(BlockType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SIMULTANS:
|
||||
return ("SIMULTANEOUS TIME SEPARABLE ");
|
||||
break;
|
||||
case PROLOGUE:
|
||||
return ("PROLOGUE ");
|
||||
break;
|
||||
case EPILOGUE:
|
||||
return ("EPILOGUE ");
|
||||
break;
|
||||
case SIMULTAN:
|
||||
return ("SIMULTANEOUS TIME UNSEPARABLE");
|
||||
break;
|
||||
default:
|
||||
return ("UNKNOWN ");
|
||||
break;
|
||||
}
|
||||
};
|
||||
inline static std::string
|
||||
BlockType0(BlockType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SIMULTANS:
|
||||
return ("SIMULTANEOUS TIME SEPARABLE ");
|
||||
break;
|
||||
case PROLOGUE:
|
||||
return ("PROLOGUE ");
|
||||
break;
|
||||
case EPILOGUE:
|
||||
return ("EPILOGUE ");
|
||||
break;
|
||||
case SIMULTAN:
|
||||
return ("SIMULTANEOUS TIME UNSEPARABLE");
|
||||
break;
|
||||
default:
|
||||
return ("UNKNOWN ");
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
inline static std::string BlockSim(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EVALUATE_FORWARD:
|
||||
return ("EVALUATE FORWARD ");
|
||||
break;
|
||||
case EVALUATE_BACKWARD:
|
||||
return ("EVALUATE BACKWARD ");
|
||||
break;
|
||||
case SOLVE_FORWARD_SIMPLE:
|
||||
return ("SOLVE FORWARD SIMPLE ");
|
||||
break;
|
||||
case SOLVE_BACKWARD_SIMPLE:
|
||||
return ("SOLVE BACKWARD SIMPLE ");
|
||||
break;
|
||||
case SOLVE_TWO_BOUNDARIES_SIMPLE:
|
||||
return ("SOLVE TWO BOUNDARIES SIMPLE ");
|
||||
break;
|
||||
case SOLVE_FORWARD_COMPLETE:
|
||||
return ("SOLVE FORWARD COMPLETE ");
|
||||
break;
|
||||
case SOLVE_BACKWARD_COMPLETE:
|
||||
return ("SOLVE BACKWARD COMPLETE ");
|
||||
break;
|
||||
case SOLVE_TWO_BOUNDARIES_COMPLETE:
|
||||
return ("SOLVE TWO BOUNDARIES COMPLETE");
|
||||
break;
|
||||
default:
|
||||
return ("UNKNOWN ");
|
||||
break;
|
||||
}
|
||||
};
|
||||
inline static std::string
|
||||
BlockSim(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EVALUATE_FORWARD:
|
||||
return ("EVALUATE FORWARD ");
|
||||
break;
|
||||
case EVALUATE_BACKWARD:
|
||||
return ("EVALUATE BACKWARD ");
|
||||
break;
|
||||
case SOLVE_FORWARD_SIMPLE:
|
||||
return ("SOLVE FORWARD SIMPLE ");
|
||||
break;
|
||||
case SOLVE_BACKWARD_SIMPLE:
|
||||
return ("SOLVE BACKWARD SIMPLE ");
|
||||
break;
|
||||
case SOLVE_TWO_BOUNDARIES_SIMPLE:
|
||||
return ("SOLVE TWO BOUNDARIES SIMPLE ");
|
||||
break;
|
||||
case SOLVE_FORWARD_COMPLETE:
|
||||
return ("SOLVE FORWARD COMPLETE ");
|
||||
break;
|
||||
case SOLVE_BACKWARD_COMPLETE:
|
||||
return ("SOLVE BACKWARD COMPLETE ");
|
||||
break;
|
||||
case SOLVE_TWO_BOUNDARIES_COMPLETE:
|
||||
return ("SOLVE TWO BOUNDARIES COMPLETE");
|
||||
break;
|
||||
default:
|
||||
return ("UNKNOWN ");
|
||||
break;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -57,5 +57,5 @@ double
|
|||
NumericalConstants::getDouble(int ID) const
|
||||
{
|
||||
assert(ID >= 0 && ID < (int) double_vals.size());
|
||||
return(double_vals[ID]);
|
||||
return (double_vals[ID]);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ InitParamStatement::fillEvalContext(eval_context_type &eval_context) const
|
|||
{
|
||||
eval_context[symb_id] = param_value->eval(eval_context);
|
||||
}
|
||||
catch(ExprNode::EvalException &e)
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
@ -65,14 +65,14 @@ InitOrEndValStatement::InitOrEndValStatement(const init_values_type &init_values
|
|||
void
|
||||
InitOrEndValStatement::fillEvalContext(eval_context_type &eval_context) const
|
||||
{
|
||||
for(init_values_type::const_iterator it = init_values.begin();
|
||||
it != init_values.end(); it++)
|
||||
for (init_values_type::const_iterator it = init_values.begin();
|
||||
it != init_values.end(); it++)
|
||||
{
|
||||
try
|
||||
{
|
||||
eval_context[it->first] = (it->second)->eval(eval_context);
|
||||
}
|
||||
catch(ExprNode::EvalException &e)
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
@ -82,8 +82,8 @@ InitOrEndValStatement::fillEvalContext(eval_context_type &eval_context) const
|
|||
void
|
||||
InitOrEndValStatement::writeInitValues(ostream &output) const
|
||||
{
|
||||
for(init_values_type::const_iterator it = init_values.begin();
|
||||
it != init_values.end(); it++)
|
||||
for (init_values_type::const_iterator it = init_values.begin();
|
||||
it != init_values.end(); it++)
|
||||
{
|
||||
const int symb_id = it->first;
|
||||
const NodeID expression = it->second;
|
||||
|
@ -134,14 +134,12 @@ InitValStatement::writeOutputPostInit(ostream &output) const
|
|||
<<"end;" << endl;
|
||||
}
|
||||
|
||||
|
||||
EndValStatement::EndValStatement(const init_values_type &init_values_arg,
|
||||
const SymbolTable &symbol_table_arg) :
|
||||
InitOrEndValStatement(init_values_arg, symbol_table_arg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
EndValStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
|
@ -179,8 +177,8 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "% HISTVAL instructions" << endl
|
||||
<< "%" << endl;
|
||||
|
||||
for(hist_values_type::const_iterator it = hist_values.begin();
|
||||
it != hist_values.end(); it++)
|
||||
for (hist_values_type::const_iterator it = hist_values.begin();
|
||||
it != hist_values.end(); it++)
|
||||
{
|
||||
const int &symb_id = it->first.first;
|
||||
const int &lag = it->first.second;
|
||||
|
@ -231,8 +229,8 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "%" << endl
|
||||
<< "options_.homotopy_values = [];" << endl;
|
||||
|
||||
for(homotopy_values_type::const_iterator it = homotopy_values.begin();
|
||||
it != homotopy_values.end(); it++)
|
||||
for (homotopy_values_type::const_iterator it = homotopy_values.begin();
|
||||
it != homotopy_values.end(); it++)
|
||||
{
|
||||
const int &symb_id = it->first;
|
||||
const NodeID expression1 = it->second.first;
|
||||
|
@ -277,7 +275,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while(true)
|
||||
while (true)
|
||||
{
|
||||
string symb_name, value;
|
||||
f >> symb_name >> value;
|
||||
|
@ -289,7 +287,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
|
|||
int symb_id = symbol_table.getID(symb_name);
|
||||
content[symb_id] = value;
|
||||
}
|
||||
catch(SymbolTable::UnknownSymbolNameException &e)
|
||||
catch (SymbolTable::UnknownSymbolNameException &e)
|
||||
{
|
||||
cerr << "WARNING: Unknown symbol " << symb_name << " in " << filename << endl;
|
||||
}
|
||||
|
@ -299,10 +297,10 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
|
|||
void
|
||||
LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
for(map<int, string>::const_iterator it = content.begin();
|
||||
it != content.end(); it++)
|
||||
for (map<int, string>::const_iterator it = content.begin();
|
||||
it != content.end(); it++)
|
||||
{
|
||||
switch(symbol_table.getType(it->first))
|
||||
switch (symbol_table.getType(it->first))
|
||||
{
|
||||
case eParameter:
|
||||
output << "M_.params";
|
||||
|
@ -329,7 +327,7 @@ LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
|
|||
void
|
||||
LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_type &eval_context) const
|
||||
{
|
||||
for(map<int, string>::const_iterator it = content.begin();
|
||||
it != content.end(); it++)
|
||||
for (map<int, string>::const_iterator it = content.begin();
|
||||
it != content.end(); it++)
|
||||
eval_context[it->first] = atof(it->second.c_str());
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ ParsingDriver::symbol_exists_and_is_not_modfile_local_or_unknown_function(const
|
|||
|
||||
SymbolType type = mod_file->symbol_table.getType(s);
|
||||
|
||||
return(type != eModFileLocalVariable && type != eUnknownFunction);
|
||||
return (type != eModFileLocalVariable && type != eUnknownFunction);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -107,7 +107,7 @@ ParsingDriver::declare_symbol(string *name, SymbolType type, string *tex_name)
|
|||
else
|
||||
mod_file->symbol_table.addSymbol(*name, type, *tex_name);
|
||||
}
|
||||
catch(SymbolTable::AlreadyDeclaredException &e)
|
||||
catch (SymbolTable::AlreadyDeclaredException &e)
|
||||
{
|
||||
if (e.same_type)
|
||||
warning("Symbol " + *name + " declared twice.");
|
||||
|
@ -155,7 +155,7 @@ ParsingDriver::add_predetermined_variable(string *name)
|
|||
|
||||
mod_file->symbol_table.markPredetermined(symb_id);
|
||||
}
|
||||
catch(SymbolTable::UnknownSymbolNameException &e)
|
||||
catch (SymbolTable::UnknownSymbolNameException &e)
|
||||
{
|
||||
error("Undeclared symbol name: " + *name);
|
||||
}
|
||||
|
@ -267,7 +267,6 @@ ParsingDriver::dsample(string *arg1, string *arg2)
|
|||
delete arg2;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParsingDriver::init_param(string *name, NodeID rhs)
|
||||
{
|
||||
|
@ -468,7 +467,7 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast)
|
|||
|
||||
vector<ShocksStatement::DetShockElement> v;
|
||||
|
||||
for(unsigned int i = 0; i < det_shocks_periods.size(); i++)
|
||||
for (unsigned int i = 0; i < det_shocks_periods.size(); i++)
|
||||
{
|
||||
ShocksStatement::DetShockElement dse;
|
||||
dse.period1 = det_shocks_periods[i].first;
|
||||
|
@ -608,8 +607,8 @@ ParsingDriver::combine_lag_and_restriction(string *lag)
|
|||
if (it->first.first == current_lag)
|
||||
error("lag " + *lag + " used more than once.");
|
||||
|
||||
for(map<int, vector<int> >::const_iterator it = svar_equation_restrictions.begin();
|
||||
it != svar_equation_restrictions.end(); it++ )
|
||||
for (map<int, vector<int> >::const_iterator it = svar_equation_restrictions.begin();
|
||||
it != svar_equation_restrictions.end(); it++)
|
||||
svar_ident_exclusion_values[make_pair(current_lag, it->first)] = it->second;
|
||||
|
||||
svar_upper_cholesky = false;
|
||||
|
@ -640,16 +639,15 @@ ParsingDriver::add_in_svar_restriction_symbols(string *tmp_var)
|
|||
check_symbol_existence(*tmp_var);
|
||||
int symb_id = mod_file->symbol_table.getID(*tmp_var);
|
||||
|
||||
for (vector<int>::const_iterator viit=svar_restriction_symbols.begin();
|
||||
viit!=svar_restriction_symbols.end(); viit++)
|
||||
if (symb_id==*viit)
|
||||
for (vector<int>::const_iterator viit = svar_restriction_symbols.begin();
|
||||
viit != svar_restriction_symbols.end(); viit++)
|
||||
if (symb_id == *viit)
|
||||
error(*tmp_var + " restriction added twice.");
|
||||
|
||||
svar_restriction_symbols.push_back(symb_id);
|
||||
delete tmp_var;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParsingDriver::add_upper_cholesky()
|
||||
{
|
||||
|
@ -673,7 +671,7 @@ ParsingDriver::do_sigma_e()
|
|||
{
|
||||
mod_file->addStatement(new SigmaeStatement(sigmae_matrix));
|
||||
}
|
||||
catch(SigmaeStatement::MatrixFormException &e)
|
||||
catch (SigmaeStatement::MatrixFormException &e)
|
||||
{
|
||||
error("Sigma_e: matrix is neither upper triangular nor lower triangular");
|
||||
}
|
||||
|
@ -791,14 +789,16 @@ ParsingDriver::add_in_symbol_list(string *tmp_var)
|
|||
delete tmp_var;
|
||||
}
|
||||
|
||||
void ParsingDriver::rplot()
|
||||
void
|
||||
ParsingDriver::rplot()
|
||||
{
|
||||
mod_file->addStatement(new RplotStatement(symbol_list, options_list));
|
||||
options_list.clear();
|
||||
symbol_list.clear();
|
||||
}
|
||||
|
||||
void ParsingDriver::stoch_simul()
|
||||
void
|
||||
ParsingDriver::stoch_simul()
|
||||
{
|
||||
mod_file->addStatement(new StochSimulStatement(symbol_list, options_list));
|
||||
symbol_list.clear();
|
||||
|
@ -1124,8 +1124,8 @@ ParsingDriver::run_identification()
|
|||
void
|
||||
ParsingDriver::add_mc_filename(string *filename, string *prior)
|
||||
{
|
||||
for(ModelComparisonStatement::filename_list_type::iterator it = filename_list.begin();
|
||||
it != filename_list.end(); it++)
|
||||
for (ModelComparisonStatement::filename_list_type::iterator it = filename_list.begin();
|
||||
it != filename_list.end(); it++)
|
||||
if ((*it).first == *filename)
|
||||
error("model_comparison: filename " + *filename + " declared twice");
|
||||
filename_list.push_back(make_pair(*filename, *prior));
|
||||
|
@ -1218,17 +1218,17 @@ ParsingDriver::svar()
|
|||
it0 = options_list.string_options.find("ms.coefficients");
|
||||
it1 = options_list.string_options.find("ms.variances");
|
||||
it2 = options_list.string_options.find("ms.constants");
|
||||
if (it0 == options_list.string_options.end() &&
|
||||
it1 == options_list.string_options.end() &&
|
||||
it2 == options_list.string_options.end())
|
||||
if (it0 == options_list.string_options.end()
|
||||
&& it1 == options_list.string_options.end()
|
||||
&& it2 == options_list.string_options.end())
|
||||
error("You must pass one of 'coefficients', 'variances', or 'constants'.");
|
||||
|
||||
if ((it0 != options_list.string_options.end() &&
|
||||
it1 != options_list.string_options.end()) ||
|
||||
(it1 != options_list.string_options.end() &&
|
||||
it2 != options_list.string_options.end()) ||
|
||||
(it0 != options_list.string_options.end() &&
|
||||
it2 != options_list.string_options.end()))
|
||||
if ((it0 != options_list.string_options.end()
|
||||
&& it1 != options_list.string_options.end())
|
||||
|| (it1 != options_list.string_options.end()
|
||||
&& it2 != options_list.string_options.end())
|
||||
|| (it0 != options_list.string_options.end()
|
||||
&& it2 != options_list.string_options.end()))
|
||||
error("You may only pass one 'coefficients', 'variances', or 'constants' option.");
|
||||
|
||||
it0 = options_list.num_options.find("ms.chain");
|
||||
|
@ -1239,7 +1239,7 @@ ParsingDriver::svar()
|
|||
|
||||
itv = options_list.vector_int_options.find("ms.equations");
|
||||
if (itv != options_list.vector_int_options.end())
|
||||
for (vector<int>::const_iterator viit=itv->second.begin(); viit != itv->second.end(); viit++)
|
||||
for (vector<int>::const_iterator viit = itv->second.begin(); viit != itv->second.end(); viit++)
|
||||
if (*viit <= 0)
|
||||
error("The value(s) passed to the equation option must be greater than zero.");
|
||||
|
||||
|
@ -1258,14 +1258,14 @@ ParsingDriver::markov_switching()
|
|||
else if (atoi(it0->second.c_str()) <= 0)
|
||||
error("The value passed to the chain option must be greater than zero.");
|
||||
|
||||
it0=options_list.num_options.find("ms.state");
|
||||
it1=options_list.num_options.find("ms.number_of_states");
|
||||
if ((it0 == options_list.num_options.end()) &&
|
||||
(it1 == options_list.num_options.end()))
|
||||
it0 = options_list.num_options.find("ms.state");
|
||||
it1 = options_list.num_options.find("ms.number_of_states");
|
||||
if ((it0 == options_list.num_options.end())
|
||||
&& (it1 == options_list.num_options.end()))
|
||||
error("Either a state option or a number_of_states option must be passed to the markov_switching statement.");
|
||||
|
||||
if ((it0 != options_list.num_options.end()) &&
|
||||
(it1 != options_list.num_options.end()))
|
||||
if ((it0 != options_list.num_options.end())
|
||||
&& (it1 != options_list.num_options.end()))
|
||||
error("You cannot pass both a state option and a number_of_states option to the markov_switching statement.");
|
||||
|
||||
if (it0 != options_list.num_options.end())
|
||||
|
@ -1276,7 +1276,7 @@ ParsingDriver::markov_switching()
|
|||
if (atoi(it1->second.c_str()) <= 0)
|
||||
error("The value passed to the number_of_states option must be greater than zero.");
|
||||
|
||||
string infStr ("Inf");
|
||||
string infStr("Inf");
|
||||
it0 = options_list.num_options.find("ms.duration");
|
||||
if (it0 == options_list.num_options.end())
|
||||
error("A duration option must be passed to the markov_switching statement.");
|
||||
|
@ -1346,7 +1346,7 @@ ParsingDriver::declare_and_init_model_local_variable(string *name, NodeID rhs)
|
|||
{
|
||||
mod_file->symbol_table.addSymbol(*name, eModelLocalVariable);
|
||||
}
|
||||
catch(SymbolTable::AlreadyDeclaredException &e)
|
||||
catch (SymbolTable::AlreadyDeclaredException &e)
|
||||
{
|
||||
error("Local model variable " + *name + " declared twice.");
|
||||
}
|
||||
|
@ -1358,15 +1358,15 @@ ParsingDriver::declare_and_init_model_local_variable(string *name, NodeID rhs)
|
|||
void
|
||||
ParsingDriver::change_type(SymbolType new_type, vector<string *> *var_list)
|
||||
{
|
||||
for(vector<string *>::iterator it = var_list->begin();
|
||||
it != var_list->end(); it++)
|
||||
for (vector<string *>::iterator it = var_list->begin();
|
||||
it != var_list->end(); it++)
|
||||
{
|
||||
int id;
|
||||
try
|
||||
{
|
||||
id = mod_file->symbol_table.getID(**it);
|
||||
}
|
||||
catch(SymbolTable::UnknownSymbolNameException &e)
|
||||
catch (SymbolTable::UnknownSymbolNameException &e)
|
||||
{
|
||||
error("Unknown variable " + **it);
|
||||
}
|
||||
|
@ -1562,19 +1562,19 @@ ParsingDriver::add_sqrt(NodeID arg1)
|
|||
NodeID
|
||||
ParsingDriver::add_max(NodeID arg1, NodeID arg2)
|
||||
{
|
||||
return data_tree->AddMax(arg1,arg2);
|
||||
return data_tree->AddMax(arg1, arg2);
|
||||
}
|
||||
|
||||
NodeID
|
||||
ParsingDriver::add_min(NodeID arg1, NodeID arg2)
|
||||
{
|
||||
return data_tree->AddMin(arg1,arg2);
|
||||
return data_tree->AddMin(arg1, arg2);
|
||||
}
|
||||
|
||||
NodeID
|
||||
ParsingDriver::add_normcdf(NodeID arg1, NodeID arg2, NodeID arg3)
|
||||
{
|
||||
return data_tree->AddNormcdf(arg1,arg2,arg3);
|
||||
return data_tree->AddNormcdf(arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
NodeID
|
||||
|
|
|
@ -50,7 +50,6 @@ 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.
|
||||
|
@ -58,7 +57,7 @@ using namespace std;
|
|||
class DynareFlex : public DynareFlexLexer
|
||||
{
|
||||
public:
|
||||
DynareFlex(istream* in = 0, ostream* out = 0);
|
||||
DynareFlex(istream *in = 0, ostream *out = 0);
|
||||
|
||||
//! The main lexing function
|
||||
Dynare::parser::token_type lex(Dynare::parser::semantic_type *yylval,
|
||||
|
@ -210,7 +209,7 @@ public:
|
|||
//! Changes type of a symbol
|
||||
void change_type(SymbolType new_type, vector<string *> *var_list);
|
||||
//! Adds a list of tags for the current equation
|
||||
void add_equation_tags(string *key, string *value);
|
||||
void add_equation_tags(string *key, string *value);
|
||||
//! Adds a constant to DataTree
|
||||
NodeID add_constant(string *constant);
|
||||
//! Adds a NaN constant to DataTree
|
||||
|
|
|
@ -39,8 +39,8 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
|
|||
{
|
||||
int exo_det_length = 0;
|
||||
|
||||
for(det_shocks_type::const_iterator it = det_shocks.begin();
|
||||
it != det_shocks.end(); it++)
|
||||
for (det_shocks_type::const_iterator it = det_shocks.begin();
|
||||
it != det_shocks.end(); it++)
|
||||
{
|
||||
int id = symbol_table.getTypeSpecificID(it->first) + 1;
|
||||
bool exo_det = (symbol_table.getType(it->first) == eExogenousDet);
|
||||
|
@ -80,7 +80,6 @@ AbstractShocksStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
mod_file_struct.shocks_present = true;
|
||||
}
|
||||
|
||||
|
||||
ShocksStatement::ShocksStatement(const det_shocks_type &det_shocks_arg,
|
||||
const var_and_std_shocks_type &var_shocks_arg,
|
||||
const var_and_std_shocks_type &std_shocks_arg,
|
||||
|
@ -119,7 +118,7 @@ ShocksStatement::writeVarAndStdShocks(ostream &output) const
|
|||
{
|
||||
var_and_std_shocks_type::const_iterator it;
|
||||
|
||||
for(it = var_shocks.begin(); it != var_shocks.end(); it++)
|
||||
for (it = var_shocks.begin(); it != var_shocks.end(); it++)
|
||||
{
|
||||
int id = symbol_table.getTypeSpecificID(it->first) + 1;
|
||||
const NodeID value = it->second;
|
||||
|
@ -128,7 +127,7 @@ ShocksStatement::writeVarAndStdShocks(ostream &output) const
|
|||
output << ";" << endl;
|
||||
}
|
||||
|
||||
for(it = std_shocks.begin(); it != std_shocks.end(); it++)
|
||||
for (it = std_shocks.begin(); it != std_shocks.end(); it++)
|
||||
{
|
||||
int id = symbol_table.getTypeSpecificID(it->first) + 1;
|
||||
const NodeID value = it->second;
|
||||
|
@ -143,7 +142,7 @@ ShocksStatement::writeCovarAndCorrShocks(ostream &output) const
|
|||
{
|
||||
covar_and_corr_shocks_type::const_iterator it;
|
||||
|
||||
for(it = covar_shocks.begin(); it != covar_shocks.end(); it++)
|
||||
for (it = covar_shocks.begin(); it != covar_shocks.end(); it++)
|
||||
{
|
||||
int id1 = symbol_table.getTypeSpecificID(it->first.first) + 1;
|
||||
int id2 = symbol_table.getTypeSpecificID(it->first.second) + 1;
|
||||
|
@ -154,7 +153,7 @@ ShocksStatement::writeCovarAndCorrShocks(ostream &output) const
|
|||
<< id1 << ", " << id2 << ");\n";
|
||||
}
|
||||
|
||||
for(it = corr_shocks.begin(); it != corr_shocks.end(); it++)
|
||||
for (it = corr_shocks.begin(); it != corr_shocks.end(); it++)
|
||||
{
|
||||
int id1 = symbol_table.getTypeSpecificID(it->first.first) + 1;
|
||||
int id2 = symbol_table.getTypeSpecificID(it->first.second) + 1;
|
||||
|
@ -196,12 +195,12 @@ ConditionalForecastPathsStatement::ConditionalForecastPathsStatement(const Abstr
|
|||
void
|
||||
ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
for(AbstractShocksStatement::det_shocks_type::const_iterator it = paths.begin();
|
||||
it != paths.end(); it++)
|
||||
for (AbstractShocksStatement::det_shocks_type::const_iterator it = paths.begin();
|
||||
it != paths.end(); it++)
|
||||
{
|
||||
int this_path_length = 0;
|
||||
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
|
||||
for(int i = 0; i < (int) elems.size(); i++)
|
||||
for (int i = 0; i < (int) elems.size(); i++)
|
||||
// Period1 < Period2, as enforced in ParsingDriver::add_period()
|
||||
this_path_length = max(this_path_length, elems[i].period2);
|
||||
if (path_length == -1)
|
||||
|
@ -223,13 +222,13 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
|
|||
|
||||
int k = 1;
|
||||
|
||||
for(AbstractShocksStatement::det_shocks_type::const_iterator it = paths.begin();
|
||||
it != paths.end(); it++)
|
||||
for (AbstractShocksStatement::det_shocks_type::const_iterator it = paths.begin();
|
||||
it != paths.end(); it++)
|
||||
{
|
||||
output << "constrained_vars_ = strvcat(constrained_vars_, '" << it->first << "');" << endl;
|
||||
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
|
||||
for(int i = 0; i < (int) elems.size(); i++)
|
||||
for(int j = elems[i].period1; j <= elems[i].period2; j++)
|
||||
for (int i = 0; i < (int) elems.size(); i++)
|
||||
for (int j = elems[i].period1; j <= elems[i].period2; j++)
|
||||
{
|
||||
output << "constrained_paths_(" << k << "," << j << ")=";
|
||||
elems[i].value->writeOutput(output);
|
||||
|
|
|
@ -51,7 +51,7 @@ SigmaeStatement::determineMatrixForm(const matrix_type &matrix) throw (MatrixFor
|
|||
// each row has one element more or less than the previous one
|
||||
// and first or last one has one element.
|
||||
matrix_type::const_iterator ir;
|
||||
for (ir = matrix.begin(), ir++; ir != matrix.end(); ir++, nbe += inc )
|
||||
for (ir = matrix.begin(), ir++; ir != matrix.end(); ir++, nbe += inc)
|
||||
if (ir->size() != nbe)
|
||||
throw MatrixFormException();
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ private:
|
|||
/*! Throws an exception if it is neither upper triangular nor lower triangular */
|
||||
static matrix_form_type determineMatrixForm(const matrix_type &matrix) throw (MatrixFormException);
|
||||
|
||||
public :
|
||||
public:
|
||||
SigmaeStatement(const matrix_type &matrix_arg) throw (MatrixFormException);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
|
|
@ -64,32 +64,32 @@ NativeStatement::writeOutput(ostream &output, const string &basename) const
|
|||
void
|
||||
OptionsList::writeOutput(ostream &output) const
|
||||
{
|
||||
for(num_options_type::const_iterator it = num_options.begin();
|
||||
it != num_options.end(); it++)
|
||||
for (num_options_type::const_iterator it = num_options.begin();
|
||||
it != num_options.end(); it++)
|
||||
output << "options_." << it->first << " = " << it->second << ";" << endl;
|
||||
|
||||
for(paired_num_options_type::const_iterator it = paired_num_options.begin();
|
||||
it != paired_num_options.end(); it++)
|
||||
for (paired_num_options_type::const_iterator it = paired_num_options.begin();
|
||||
it != paired_num_options.end(); it++)
|
||||
output << "options_." << it->first << " = [" << it->second.first << "; "
|
||||
<< it->second.second << "];" << endl;
|
||||
|
||||
for(string_options_type::const_iterator it = string_options.begin();
|
||||
it != string_options.end(); it++)
|
||||
for (string_options_type::const_iterator it = string_options.begin();
|
||||
it != string_options.end(); it++)
|
||||
output << "options_." << it->first << " = '" << it->second << "';" << endl;
|
||||
|
||||
for(symbol_list_options_type::const_iterator it = symbol_list_options.begin();
|
||||
it != symbol_list_options.end(); it++)
|
||||
for (symbol_list_options_type::const_iterator it = symbol_list_options.begin();
|
||||
it != symbol_list_options.end(); it++)
|
||||
it->second.writeOutput("options_." + it->first, output);
|
||||
|
||||
for(vec_int_options_type::const_iterator it = vector_int_options.begin();
|
||||
it != vector_int_options.end(); it++)
|
||||
for (vec_int_options_type::const_iterator it = vector_int_options.begin();
|
||||
it != vector_int_options.end(); it++)
|
||||
{
|
||||
output << "options_." << it->first << " = ";
|
||||
if (it->second.size() > 1)
|
||||
{
|
||||
output << "[";
|
||||
for (vector<int>::const_iterator viit=it->second.begin();
|
||||
viit!=it->second.end(); viit++)
|
||||
for (vector<int>::const_iterator viit = it->second.begin();
|
||||
viit != it->second.end(); viit++)
|
||||
output << *viit << ";";
|
||||
output << "];" << endl;
|
||||
}
|
||||
|
@ -103,32 +103,32 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
|
|||
{
|
||||
output << option_group << " = struct();" << endl;
|
||||
|
||||
for(num_options_type::const_iterator it = num_options.begin();
|
||||
it != num_options.end(); it++)
|
||||
for (num_options_type::const_iterator it = num_options.begin();
|
||||
it != num_options.end(); it++)
|
||||
output << option_group << "." << it->first << " = " << it->second << ";" << endl;
|
||||
|
||||
for(paired_num_options_type::const_iterator it = paired_num_options.begin();
|
||||
it != paired_num_options.end(); it++)
|
||||
for (paired_num_options_type::const_iterator it = paired_num_options.begin();
|
||||
it != paired_num_options.end(); it++)
|
||||
output << option_group << "." << it->first << " = [" << it->second.first << "; "
|
||||
<< it->second.second << "];" << endl;
|
||||
|
||||
for(string_options_type::const_iterator it = string_options.begin();
|
||||
it != string_options.end(); it++)
|
||||
for (string_options_type::const_iterator it = string_options.begin();
|
||||
it != string_options.end(); it++)
|
||||
output << option_group << "." << it->first << " = '" << it->second << "';" << endl;
|
||||
|
||||
for(symbol_list_options_type::const_iterator it = symbol_list_options.begin();
|
||||
it != symbol_list_options.end(); it++)
|
||||
for (symbol_list_options_type::const_iterator it = symbol_list_options.begin();
|
||||
it != symbol_list_options.end(); it++)
|
||||
it->second.writeOutput(option_group + "." + it->first, output);
|
||||
|
||||
for(vec_int_options_type::const_iterator it = vector_int_options.begin();
|
||||
it != vector_int_options.end(); it++)
|
||||
for (vec_int_options_type::const_iterator it = vector_int_options.begin();
|
||||
it != vector_int_options.end(); it++)
|
||||
{
|
||||
output << option_group << "." << it->first << " = ";
|
||||
if (it->second.size() > 1)
|
||||
{
|
||||
output << "[";
|
||||
for (vector<int>::const_iterator viit=it->second.begin();
|
||||
viit!=it->second.end(); viit++)
|
||||
for (vector<int>::const_iterator viit = it->second.begin();
|
||||
viit != it->second.end(); viit++)
|
||||
output << *viit << ";";
|
||||
output << "];" << endl;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -44,7 +44,6 @@ private:
|
|||
|
||||
vector<temporary_terms_inuse_type> v_temporary_terms_inuse;
|
||||
|
||||
|
||||
typedef map< pair< int, pair< int, int> >, NodeID> first_chain_rule_derivatives_type;
|
||||
first_chain_rule_derivatives_type first_chain_rule_derivatives;
|
||||
|
||||
|
@ -54,7 +53,6 @@ private:
|
|||
//! Writes the static function calling the block to solve (Matlab version)
|
||||
void writeStaticBlockMFSFile(const string &basename) const;
|
||||
|
||||
|
||||
//! Writes static model file (C version)
|
||||
/*! \todo add third derivatives handling */
|
||||
void writeStaticCFile(const string &static_basename) const;
|
||||
|
@ -154,9 +152,9 @@ public:
|
|||
double cutoff;
|
||||
//! Compute the minimum feedback set in the static model:
|
||||
/*! 0 : all endogenous variables are considered as feedback variables
|
||||
1 : the variables belonging to a non linear equation are considered as feedback variables
|
||||
2 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
|
||||
default value = 0 */
|
||||
1 : the variables belonging to a non linear equation are considered as feedback variables
|
||||
2 : 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;
|
||||
|
@ -187,36 +185,95 @@ public:
|
|||
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
|
||||
|
||||
//! Return the number of blocks
|
||||
virtual unsigned int getNbBlocks() const {return(block_type_firstequation_size_mfs.size());};
|
||||
virtual unsigned int
|
||||
getNbBlocks() const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs.size());
|
||||
};
|
||||
//! Determine the simulation type of each block
|
||||
virtual BlockSimulationType getBlockSimulationType(int block_number) const {return(block_type_firstequation_size_mfs[block_number].first.first);};
|
||||
virtual BlockSimulationType
|
||||
getBlockSimulationType(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].first.first);
|
||||
};
|
||||
//! Return the first equation number of a block
|
||||
virtual unsigned int getBlockFirstEquation(int block_number) const {return(block_type_firstequation_size_mfs[block_number].first.second);};
|
||||
virtual unsigned int
|
||||
getBlockFirstEquation(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].first.second);
|
||||
};
|
||||
//! Return the size of the block block_number
|
||||
virtual unsigned int getBlockSize(int block_number) const {return(block_type_firstequation_size_mfs[block_number].second.first);};
|
||||
virtual unsigned int
|
||||
getBlockSize(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].second.first);
|
||||
};
|
||||
//! Return the number of feedback variable of the block block_number
|
||||
virtual unsigned int getBlockMfs(int block_number) const {return(block_type_firstequation_size_mfs[block_number].second.second);};
|
||||
virtual unsigned int
|
||||
getBlockMfs(int block_number) const
|
||||
{
|
||||
return (block_type_firstequation_size_mfs[block_number].second.second);
|
||||
};
|
||||
//! Return the maximum lag in a block
|
||||
virtual unsigned int getBlockMaxLag(int block_number) const {return(block_lag_lead[block_number].first);};
|
||||
virtual unsigned int
|
||||
getBlockMaxLag(int block_number) const
|
||||
{
|
||||
return (block_lag_lead[block_number].first);
|
||||
};
|
||||
//! Return the maximum lead in a block
|
||||
virtual unsigned int getBlockMaxLead(int block_number) const {return(block_lag_lead[block_number].second);};
|
||||
virtual unsigned int
|
||||
getBlockMaxLead(int block_number) const
|
||||
{
|
||||
return (block_lag_lead[block_number].second);
|
||||
};
|
||||
//! Return the type of equation (equation_number) belonging to the block block_number
|
||||
virtual EquationType getBlockEquationType(int block_number, int equation_number) const {return( equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first);};
|
||||
virtual EquationType
|
||||
getBlockEquationType(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first);
|
||||
};
|
||||
//! Return true if the equation has been normalized
|
||||
virtual bool isBlockEquationRenormalized(int block_number, int equation_number) const {return( equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first == E_EVALUATE_S);};
|
||||
virtual bool
|
||||
isBlockEquationRenormalized(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].first == E_EVALUATE_S);
|
||||
};
|
||||
//! Return the NodeID of the equation equation_number belonging to the block block_number
|
||||
virtual NodeID getBlockEquationNodeID(int block_number, int equation_number) const {return( equations[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]]);};
|
||||
virtual NodeID
|
||||
getBlockEquationNodeID(int block_number, int equation_number) const
|
||||
{
|
||||
return (equations[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]]);
|
||||
};
|
||||
//! Return the NodeID of the renormalized equation equation_number belonging to the block block_number
|
||||
virtual NodeID getBlockEquationRenormalizedNodeID(int block_number, int equation_number) const {return( equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].second);};
|
||||
virtual NodeID
|
||||
getBlockEquationRenormalizedNodeID(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_type_and_normalized_equation[equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]].second);
|
||||
};
|
||||
//! Return the original number of equation equation_number belonging to the block block_number
|
||||
virtual int getBlockEquationID(int block_number, int equation_number) const {return( equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]);};
|
||||
virtual int
|
||||
getBlockEquationID(int block_number, int equation_number) const
|
||||
{
|
||||
return (equation_reordered[block_type_firstequation_size_mfs[block_number].first.second+equation_number]);
|
||||
};
|
||||
//! Return the original number of variable variable_number belonging to the block block_number
|
||||
virtual int getBlockVariableID(int block_number, int variable_number) const {return( variable_reordered[block_type_firstequation_size_mfs[block_number].first.second+variable_number]);};
|
||||
virtual int
|
||||
getBlockVariableID(int block_number, int variable_number) const
|
||||
{
|
||||
return (variable_reordered[block_type_firstequation_size_mfs[block_number].first.second+variable_number]);
|
||||
};
|
||||
//! Return the position of equation_number in the block number belonging to the block block_number
|
||||
virtual int getBlockInitialEquationID(int block_number, int equation_number) const {return((int)inv_equation_reordered[equation_number] - (int)block_type_firstequation_size_mfs[block_number].first.second);};
|
||||
virtual int
|
||||
getBlockInitialEquationID(int block_number, int equation_number) const
|
||||
{
|
||||
return ((int) inv_equation_reordered[equation_number] - (int) block_type_firstequation_size_mfs[block_number].first.second);
|
||||
};
|
||||
//! Return the position of variable_number in the block number belonging to the block block_number
|
||||
virtual int getBlockInitialVariableID(int block_number, int variable_number) const {return((int)inv_variable_reordered[variable_number] - (int)block_type_firstequation_size_mfs[block_number].first.second);};
|
||||
|
||||
virtual int
|
||||
getBlockInitialVariableID(int block_number, int variable_number) const
|
||||
{
|
||||
return ((int) inv_variable_reordered[variable_number] - (int) block_type_firstequation_size_mfs[block_number].first.second);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclar
|
|||
// Construct "tex_name" by prepending an antislash to all underscores in "name"
|
||||
string tex_name = name;
|
||||
size_t pos = 0;
|
||||
while((pos = tex_name.find('_', pos)) != string::npos)
|
||||
while ((pos = tex_name.find('_', pos)) != string::npos)
|
||||
{
|
||||
tex_name.insert(pos, "\\");
|
||||
pos += 2;
|
||||
|
@ -74,10 +74,10 @@ SymbolTable::freeze() throw (FrozenException)
|
|||
|
||||
frozen = true;
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
int tsi;
|
||||
switch(getType(i))
|
||||
switch (getType(i))
|
||||
{
|
||||
case eEndogenous:
|
||||
tsi = endo_ids.size();
|
||||
|
@ -121,7 +121,7 @@ SymbolTable::getID(SymbolType type, int tsid) const throw (UnknownTypeSpecificID
|
|||
if (!frozen)
|
||||
throw NotYetFrozenException();
|
||||
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case eEndogenous:
|
||||
if (tsid < 0 || tsid >= (int) endo_ids.size())
|
||||
|
@ -207,11 +207,11 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
|||
if (aux_vars.size() == 0)
|
||||
output << "M_.aux_vars = [];" << endl;
|
||||
else
|
||||
for(int i = 0; i < (int) aux_vars.size(); i++)
|
||||
for (int i = 0; i < (int) aux_vars.size(); i++)
|
||||
{
|
||||
output << "M_.aux_vars(" << i+1 << ").endo_index = " << getTypeSpecificID(aux_vars[i].symb_id)+1 << ";" << endl
|
||||
<< "M_.aux_vars(" << i+1 << ").type = " << aux_vars[i].type << ";" << endl;
|
||||
switch(aux_vars[i].type)
|
||||
switch (aux_vars[i].type)
|
||||
{
|
||||
case avEndoLead:
|
||||
case avExoLead:
|
||||
|
@ -228,8 +228,8 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
|||
if (predeterminedNbr() > 0)
|
||||
{
|
||||
output << "M_.predetermined_variables = [ ";
|
||||
for(set<int>::const_iterator it = predetermined_variables.begin();
|
||||
it != predetermined_variables.end(); it++)
|
||||
for (set<int>::const_iterator it = predetermined_variables.begin();
|
||||
it != predetermined_variables.end(); it++)
|
||||
output << getTypeSpecificID(*it)+1 << " ";
|
||||
output << "];" << endl;
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenExce
|
|||
{
|
||||
symb_id = addSymbol(varname.str(), eEndogenous);
|
||||
}
|
||||
catch(AlreadyDeclaredException &e)
|
||||
catch (AlreadyDeclaredException &e)
|
||||
{
|
||||
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -278,7 +278,7 @@ SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_le
|
|||
{
|
||||
symb_id = addSymbol(varname.str(), eEndogenous);
|
||||
}
|
||||
catch(AlreadyDeclaredException &e)
|
||||
catch (AlreadyDeclaredException &e)
|
||||
{
|
||||
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -329,7 +329,7 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index) throw (F
|
|||
{
|
||||
symb_id = addSymbol(varname.str(), eEndogenous);
|
||||
}
|
||||
catch(AlreadyDeclaredException &e)
|
||||
catch (AlreadyDeclaredException &e)
|
||||
{
|
||||
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -362,11 +362,11 @@ SymbolTable::isPredetermined(int symb_id) const throw (UnknownSymbolIDException)
|
|||
if (symb_id < 0 || symb_id >= size)
|
||||
throw UnknownSymbolIDException(symb_id);
|
||||
|
||||
return(predetermined_variables.find(symb_id) != predetermined_variables.end());
|
||||
return (predetermined_variables.find(symb_id) != predetermined_variables.end());
|
||||
}
|
||||
|
||||
int
|
||||
SymbolTable::predeterminedNbr() const
|
||||
{
|
||||
return(predetermined_variables.size());
|
||||
return (predetermined_variables.size());
|
||||
}
|
||||
|
|
|
@ -104,7 +104,9 @@ public:
|
|||
public:
|
||||
//! Symbol name
|
||||
string name;
|
||||
UnknownSymbolNameException(const string &name_arg) : name(name_arg) {}
|
||||
UnknownSymbolNameException(const string &name_arg) : name(name_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
//! Thrown when trying to access an unknown symbol (by id)
|
||||
class UnknownSymbolIDException
|
||||
|
@ -112,7 +114,9 @@ public:
|
|||
public:
|
||||
//! Symbol ID
|
||||
int id;
|
||||
UnknownSymbolIDException(int id_arg) : id(id_arg) {}
|
||||
UnknownSymbolIDException(int id_arg) : id(id_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
//! Thrown when trying to access an unknown type specific ID
|
||||
class UnknownTypeSpecificIDException
|
||||
|
@ -120,7 +124,9 @@ public:
|
|||
public:
|
||||
int tsid;
|
||||
SymbolType type;
|
||||
UnknownTypeSpecificIDException(int tsid_arg, SymbolType type_arg) : tsid(tsid_arg), type(type_arg) {}
|
||||
UnknownTypeSpecificIDException(int tsid_arg, SymbolType type_arg) : tsid(tsid_arg), type(type_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
//! Thrown when trying to declare a symbol twice
|
||||
class AlreadyDeclaredException
|
||||
|
@ -130,7 +136,9 @@ public:
|
|||
string name;
|
||||
//! Was the previous declaration done with the same symbol type ?
|
||||
bool same_type;
|
||||
AlreadyDeclaredException(const string &name_arg, bool same_type_arg) : name(name_arg), same_type(same_type_arg) {}
|
||||
AlreadyDeclaredException(const string &name_arg, bool same_type_arg) : name(name_arg), same_type(same_type_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
//! Thrown when table is frozen and trying to modify it
|
||||
class FrozenException
|
||||
|
@ -332,7 +340,7 @@ SymbolTable::param_nbr() const throw (NotYetFrozenException)
|
|||
inline int
|
||||
SymbolTable::maxID()
|
||||
{
|
||||
return(size-1);
|
||||
return (size-1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,8 @@ MacroDriver::MacroDriver()
|
|||
|
||||
MacroDriver::~MacroDriver()
|
||||
{
|
||||
for(set<const MacroValue *>::iterator it = values.begin();
|
||||
it != values.end(); it++)
|
||||
for (set<const MacroValue *>::iterator it = values.begin();
|
||||
it != values.end(); it++)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,9 @@ private:
|
|||
const string &for_body_arg,
|
||||
Macro::parser::location_type &for_body_loc_arg) :
|
||||
input(input_arg), buffer(buffer_arg), yylloc(yylloc_arg), is_for_context(is_for_context_arg),
|
||||
for_body(for_body_arg), for_body_loc(for_body_loc_arg) { }
|
||||
for_body(for_body_arg), for_body_loc(for_body_loc_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//! The stack used to keep track of nested scanning contexts
|
||||
|
@ -134,7 +136,7 @@ private:
|
|||
void new_loop_body_buffer(Macro::parser::location_type *yylloc);
|
||||
|
||||
public:
|
||||
MacroFlex(istream* in, ostream* out, bool no_line_macro_arg);
|
||||
MacroFlex(istream *in, ostream *out, bool no_line_macro_arg);
|
||||
|
||||
//! The main lexing function
|
||||
Macro::parser::token_type lex(Macro::parser::semantic_type *yylval,
|
||||
|
@ -162,7 +164,9 @@ public:
|
|||
{
|
||||
public:
|
||||
const string name;
|
||||
UnknownVariable(const string &name_arg) : name(name_arg) {}
|
||||
UnknownVariable(const string &name_arg) : name(name_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
|
|
|
@ -302,8 +302,8 @@ IntMV::in(const MacroValue *array) const throw (TypeError)
|
|||
throw TypeError("Type mismatch for 'in' operator");
|
||||
|
||||
int result = 0;
|
||||
for(vector<int>::const_iterator it = array2->values.begin();
|
||||
it != array2->values.end(); it++)
|
||||
for (vector<int>::const_iterator it = array2->values.begin();
|
||||
it != array2->values.end(); it++)
|
||||
if (*it == value)
|
||||
{
|
||||
result = 1;
|
||||
|
@ -331,7 +331,7 @@ IntMV::new_range(MacroDriver &driver, const MacroValue *mv1, const MacroValue *m
|
|||
v2 = v1;
|
||||
v1 = x;
|
||||
}
|
||||
for(; v1 <= v2; v1++)
|
||||
for (; v1 <= v2; v1++)
|
||||
result.push_back(v1);
|
||||
return new ArrayMV<int>(driver, result);
|
||||
}
|
||||
|
@ -381,8 +381,8 @@ StringMV::operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsEr
|
|||
if (mv2 == NULL)
|
||||
throw TypeError("Expression inside [] must be an integer array");
|
||||
string result;
|
||||
for(vector<int>::const_iterator it = mv2->values.begin();
|
||||
it != mv2->values.end(); it++)
|
||||
for (vector<int>::const_iterator it = mv2->values.begin();
|
||||
it != mv2->values.end(); it++)
|
||||
{
|
||||
if (*it < 1 || *it > (int) value.length())
|
||||
throw OutOfBoundsError();
|
||||
|
@ -426,8 +426,8 @@ StringMV::in(const MacroValue *array) const throw (TypeError)
|
|||
throw TypeError("Type mismatch for 'in' operator");
|
||||
|
||||
int result = 0;
|
||||
for(vector<string>::const_iterator it = array2->values.begin();
|
||||
it != array2->values.end(); it++)
|
||||
for (vector<string>::const_iterator it = array2->values.begin();
|
||||
it != array2->values.end(); it++)
|
||||
if (*it == value)
|
||||
{
|
||||
result = 1;
|
||||
|
|
|
@ -40,7 +40,9 @@ public:
|
|||
{
|
||||
public:
|
||||
const string message;
|
||||
TypeError(const string &message_arg) : message(message_arg) {};
|
||||
TypeError(const string &message_arg) : message(message_arg)
|
||||
{
|
||||
};
|
||||
};
|
||||
//! Exception thrown when doing an out-of-bounds access through [] operator
|
||||
class OutOfBoundsError
|
||||
|
@ -251,11 +253,11 @@ ArrayMV<T>::operator-(const MacroValue &mv) const throw (TypeError)
|
|||
/* Highly inefficient algorithm for computing set difference
|
||||
(but vector<T> is not suited for that...) */
|
||||
vector<T> new_values;
|
||||
for(typename vector<T>::const_iterator it = values.begin();
|
||||
it != values.end(); it++)
|
||||
for (typename vector<T>::const_iterator it = values.begin();
|
||||
it != values.end(); it++)
|
||||
{
|
||||
typename vector<T>::const_iterator it2;
|
||||
for(it2 = mv2->values.begin(); it2 != mv2->values.end(); it2++)
|
||||
for (it2 = mv2->values.begin(); it2 != mv2->values.end(); it2++)
|
||||
if (*it == *it2)
|
||||
break;
|
||||
if (it2 == mv2->values.end())
|
||||
|
@ -295,8 +297,8 @@ ArrayMV<T>::operator[](const MacroValue &mv) const throw (TypeError, OutOfBounds
|
|||
if (mv2 == NULL)
|
||||
throw TypeError("Expression inside [] must be an integer array");
|
||||
vector<T> result;
|
||||
for(vector<int>::const_iterator it = mv2->values.begin();
|
||||
it != mv2->values.end(); it++)
|
||||
for (vector<int>::const_iterator it = mv2->values.begin();
|
||||
it != mv2->values.end(); it++)
|
||||
{
|
||||
if (*it < 1 || *it > (int) values.size())
|
||||
throw OutOfBoundsError();
|
||||
|
@ -314,8 +316,8 @@ string
|
|||
ArrayMV<T>::toString() const
|
||||
{
|
||||
ostringstream ss;
|
||||
for(typename vector<T>::const_iterator it = values.begin();
|
||||
it != values.end(); it++)
|
||||
for (typename vector<T>::const_iterator it = values.begin();
|
||||
it != values.end(); it++)
|
||||
ss << *it;
|
||||
return ss.str();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue