SubModel.cc 19.2 KB
Newer Older
1
/*
2
 * Copyright (C) 2018-2019 Dynare Team
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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 "SubModel.hh"

TrendComponentModelTable::TrendComponentModelTable(SymbolTable &symbol_table_arg) :
25
  symbol_table{symbol_table_arg}
26
27
28
29
30
31
{
}

void
TrendComponentModelTable::addTrendComponentModel(string name_arg,
                                                 vector<string> eqtags_arg,
32
                                                 vector<string> target_eqtags_arg)
33
34
35
36
37
38
39
{
  if (isExistingTrendComponentModelName(name_arg))
    {
      cerr << "Error: a trend component model already exists with the name " << name_arg << endl;
      exit(EXIT_FAILURE);
    }
  eqtags[name_arg] = move(eqtags_arg);
40
  target_eqtags[name_arg] = move(target_eqtags_arg);
41
42
43
44
  names.insert(move(name_arg));
}

void
45
TrendComponentModelTable::setVals(map<string, vector<int>> eqnums_arg, map<string, vector<int>> target_eqnums_arg,
46
                                  map<string, vector<int>> lhs_arg, map<string, vector<expr_t>> lhs_expr_t_arg)
47
48
{
  eqnums = move(eqnums_arg);
49
  target_eqnums = move(target_eqnums_arg);
Houtan Bastani's avatar
Houtan Bastani committed
50
51
  lhs = move(lhs_arg);
  lhs_expr_t = move(lhs_expr_t_arg);
52
53
54
55
56

  for (const auto &it : eqnums)
    {
      vector<int> nontrend_vec;
      for (auto eq : it.second)
57
        if (find(target_eqnums[it.first].begin(), target_eqnums[it.first].end(), eq) == target_eqnums[it.first].end())
58
          nontrend_vec.push_back(eq);
59
      nontarget_eqnums[it.first] = nontrend_vec;
60
61
    }

Houtan Bastani's avatar
Houtan Bastani committed
62
63
  for (const auto &name : names)
    {
64
      vector<int> nontarget_lhs_vec, target_lhs_vec;
Houtan Bastani's avatar
Houtan Bastani committed
65
66
      vector<int> lhsv = getLhs(name);
      vector<int> eqnumsv = getEqNums(name);
67
68
69
      for (int nontrend_it : getNonTargetEqNums(name))
        nontarget_lhs_vec.push_back(lhsv.at(distance(eqnumsv.begin(), find(eqnumsv.begin(), eqnumsv.end(), nontrend_it))));
      nontarget_lhs[name] = nontarget_lhs_vec;
70

71
72
73
      for (int trend_it : getTargetEqNums(name))
        target_lhs_vec.push_back(lhsv.at(distance(eqnumsv.begin(), find(eqnumsv.begin(), eqnumsv.end(), trend_it))));
      target_lhs[name] = target_lhs_vec;
Houtan Bastani's avatar
Houtan Bastani committed
74
    }
75
76
77
78
79
80
81
82
83
}

void
TrendComponentModelTable::setRhs(map<string, vector<set<pair<int, int>>>> rhs_arg)
{
  rhs = move(rhs_arg);
}

void
84
TrendComponentModelTable::setTargetVar(map<string, vector<int>> target_vars_arg)
85
{
86
  target_vars = move(target_vars_arg);
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
}

void
TrendComponentModelTable::setMaxLags(map<string, vector<int>> max_lags_arg)
{
  max_lags = move(max_lags_arg);
}

void
TrendComponentModelTable::setDiff(map<string, vector<bool>> diff_arg)
{
  diff = move(diff_arg);
}

void
TrendComponentModelTable::setOrigDiffVar(map<string, vector<int>> orig_diff_var_arg)
{
  orig_diff_var = move(orig_diff_var_arg);
}

107
108
109
110
111
112
void
TrendComponentModelTable::setAR(map<string, map<tuple<int, int, int>, expr_t>> AR_arg)
{
  AR = move(AR_arg);
}

113
114
115
116
117
118
void
TrendComponentModelTable::setEC(map<string, map<tuple<int, int, int>, expr_t>> EC_arg)
{
  EC = move(EC_arg);
}

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
map<string, vector<string>>
TrendComponentModelTable::getEqTags() const
{
  return eqtags;
}

vector<string>
TrendComponentModelTable::getEqTags(const string &name_arg) const
{
  checkModelName(name_arg);
  return eqtags.find(name_arg)->second;
}

void
TrendComponentModelTable::checkModelName(const string &name_arg) const
{
  if (!isExistingTrendComponentModelName(name_arg))
    {
      cerr << name_arg
           << " is not a recognized equation tag of a trend component model equation" << endl;
      exit(EXIT_FAILURE);
    }
}

Houtan Bastani's avatar
Houtan Bastani committed
143
vector<int>
144
TrendComponentModelTable::getNonTargetLhs(const string &name_arg) const
Houtan Bastani's avatar
Houtan Bastani committed
145
146
{
  checkModelName(name_arg);
147
  return nontarget_lhs.find(name_arg)->second;
Houtan Bastani's avatar
Houtan Bastani committed
148
149
150
}

vector<int>
151
TrendComponentModelTable::getTargetLhs(const string &name_arg) const
Houtan Bastani's avatar
Houtan Bastani committed
152
153
{
  checkModelName(name_arg);
154
  return target_lhs.find(name_arg)->second;
Houtan Bastani's avatar
Houtan Bastani committed
155
156
}

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
vector<int>
TrendComponentModelTable::getLhs(const string &name_arg) const
{
  checkModelName(name_arg);
  return lhs.find(name_arg)->second;
}

vector<expr_t>
TrendComponentModelTable::getLhsExprT(const string &name_arg) const
{
  checkModelName(name_arg);
  return lhs_expr_t.find(name_arg)->second;
}

map<string, vector<string>>
172
TrendComponentModelTable::getTargetEqTags() const
173
{
174
  return target_eqtags;
175
176
177
178
179
180
181
182
}

map<string, vector<int>>
TrendComponentModelTable::getEqNums() const
{
  return eqnums;
}

183
map<string, vector<int>>
184
TrendComponentModelTable::getTargetEqNums() const
185
{
186
  return target_eqnums;
187
188
}

189
vector<int>
190
TrendComponentModelTable::getTargetEqNums(const string &name_arg) const
191
192
{
  checkModelName(name_arg);
193
  return target_eqnums.find(name_arg)->second;
194
195
196
}

map<string, vector<int>>
197
TrendComponentModelTable::getNonTargetEqNums() const
198
{
199
  return nontarget_eqnums;
200
201
}

202
vector<int>
203
TrendComponentModelTable::getNonTargetEqNums(const string &name_arg) const
204
205
{
  checkModelName(name_arg);
206
  return nontarget_eqnums.find(name_arg)->second;
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
}

vector<int>
TrendComponentModelTable::getEqNums(const string &name_arg) const
{
  checkModelName(name_arg);
  return eqnums.find(name_arg)->second;
}

vector<int>
TrendComponentModelTable::getMaxLags(const string &name_arg) const
{
  checkModelName(name_arg);
  return max_lags.find(name_arg)->second;
}

int
TrendComponentModelTable::getMaxLag(const string &name_arg) const
{
  int max_lag_int = 0;
  for (auto it : getMaxLags(name_arg))
    max_lag_int = max(max_lag_int, it);
  return max_lag_int;
}

vector<bool>
TrendComponentModelTable::getDiff(const string &name_arg) const
{
  checkModelName(name_arg);
  return diff.find(name_arg)->second;
}

vector<int>
TrendComponentModelTable::getOrigDiffVar(const string &name_arg) const
{
  checkModelName(name_arg);
  return orig_diff_var.find(name_arg)->second;
}

void
247
TrendComponentModelTable::writeOutput(const string &basename, ostream &output) const
248
{
249
250
251
  if (names.empty())
    return;

252
253
254
255
  string filename = "+" + basename + "/trend_component_ar_ec.m";
  ofstream ar_ec_output;
  ar_ec_output.open(filename, ios::out | ios::binary);
  if (!ar_ec_output.is_open())
256
257
258
259
    {
      cerr << "Error: Can't open file " << filename << " for writing" << endl;
      exit(EXIT_FAILURE);
    }
260
261
  ar_ec_output << "function [ar, ec] = trend_component_ar_ec(model_name, params)" << endl
            << "%function [ar, ec] = trend_component_ar_ec(model_name, params)" << endl
262
263
            << "% File automatically generated by the Dynare preprocessor" << endl << endl;

264
265
  for (const auto &name : names)
    {
Houtan Bastani's avatar
Houtan Bastani committed
266
      output << "M_.trend_component." << name << ".model_name = '" << name << "';" << endl
267
268
269
270
271
272
273
274
             << "M_.trend_component." << name << ".eqtags = {";
      for (const auto &it : eqtags.at(name))
        output << "'" << it << "'; ";
      output << "};" << endl
             << "M_.trend_component." << name << ".eqn = [";
      for (auto it : eqnums.at(name))
        output << it + 1 << " ";
      output << "];" << endl
275
276
             << "M_.trend_component." << name << ".target_eqn = [";
      for (auto it : target_eqnums.at(name))
277
278
        output << it + 1 << " ";
      output << "];" << endl
279
             << "M_.trend_component." << name << ".targets = [";
280
      for (auto it : eqnums.at(name))
281
282
        if (find(target_eqnums.at(name).begin(), target_eqnums.at(name).end(), it)
            == target_eqnums.at(name).end())
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
          output << "false ";
        else
          output << "true ";
      output << "];" << endl
             << "M_.trend_component." << name << ".lhs = [";
      for (auto it : lhs.at(name))
        output << symbol_table.getTypeSpecificID(it) + 1 << " ";
      output << "];" << endl
             << "M_.trend_component." << name << ".max_lag = [";
      for (auto it : max_lags.at(name))
        output << it << " ";
      output << "];" << endl
             << "M_.trend_component." << name << ".diff = [";
      for (const auto &it : diff.at(name))
        output << (it ? "true" : "false") << " ";
      output << "];" << endl
             << "M_.trend_component." << name << ".orig_diff_var = [";
      for (auto it : orig_diff_var.at(name))
        output << (it >= 0 ? symbol_table.getTypeSpecificID(it) + 1 : -1) << " ";
302
303
      output << "];" << endl
             << "M_.trend_component." << name << ".nonstationary = [";
304
305
      for (size_t i = 0; i < diff.at(name).size(); i++)
        output << "true ";
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
      output << "];" << endl;
      int i = 1;
      for (const auto &it : rhs.at(name))
        {
          output << "M_.trend_component." << name << ".rhs.vars_at_eq{" << i << "}.var = [";
          for (const auto &it1 : it)
            output << symbol_table.getTypeSpecificID(it1.first) + 1 << " ";
          output << "];" << endl
                 << "M_.trend_component." << name << ".rhs.vars_at_eq{" << i << "}.lag = [";
          for (const auto &it1 : it)
            output << it1.second << " ";
          output << "];" << endl;

          i++;
        }
321
322
      output << "M_.trend_component." << name << ".target_vars = [";
      for (auto it : target_vars.at(name))
323
324
        output << (it >= 0 ? symbol_table.getTypeSpecificID(it) + 1 : -1) << " ";
      output << "];" << endl;
325

326
      vector<int> target_lhs_vec = getTargetLhs(name);
327
      vector<int> nontarget_lhs_vec = getNonTargetLhs(name);
328
329
330

      ar_ec_output << "if strcmp(model_name, '" << name << "')" << endl
                << "    % AR" << endl
331
                << "    ar = zeros(" << nontarget_lhs_vec.size() << ", " << nontarget_lhs_vec.size() << ", " << getMaxLag(name) << ");" << endl;
332
333
334
335
      for (const auto & it : AR.at(name))
        {
          int eqn, lag, lhs_symb_id;
          tie (eqn, lag, lhs_symb_id) = it.first;
336
          int colidx = (int) distance(nontarget_lhs_vec.begin(), find(nontarget_lhs_vec.begin(), nontarget_lhs_vec.end(), lhs_symb_id));
337
338
339
340
          ar_ec_output << "    ar(" << eqn + 1 << ", " << colidx + 1 << ", " << lag << ") = ";
          it.second->writeOutput(ar_ec_output, ExprNodeOutputType::matlabDynamicModel);
          ar_ec_output << ";" << endl;
        }
341
342
343
344
345

      int ec_lag = 0;
      for (const auto & it : EC.at(name))
        if (get<1>(it.first) > ec_lag)
          ec_lag = get<1>(it.first);
346
347
      ar_ec_output << endl
                   << "    % EC" << endl
348
                   << "    ec = zeros(" << nontarget_lhs_vec.size() << ", " << target_lhs_vec.size() << ", " << ec_lag << ");" << endl;
349
350
      for (const auto & it : EC.at(name))
        {
351
352
          int eqn, lag, colidx;
          tie (eqn, lag, colidx) = it.first;
353
          ar_ec_output << "    ec(" << eqn + 1 << ", " << colidx + 1 << ", " << lag << ") = ";
354
355
          it.second->writeOutput(ar_ec_output, ExprNodeOutputType::matlabDynamicModel);
          ar_ec_output << ";" << endl;
356
        }
357
      ar_ec_output << "    return" << endl
358
                << "end" << endl << endl;
359
    }
360
  ar_ec_output << "error([model_name ' is not a valid trend_component_model name'])" << endl
361
            << "end" << endl;
362
  ar_ec_output.close();
363
364
365
366
367
368
369
370
371
372
}

void
TrendComponentModelTable::writeJsonOutput(ostream &output) const
{
  for (const auto &name : names)
    {
      if (name != *(names.begin()))
        output << ", ";
      output << "{\"statementName\": \"trend_component_model\","
373
374
375
376
377
378
379
380
             << "\"model_name\": \"" << name << "\","
             << "\"eqtags\": [";
      for (const auto &it : eqtags.at(name))
        {
          output << "\"" << it << "\"";
          if (&it != &eqtags.at(name).back())
            output << ", ";
        }
381
382
      output << "], \"target_eqtags\": [";
      for (const auto &it : target_eqtags.at(name))
383
384
        {
          output << "\"" << it << "\"";
385
          if (&it != &target_eqtags.at(name).back())
386
387
388
            output << ", ";
        }
      output << "]}";
389
390
    }
}
Houtan Bastani's avatar
Houtan Bastani committed
391
392

VarModelTable::VarModelTable(SymbolTable &symbol_table_arg) :
393
  symbol_table{symbol_table_arg}
Houtan Bastani's avatar
Houtan Bastani committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
{
}

void
VarModelTable::addVarModel(string name_arg, vector<string> eqtags_arg,
                           pair<SymbolList, int> symbol_list_and_order_arg)
{
  if (isExistingVarModelName(name_arg))
    {
      cerr << "Error: a VAR model already exists with the name " << name_arg << endl;
      exit(EXIT_FAILURE);
    }

  eqtags[name_arg] = move(eqtags_arg);
  symbol_list_and_order[name_arg] = move(symbol_list_and_order_arg);
  names.insert(move(name_arg));
}

map<string, pair<SymbolList, int>>
VarModelTable::getSymbolListAndOrder() const
{
  return symbol_list_and_order;
}

void
Houtan Bastani's avatar
Houtan Bastani committed
419
VarModelTable::writeOutput(const string &basename, ostream &output) const
Houtan Bastani's avatar
Houtan Bastani committed
420
{
421
422
423
  if (names.empty())
    return;

Houtan Bastani's avatar
Houtan Bastani committed
424
425
426
427
428
429
430
431
432
433
434
435
  string filename = "+" + basename + "/var_ar.m";
  ofstream ar_output;
  ar_output.open(filename, ios::out | ios::binary);
  if (!ar_output.is_open())
    {
      cerr << "Error: Can't open file " << filename << " for writing" << endl;
      exit(EXIT_FAILURE);
    }
  ar_output << "function ar = var_ar(model_name, params)" << endl
            << "%function ar = var_ar(model_name, params)" << endl
            << "% File automatically generated by the Dynare preprocessor" << endl << endl;

Houtan Bastani's avatar
Houtan Bastani committed
436
437
438
  for (const auto &name : names)
    {
      output << "M_.var." << name << ".model_name = '" << name << "';" << endl;
439
      if (!symbol_list_and_order.at(name).first.empty())
Houtan Bastani's avatar
Houtan Bastani committed
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
        {
          symbol_list_and_order.at(name).first.writeOutput("M_.var." + name + ".var_list_", output);
          output  << "M_.var." << name << ".order = "
                  << symbol_list_and_order.at(name).second << ";" << endl;
        }
      output << "M_.var." << name << ".eqtags = {";
      for (const auto &it : eqtags.at(name))
        output << "'" << it << "'; ";
      output << "};" << endl
             << "M_.var." << name << ".eqn = [";
      for (auto it : eqnums.at(name))
        output << it + 1 << " ";
      output << "];" << endl
             << "M_.var." << name << ".lhs = [";
      for (auto it : lhs.at(name))
        output << symbol_table.getTypeSpecificID(it) + 1 << " ";
      output << "];" << endl
             << "M_.var." << name << ".max_lag = [";
      for (auto it : max_lags.at(name))
        output << it << " ";
      output << "];" << endl
             << "M_.var." << name << ".diff = [";
      for (const auto &it : diff.at(name))
        output << (it ? "true" : "false") << " ";
      output << "];" << endl
465
             << "M_.var." << name << ".nonstationary = M_.var." << name << ".diff;" << endl
Houtan Bastani's avatar
Houtan Bastani committed
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
             << "M_.var." << name << ".orig_diff_var = [";
      for (auto it : orig_diff_var.at(name))
        output << (it >= 0 ? symbol_table.getTypeSpecificID(it) + 1 : -1) << " ";
      output << "];" << endl;
      int i = 1;
      for (const auto &it : rhs.at(name))
        {
          output << "M_.var." << name << ".rhs.vars_at_eq{" << i << "}.var = [";
          for (const auto &it1 : it)
            output << symbol_table.getTypeSpecificID(it1.first) + 1 << " ";
          output << "];" << endl
                 << "M_.var." << name << ".rhs.vars_at_eq{" << i << "}.lag = [";
          for (const auto &it1 : it)
            output << it1.second << " ";
          output << "];" << endl;

          i++;
        }
Houtan Bastani's avatar
Houtan Bastani committed
484
485
486
487
488
489
490
491
492

      vector<int> lhs = getLhs(name);
      ar_output << "if strcmp(model_name, '" << name << "')" << endl
                << "    ar = zeros(" << lhs.size() << ", " << lhs.size() << ", " << getMaxLag(name) << ");" << endl;
      for (const auto & it : AR.at(name))
        {
          int eqn, lag, lhs_symb_id;
          tie (eqn, lag, lhs_symb_id) = it.first;
          int colidx = (int) distance(lhs.begin(), find(lhs.begin(), lhs.end(), lhs_symb_id));
Houtan Bastani's avatar
Houtan Bastani committed
493
          ar_output << "    ar(" << eqn + 1 << ", " << colidx + 1 << ", " << lag << ") = ";
494
          it.second->writeOutput(ar_output, ExprNodeOutputType::matlabDynamicModel);
Houtan Bastani's avatar
Houtan Bastani committed
495
          ar_output << ";" << endl;
Houtan Bastani's avatar
Houtan Bastani committed
496
497
498
        }
      ar_output << "    return" << endl
                << "end" << endl << endl;
Houtan Bastani's avatar
Houtan Bastani committed
499
    }
Houtan Bastani's avatar
Houtan Bastani committed
500
501
502
  ar_output << "error([model_name ' is not a valid var_model name'])" << endl
            << "end" << endl;
  ar_output.close();
Houtan Bastani's avatar
Houtan Bastani committed
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
}

void
VarModelTable::writeJsonOutput(ostream &output) const
{
  for (const auto &name : names)
    {
      if (name != *(names.begin()))
        output << ", ";
      output << "{\"statementName\": \"var_model\","
             << "\"model_name\": \"" << name << "\",";
      if (symbol_list_and_order.empty())
        {
          output << "\"eqtags\": [";
          for (const auto &it : eqtags.at(name))
            {
              output << "\"" << it << "\"";
              if (&it != &eqtags.at(name).back())
                output << ", ";
            }
          output << "]";
        }
      else
526
        output << "\"order\": \"" << symbol_list_and_order.at(name).second << "\"";
Houtan Bastani's avatar
Houtan Bastani committed
527
528
529
530
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
      output << "}";
    }
}

map<string, vector<string>>
VarModelTable::getEqTags() const
{
  return eqtags;
}

vector<string>
VarModelTable::getEqTags(const string &name_arg) const
{
  checkModelName(name_arg);
  return eqtags.find(name_arg)->second;
}

void
VarModelTable::checkModelName(const string &name_arg) const
{
  if (!isExistingVarModelName(name_arg))
    {
      cerr << name_arg
           << " is not a recognized equation tag of a VAR model equation" << endl;
      exit(EXIT_FAILURE);
    }
}

void
VarModelTable::setEqNums(map<string, vector<int>> eqnums_arg)
{
  eqnums = move(eqnums_arg);
}

void
VarModelTable::setLhs(map<string, vector<int>> lhs_arg)
{
  lhs = move(lhs_arg);
}

void
VarModelTable::setRhs(map<string, vector<set<pair<int, int>>>> rhs_arg)
{
  rhs = move(rhs_arg);
}

void
VarModelTable::setLhsExprT(map<string, vector<expr_t>> lhs_expr_t_arg)
{
  lhs_expr_t = move(lhs_expr_t_arg);
}

map<string, vector<int>>
VarModelTable::getEqNums() const
{
  return eqnums;
}

585
586
587
588
589
590
591
vector<bool>
VarModelTable::getDiff(const string &name_arg) const
{
  checkModelName(name_arg);
  return diff.find(name_arg)->second;
}

Houtan Bastani's avatar
Houtan Bastani committed
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
vector<int>
VarModelTable::getEqNums(const string &name_arg) const
{
  checkModelName(name_arg);
  return eqnums.find(name_arg)->second;
}

void
VarModelTable::setMaxLags(map<string, vector<int>> max_lags_arg)
{
  max_lags = move(max_lags_arg);
}

void
VarModelTable::setDiff(map<string, vector<bool>> diff_arg)
{
  diff = move(diff_arg);
}

void
VarModelTable::setOrigDiffVar(map<string, vector<int>> orig_diff_var_arg)
{
  orig_diff_var = move(orig_diff_var_arg);
}

Houtan Bastani's avatar
Houtan Bastani committed
617
void
618
VarModelTable::setAR(map<string, map<tuple<int, int, int>, expr_t>> AR_arg)
Houtan Bastani's avatar
Houtan Bastani committed
619
620
621
622
{
  AR = move(AR_arg);
}

Houtan Bastani's avatar
Houtan Bastani committed
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
vector<int>
VarModelTable::getMaxLags(const string &name_arg) const
{
  checkModelName(name_arg);
  return max_lags.find(name_arg)->second;
}

int
VarModelTable::getMaxLag(const string &name_arg) const
{
  int max_lag_int = 0;
  for (auto it : getMaxLags(name_arg))
    max_lag_int = max(max_lag_int, it);
  return max_lag_int;
}

vector<int>
VarModelTable::getLhs(const string &name_arg) const
{
  checkModelName(name_arg);
  return lhs.find(name_arg)->second;
}

vector<set<pair<int, int>>>
VarModelTable::getRhs(const string &name_arg) const
{
  checkModelName(name_arg);
  return rhs.find(name_arg)->second;
}


vector<expr_t>
VarModelTable::getLhsExprT(const string &name_arg) const
{
  checkModelName(name_arg);
  return lhs_expr_t.find(name_arg)->second;
}