SymbolTable.cc 18.3 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 Dynare Team
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 * 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/>.
 */

#include <algorithm>
#include <sstream>
sebastien's avatar
sebastien committed
22
#include <iostream>
sebastien's avatar
sebastien committed
23
#include <cassert>
24
25
26

#include "SymbolTable.hh"

27
AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg,
28
                       int equation_number_for_multiplier_arg) :
29
30
31
32
  symb_id(symb_id_arg),
  type(type_arg),
  orig_symb_id(orig_symb_id_arg),
  orig_lead_lag(orig_lead_lag_arg),
33
  equation_number_for_multiplier(equation_number_for_multiplier_arg)
34
35
36
{
}

sebastien's avatar
sebastien committed
37
SymbolTable::SymbolTable() : frozen(false), size(0)
38
39
40
{
}

sebastien's avatar
sebastien committed
41
int
42
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const string &long_name) throw (AlreadyDeclaredException, FrozenException)
43
{
sebastien's avatar
sebastien committed
44
45
46
  if (frozen)
    throw FrozenException();

47
  if (exists(name))
48
    {
sebastien's avatar
sebastien committed
49
      if (type_table[getID(name)] == type)
50
51
52
53
        throw AlreadyDeclaredException(name, true);
      else
        throw AlreadyDeclaredException(name, false);
    }
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  string final_tex_name = tex_name;
  if (final_tex_name.empty())
    {
      final_tex_name = name;
      size_t pos = 0;
      while ((pos = final_tex_name.find('_', pos)) != string::npos)
        {
          final_tex_name.insert(pos, "\\");
          pos += 2;
        }
    }

  string final_long_name = long_name;
  if (final_long_name.empty())
    final_long_name = name;

sebastien's avatar
sebastien committed
71
72
73
74
75
  int id = size++;

  symbol_table[name] = id;
  type_table.push_back(type);
  name_table.push_back(name);
76
77
  tex_name_table.push_back(final_tex_name);
  long_name_table.push_back(final_long_name);
sebastien's avatar
sebastien committed
78
79

  return id;
sebastien's avatar
sebastien committed
80
81
}

sebastien's avatar
sebastien committed
82
int
83
SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
84
{
85
  return addSymbol(name, type, "", "");
86
87
}

sebastien's avatar
sebastien committed
88
89
90
91
92
void
SymbolTable::freeze() throw (FrozenException)
{
  if (frozen)
    throw FrozenException();
93

sebastien's avatar
sebastien committed
94
95
  frozen = true;

96
  for (int i = 0; i < size; i++)
97
    {
sebastien's avatar
sebastien committed
98
      int tsi;
99
      switch (getType(i))
sebastien's avatar
sebastien committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        {
        case eEndogenous:
          tsi = endo_ids.size();
          endo_ids.push_back(i);
          break;
        case eExogenous:
          tsi = exo_ids.size();
          exo_ids.push_back(i);
          break;
        case eExogenousDet:
          tsi = exo_det_ids.size();
          exo_det_ids.push_back(i);
          break;
        case eParameter:
          tsi = param_ids.size();
          param_ids.push_back(i);
          break;
        default:
          tsi = -1;
          break;
        }
      type_specific_ids.push_back(tsi);
    }
}

void
SymbolTable::changeType(int id, SymbolType newtype) throw (UnknownSymbolIDException, FrozenException)
{
  if (frozen)
    throw FrozenException();

  if (id < 0 || id >= size)
    throw UnknownSymbolIDException(id);

  type_table[id] = newtype;
}

int
SymbolTable::getID(SymbolType type, int tsid) const throw (UnknownTypeSpecificIDException, NotYetFrozenException)
{
  if (!frozen)
    throw NotYetFrozenException();

143
  switch (type)
sebastien's avatar
sebastien committed
144
145
146
147
148
149
    {
    case eEndogenous:
      if (tsid < 0 || tsid >= (int) endo_ids.size())
        throw UnknownTypeSpecificIDException(tsid, type);
      else
        return endo_ids[tsid];
150
    case eExogenous:
sebastien's avatar
sebastien committed
151
152
153
154
      if (tsid < 0 || tsid >= (int) exo_ids.size())
        throw UnknownTypeSpecificIDException(tsid, type);
      else
        return exo_ids[tsid];
155
    case eExogenousDet:
sebastien's avatar
sebastien committed
156
157
158
159
      if (tsid < 0 || tsid >= (int) exo_det_ids.size())
        throw UnknownTypeSpecificIDException(tsid, type);
      else
        return exo_det_ids[tsid];
160
    case eParameter:
sebastien's avatar
sebastien committed
161
162
163
164
165
166
      if (tsid < 0 || tsid >= (int) param_ids.size())
        throw UnknownTypeSpecificIDException(tsid, type);
      else
        return param_ids[tsid];
    default:
      throw UnknownTypeSpecificIDException(tsid, type);
167
168
169
170
    }
}

