Added method for recognizing unreferenced atoms. Call to this method replace catching the exception used before to recognize that an atom is not referenced.

time-shift
Stéphane Adjemian (Sedna) 2015-03-25 14:52:28 +01:00
parent 64346de401
commit a97973d01f
4 changed files with 15 additions and 15 deletions

View File

@ -341,6 +341,12 @@ int DynamicAtoms::index(const char* name, int ll) const
return -1;
}
bool DynamicAtoms::is_referenced(const char* name) const
{
Tvarmap::const_iterator it = vars.find(name);
return it != vars.end();
}
const DynamicAtoms::Tlagmap& DynamicAtoms::lagmap(const char* name) const
{
Tvarmap::const_iterator it = vars.find(name);

View File

@ -182,6 +182,9 @@ namespace ogp {
/** Return index of the variable described by the variable
* name and lag/lead. If it doesn't exist, return -1. */
int index(const char* name, int ll) const;
/** Return true if a variable is referenced, i.e. it has lag
* map. */
bool is_referenced(const char* name) const;
/** Return the lag map for the variable name. */
const Tlagmap& lagmap(const char* name) const;
/** Return the variable name for the tree index. It throws an

View File

@ -41,15 +41,14 @@ void StaticAtoms::import_atoms(const DynamicAtoms& da, OperationTree& otree, Tin
register_name(name);
int tnew = otree.add_nulary();
assign(name, tnew);
try {
const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
if (da.is_referenced(name)) {
const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
int told = (*it).second;
tmap.insert(Tintintmap::value_type(told, tnew));
}
} catch (const ogu::Exception& e) {
}
}
}
}

View File

@ -135,22 +135,19 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
// set parameteres
for (unsigned int i = 0; i < atoms.get_params().size(); i++) {
try {
if (atoms.is_referenced(atoms.get_params()[i])) {
const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_params()[i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
int t = (*it).second;
et.set_nulary(t, paramvals[i]);
}
} catch (const ogu::Exception& e) {
// ignore non-referenced parameters; there is no
// lagmap for them
}
}
// set endogenous
for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) {
try {
if (atoms.is_referenced(atoms.get_endovars()[outer_i])) {
const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_endovars()[outer_i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
@ -165,15 +162,12 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
else
et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]);
}
} catch (const ogu::Exception& e) {
// ignore non-referenced endogenous variables; there is no
// lagmap for them
}
}
// set exogenous
for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) {
try {
if (atoms.is_referenced(atoms.get_exovars()[outer_i])) {
const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_exovars()[outer_i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
@ -184,8 +178,6 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
et.set_nulary(t, xx[i]);
}
}
} catch (const ogu::Exception& e) {
// ignore non-referenced variables
}
}
}