2019-06-19 14:34:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2006 Ondra Kamenik
|
|
|
|
* Copyright © 2019 Dynare Team
|
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-01-08 17:12:05 +01:00
|
|
|
|
|
|
|
#include "static_atoms.hh"
|
|
|
|
#include "utils/cc/exception.hh"
|
|
|
|
|
|
|
|
using namespace ogp;
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticAtoms::import_atoms(const DynamicAtoms &da, OperationTree &otree, Tintintmap &tmap)
|
|
|
|
{
|
|
|
|
Constants::import_constants(da, otree, tmap);
|
|
|
|
|
|
|
|
for (int i = 0; i < da.get_name_storage().num(); i++)
|
|
|
|
{
|
2019-04-24 14:52:30 +02:00
|
|
|
const string &name = da.get_name_storage().get_name(i);
|
2019-01-08 17:12:05 +01:00
|
|
|
register_name(name);
|
|
|
|
int tnew = otree.add_nulary();
|
|
|
|
assign(name, tnew);
|
|
|
|
if (da.is_referenced(name))
|
|
|
|
{
|
|
|
|
const DynamicAtoms::Tlagmap &lmap = da.lagmap(name);
|
2019-04-24 14:52:30 +02:00
|
|
|
for (const auto &it : lmap)
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
2019-01-09 15:44:26 +01:00
|
|
|
int told = it.second;
|
2019-04-19 17:09:04 +02:00
|
|
|
tmap.emplace(told, tnew);
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-04-24 14:52:30 +02:00
|
|
|
StaticAtoms::check(const string &name) const
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
|
|
|
if (DynamicAtoms::is_string_constant(name))
|
2019-04-19 17:09:04 +02:00
|
|
|
return Constants::check(name);
|
2019-01-08 17:12:05 +01:00
|
|
|
else
|
2019-04-19 17:09:04 +02:00
|
|
|
return check_variable(name);
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-04-24 14:52:30 +02:00
|
|
|
StaticAtoms::index(const string &name) const
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
2019-01-09 15:51:19 +01:00
|
|
|
auto it = vars.find(name);
|
2019-01-08 17:12:05 +01:00
|
|
|
if (it == vars.end())
|
|
|
|
return -1;
|
|
|
|
else
|
2019-04-19 17:09:04 +02:00
|
|
|
return it->second;
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-24 14:52:30 +02:00
|
|
|
StaticAtoms::assign(const string &name, int t)
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
|
|
|
if (DynamicAtoms::is_string_constant(name))
|
|
|
|
{
|
2019-04-23 18:57:52 +02:00
|
|
|
double val = std::stod(name);
|
2019-01-08 17:12:05 +01:00
|
|
|
add_constant(t, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-24 14:52:30 +02:00
|
|
|
varnames.insert(name);
|
|
|
|
vars.emplace(name, t);
|
|
|
|
indices.emplace(t, name);
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int>
|
|
|
|
StaticAtoms::variables() const
|
|
|
|
{
|
|
|
|
vector<int> res;
|
2019-04-24 14:52:30 +02:00
|
|
|
for (const auto &var : vars)
|
2019-04-19 17:09:04 +02:00
|
|
|
res.push_back(var.second);
|
2019-01-08 17:12:05 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-24 14:52:30 +02:00
|
|
|
StaticAtoms::register_name(string name)
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
2019-04-24 14:52:30 +02:00
|
|
|
varnames.insert(name);
|
|
|
|
varorder.push_back(std::move(name));
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticAtoms::print() const
|
|
|
|
{
|
2019-04-24 14:52:30 +02:00
|
|
|
std::cout << "constants:\n";
|
2019-01-08 17:12:05 +01:00
|
|
|
Constants::print();
|
2019-04-24 14:52:30 +02:00
|
|
|
std::cout << "variable names:\n";
|
2019-01-08 17:12:05 +01:00
|
|
|
varnames.print();
|
2019-04-24 14:52:30 +02:00
|
|
|
std::cout << "map to tree indices:\n";
|
2019-01-09 15:44:26 +01:00
|
|
|
for (auto var : vars)
|
2019-04-24 14:52:30 +02:00
|
|
|
std::cout << var.first << u8"\t→\t" << var.second << "\n";
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|