void
sebastien's avatar
sebastien committed
171
SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
172
{
sebastien's avatar
sebastien committed
173
174
175
176
  if (!frozen)
    throw NotYetFrozenException();

  if (exo_nbr() > 0)
177
    {
sebastien's avatar
sebastien committed
178
179
      output << "M_.exo_names = '" << getName(exo_ids[0]) << "';" << endl;
      output << "M_.exo_names_tex = '" << getTeXName(exo_ids[0]) << "';" << endl;
180
      output << "M_.exo_names_long = '" << getLongName(exo_ids[0]) << "';" << endl;
sebastien's avatar
sebastien committed
181
      for (int id = 1; id < exo_nbr(); id++)
182
        {
183
          output << "M_.exo_names = char(M_.exo_names, '" << getName(exo_ids[id]) << "');" << endl
184
185
                 << "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl
                 << "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl;
186
187
        }
    }
sebastien's avatar
sebastien committed
188
  if (exo_det_nbr() > 0)
189
    {
sebastien's avatar
sebastien committed
190
191
      output << "M_.exo_det_names = '" << getName(exo_det_ids[0]) << "';" << endl;
      output << "M_.exo_det_names_tex = '" << getTeXName(exo_det_ids[0]) << "';" << endl;
192
      output << "M_.exo_det_names_long = '" << getLongName(exo_det_ids[0]) << "';" << endl;
sebastien's avatar
sebastien committed
193
      for (int id = 1; id < exo_det_nbr(); id++)
194
        {
195
          output << "M_.exo_det_names = char(M_.exo_det_names, '" << getName(exo_det_ids[id]) << "');" << endl
196
197
                 << "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl
                 << "M_.exo_det_names_long = char(M_.exo_det_names_long, '" << getLongName(exo_det_ids[id]) << "');" << endl;
198
199
        }
    }
sebastien's avatar
sebastien committed
200
  if (endo_nbr() > 0)
201
    {
sebastien's avatar
sebastien committed
202
203
      output << "M_.endo_names = '" << getName(endo_ids[0]) << "';" << endl;
      output << "M_.endo_names_tex = '" << getTeXName(endo_ids[0]) << "';" << endl;
204
      output << "M_.endo_names_long = '" << getLongName(endo_ids[0]) << "';" << endl;
sebastien's avatar
sebastien committed
205
      for (int id = 1; id < endo_nbr(); id++)
206
        {
207
          output << "M_.endo_names = char(M_.endo_names, '" << getName(endo_ids[id]) << "');" << endl
208
209
                 << "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl
                 << "M_.endo_names_long = char(M_.endo_names_long, '" << getLongName(endo_ids[id]) << "');" << endl;
210
211
        }
    }
sebastien's avatar
sebastien committed
212
  if (param_nbr() > 0)
213
    {
sebastien's avatar
sebastien committed
214
215
      output << "M_.param_names = '" << getName(param_ids[0]) << "';" << endl;
      output << "M_.param_names_tex = '" << getTeXName(param_ids[0]) << "';" << endl;
216
      output << "M_.param_names_long = '" << getLongName(param_ids[0]) << "';" << endl;
sebastien's avatar
sebastien committed
217
      for (int id = 1; id < param_nbr(); id++)
218
        {
219
          output << "M_.param_names = char(M_.param_names, '" << getName(param_ids[id]) << "');" << endl
220
221
                 << "M_.param_names_tex = char(M_.param_names_tex, '" << getTeXName(param_ids[id]) << "');" << endl
                 << "M_.param_names_long = char(M_.param_names_long, '" << getLongName(param_ids[id]) << "');" << endl;
222
223
224

          if (getName(param_ids[id]) == "dsge_prior_weight")
            output << "options_.dsge_var = 1;" << endl;
225
226
227
        }
    }

sebastien's avatar
sebastien committed
228
229
230
231
  output << "M_.exo_det_nbr = " << exo_det_nbr() << ";" << endl
         << "M_.exo_nbr = " << exo_nbr() << ";" << endl
         << "M_.endo_nbr = " << endo_nbr() << ";" << endl
         << "M_.param_nbr = " << param_nbr() << ";" << endl;
232

sebastien's avatar
sebastien committed
233
  // Write the auxiliary variable table
234
  output << "M_.orig_endo_nbr = " << orig_endo_nbr() << ";" << endl;
sebastien's avatar
sebastien committed
235
236
237
  if (aux_vars.size() == 0)
    output << "M_.aux_vars = [];" << endl;
  else
238
    for (int i = 0; i < (int) aux_vars.size(); i++)
sebastien's avatar
sebastien committed
239
      {
240
241
242
        output << "M_.aux_vars(" << i+1 << ").endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id())+1 << ";" << endl
               << "M_.aux_vars(" << i+1 << ").type = " << aux_vars[i].get_type() << ";" << endl;
        switch (aux_vars[i].get_type())
sebastien's avatar
sebastien committed
243
244
245
246
247
248
249
          {
          case avEndoLead:
          case avExoLead:
          case avExpectation:
            break;
          case avEndoLag:
          case avExoLag:
250
251
            output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl
                   << "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
sebastien's avatar
sebastien committed
252
            break;
253
254
255
          case avMultiplier:
            output << "M_.aux_vars(" << i+1 << ").eq_nbr = '" << aux_vars[i].get_equation_number_for_multiplier() << "';" << endl;
            break;
256
257
258
          case avDiffForward:
            output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl;
            break;
sebastien's avatar
sebastien committed
259
260
          }
      }
sebastien's avatar
sebastien committed
261
262
263
264

  if (predeterminedNbr() > 0)
    {
      output << "M_.predetermined_variables = [ ";
265
266
      for (set<int>::const_iterator it = predetermined_variables.begin();
           it != predetermined_variables.end(); it++)
267
        output << getTypeSpecificID(*it)+1 << " ";
sebastien's avatar
sebastien committed
268
269
      output << "];" << endl;
    }
Sébastien Villemot's avatar
Sébastien Villemot committed
270
271
272
273
274
275

  if (observedVariablesNbr() > 0)
    {
      output << "options_.varobs = [];" << endl;
      for (vector<int>::const_iterator it = varobs.begin();
           it != varobs.end(); it++)
276
277
278
279
        if (it == varobs.begin())
          output << "options_.varobs = '" << getName(*it) << "';" << endl;
        else
          output << "options_.varobs = char(options_.varobs, '" << getName(*it) << "');" << endl;
280
281
282
283
284
285

      output << "options_.varobs_id = [ ";
      for (vector<int>::const_iterator it = varobs.begin();
           it != varobs.end(); it++)
        output << getTypeSpecificID(*it)+1 << " ";
      output << " ];"  << endl;
Sébastien Villemot's avatar
Sébastien Villemot committed
286
    }
sebastien's avatar
sebastien committed
287
288
}

289
290
291
292
293
294
295
void
SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException)
{
  if (!frozen)
    throw NotYetFrozenException();

  output << endl
296
         << "exo_nbr = " << exo_nbr() << ";" << endl;
297
298
299
300
301
  if (exo_nbr() > 0)
    for (int id = 0; id < exo_nbr(); id++)
      output << "exo_names[\"" << getName(exo_ids[id]) << "\"] = " << id << ";" << endl;

  output << endl
302
         << "exo_det_nbr = " << exo_det_nbr() << ";" << endl;
303
304
305
306
307
  if (exo_det_nbr() > 0)
    for (int id = 0; id < exo_det_nbr(); id++)
      output << "exo_det_names[\"" << getName(exo_det_ids[id]) << "\"] = " << id << " ;" << endl;

  output << endl
308
         << "endo_nbr = " << endo_nbr() << ";" << endl;
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
  if (endo_nbr() > 0)
    for (int id = 0; id < endo_nbr(); id++)
      output << "endo_names[\"" << getName(endo_ids[id]) << "\"] = " << id << ";" << endl;

  output << endl
         << "int param_nbr = " << param_nbr() << ";" << endl;
  if (param_nbr() > 0)
    for (int id = 0; id < param_nbr(); id++)
      output << "param_names[\"" << getName(param_ids[id]) << "\"] = " << id << ";" << endl;

  // Write the auxiliary variable table
  if (aux_vars.size() > 0)
    for (int i = 0; i < (int) aux_vars.size(); i++)
      {
        output << "aux_vars_t av" << i << ";" << endl;
        output << "av" << i << ".endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl
               << "av" << i << ".type = " << aux_vars[i].get_type() << ";" << endl;
        switch (aux_vars[i].get_type())
          {
          case avEndoLead:
          case avExoLead:
          case avExpectation:
          case avMultiplier:
            break;
          case avEndoLag:
          case avExoLag:
            output << "av" << i << ".orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
                   << "av" << i << ".orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
            break;
          }
        output << "aux_vars.push_back(" << "av" << i << ");" << endl;
      }

  if (predeterminedNbr() > 0)
    for (set<int>::const_iterator it = predetermined_variables.begin();
         it != predetermined_variables.end(); it++)
      output << "predetermined_variables.push_back(" << getTypeSpecificID(*it) << ");" << endl;

  if (observedVariablesNbr() > 0)
    for (vector<int>::const_iterator it = varobs.begin();
         it != varobs.end(); it++)
      output << "varobs.push_back(" << getTypeSpecificID(*it) << ");" << endl;
}

sebastien's avatar
sebastien committed
353
int
sebastien's avatar
sebastien committed
354
SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenException)
sebastien's avatar
sebastien committed
355
356
{
  ostringstream varname;
sebastien's avatar
sebastien committed
357
358
359
360
361
  if (endo)
    varname << "AUX_ENDO_LEAD_";
  else
    varname << "AUX_EXO_LEAD_";
  varname << index;
sebastien's avatar
sebastien committed
362
363
364
365
366
  int symb_id;
  try
    {
      symb_id = addSymbol(varname.str(), eEndogenous);
    }
367
  catch (AlreadyDeclaredException &e)
sebastien's avatar
sebastien committed
368
369
370
371
372
    {
      cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
      exit(EXIT_FAILURE);
    }

373
  aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLead : avExoLead), 0, 0, 0));
sebastien's avatar
sebastien committed
374
375
376
377
378

  return symb_id;
}

int
sebastien's avatar
sebastien committed
379
SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException)
sebastien's avatar
sebastien committed
380
381
{
  ostringstream varname;
sebastien's avatar
sebastien committed
382
383
384
385
  if (endo)
    varname << "AUX_ENDO_LAG_";
  else
    varname << "AUX_EXO_LAG_";
386
  varname << orig_symb_id << "_" << -orig_lead_lag;
387

sebastien's avatar
sebastien committed
388
389
390
391
392
  int symb_id;
  try
    {
      symb_id = addSymbol(varname.str(), eEndogenous);
    }
393
  catch (AlreadyDeclaredException &e)
sebastien's avatar
sebastien committed
394
395
396
397
398
    {
      cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
      exit(EXIT_FAILURE);
    }

399
  aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLag : avExoLag), orig_symb_id, orig_lead_lag, 0));
sebastien's avatar
sebastien committed
400
401

  return symb_id;
402
}
403

sebastien's avatar
sebastien committed
404
405
406
407
408
409
int
SymbolTable::addEndoLeadAuxiliaryVar(int index) throw (FrozenException)
{
  return addLeadAuxiliaryVarInternal(true, index);
}

410
int
sebastien's avatar
sebastien committed
411
SymbolTable::addEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag) throw (FrozenException)
412
{
sebastien's avatar
sebastien committed
413
  return addLagAuxiliaryVarInternal(true, orig_symb_id, orig_lead_lag);
414
415
416
}

int
sebastien's avatar
sebastien committed
417
SymbolTable::addExoLeadAuxiliaryVar(int index) throw (FrozenException)
418
{
sebastien's avatar
sebastien committed
419
  return addLeadAuxiliaryVarInternal(false, index);
420
421
422
}

int
sebastien's avatar
sebastien committed
423
SymbolTable::addExoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag) throw (FrozenException)
424
{
sebastien's avatar
sebastien committed
425
  return addLagAuxiliaryVarInternal(false, orig_symb_id, orig_lead_lag);
426
}
427
428

int
429
SymbolTable::addExpectationAuxiliaryVar(int information_set, int index) throw (FrozenException)
430
431
432
{
  ostringstream varname;
  int symb_id;
433

434
435
  varname << "AUX_EXPECT_" << (information_set < 0 ? "LAG" : "LEAD") << "_"
          << abs(information_set) << "_" << index;
436

437
438
439
440
  try
    {
      symb_id = addSymbol(varname.str(), eEndogenous);
    }
441
  catch (AlreadyDeclaredException &e)
442
443
444
445
446
    {
      cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
      exit(EXIT_FAILURE);
    }

447
  aux_vars.push_back(AuxVarInfo(symb_id, avExpectation, 0, 0, 0));
448
449
450
451
452
453
454
455
456

  return symb_id;
}

int
SymbolTable::addMultiplierAuxiliaryVar(int index) throw (FrozenException)
{
  ostringstream varname;
  int symb_id;
457
  varname << "MULT_" << index+1;
458
459
460
461
462
463
464
465
466
467

  try
    {
      symb_id = addSymbol(varname.str(), eEndogenous);
    }
  catch (AlreadyDeclaredException &e)
    {
      cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
      exit(EXIT_FAILURE);
    }
468

469
  aux_vars.push_back(AuxVarInfo(symb_id, avMultiplier, 0, 0, index));
470
471
  return symb_id;
}
sebastien's avatar
sebastien committed
472

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
int
SymbolTable::addDiffForwardAuxiliaryVar(int orig_symb_id) throw (FrozenException)
{
  ostringstream varname;
  int symb_id;
  varname << "AUX_DIFF_FWRD_" << orig_symb_id+1;

  try
    {
      symb_id = addSymbol(varname.str(), eEndogenous);
    }
  catch (AlreadyDeclaredException &e)
    {
      cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
      exit(EXIT_FAILURE);
    }

  aux_vars.push_back(AuxVarInfo(symb_id, avDiffForward, orig_symb_id, 0, 0));
  return symb_id;
}

494
int
Sébastien Villemot's avatar
Sébastien Villemot committed
495
SymbolTable::searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const throw (SearchFailedException)
496
{
Sébastien Villemot's avatar
Sébastien Villemot committed
497
  for (size_t i = 0; i < aux_vars.size(); i++)
498
499
    if ((aux_vars[i].get_type() == avEndoLag || aux_vars[i].get_type() == avExoLag)
        && aux_vars[i].get_orig_symb_id() == orig_symb_id && aux_vars[i].get_orig_lead_lag() == orig_lead_lag)
500
      return aux_vars[i].get_symb_id();
Sébastien Villemot's avatar
Sébastien Villemot committed
501
  throw SearchFailedException(orig_symb_id, orig_lead_lag);
502
503
}

sebastien's avatar
sebastien committed
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
void
SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, FrozenException)
{
  if (symb_id < 0 || symb_id >= size)
    throw UnknownSymbolIDException(symb_id);
  if (frozen)
    throw FrozenException();

  assert(getType(symb_id) == eEndogenous);

  predetermined_variables.insert(symb_id);
}

bool
SymbolTable::isPredetermined(int symb_id) const throw (UnknownSymbolIDException)
{
  if (symb_id < 0 || symb_id >= size)
    throw UnknownSymbolIDException(symb_id);

523
  return (predetermined_variables.find(symb_id) != predetermined_variables.end());
sebastien's avatar
sebastien committed
524
525
526
527
528
}

int
SymbolTable::predeterminedNbr() const
{
529
  return (predetermined_variables.size());
sebastien's avatar
sebastien committed
530
}
Sébastien Villemot's avatar
Sébastien Villemot committed
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560

void
SymbolTable::addObservedVariable(int symb_id) throw (UnknownSymbolIDException)
{
  if (symb_id < 0 || symb_id >= size)
    throw UnknownSymbolIDException(symb_id);

  assert(getType(symb_id) == eEndogenous);
  varobs.push_back(symb_id);
}

int
SymbolTable::observedVariablesNbr() const
{
  return (int) varobs.size();
}

bool
SymbolTable::isObservedVariable(int symb_id) const
{
  return (find(varobs.begin(), varobs.end(), symb_id) != varobs.end());
}

int
SymbolTable::getObservedVariableIndex(int symb_id) const
{
  vector<int>::const_iterator it = find(varobs.begin(), varobs.end(), symb_id);
  assert(it != varobs.end());
  return (int) (it - varobs.begin());
}
561
562
563
564
565
566
567

vector <int>
SymbolTable::getTrendVarIds() const
{
  vector <int> trendVars;
  for (symbol_table_type::const_iterator it = symbol_table.begin();
       it != symbol_table.end(); it++)
568
    if (getType(it->second) == eTrend || getType(it->second) == eLogTrend)
569
570
571
      trendVars.push_back(it->second);
  return trendVars;
}
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

set<int>
SymbolTable::getExogenous() const
{
  set <int> exogs;
  for (symbol_table_type::const_iterator it = symbol_table.begin();
       it != symbol_table.end(); it++)
    if (getType(it->second) == eExogenous)
      exogs.insert(it->second);
  return exogs;
}

set<int>
SymbolTable::getEndogenous() const
{
  set <int> endogs;
  for (symbol_table_type::const_iterator it = symbol_table.begin();
       it != symbol_table.end(); it++)
    if (getType(it->second) == eEndogenous)
      endogs.insert(it->second);
  return endogs;
}