Minsky
evalGodley.cc
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2013
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "cairoItems.h"
21 #include "evalGodley.h"
22 #include "group.h"
23 #include "selection.h"
24 #include "lasso.h"
25 #include "evalGodley.rcd"
26 #include "minsky_epilogue.h"
27 
28 using namespace std;
29 
30 namespace minsky
31 {
32  namespace
33  {
34  void throwInvalidAssetLiabilityPair(const string& name)
35  {
36  throw error("shared column %s is not an asset/liability pair",
37  name.c_str());
38  }
39  }
40 
41  void SharedColumnCheck::checkShared(const string& name, AssetClass ac)
42  {
43  if (name.empty() || name==":_")
44  return; // ignore blank columns
45  if (!colAssetType.insert(make_pair(name, ac)).second)
46  {
47  switch (ac)
48  {
49  case liability:
50  if (colAssetType[name]!=asset)
52  break;
53  case asset:
54  if (colAssetType[name]!=liability)
56  break;
57  case equity:
58  break; // do not check duplicate column
59  default:
60  throw error("duplicated column %s detected",name.c_str());
61  }
62  // At this point, a shared pair of columns is OK
63  if (!sharedCol.insert(name).second)
64  throw error("More than two columns %s detected" ,name.c_str());
65  }
66  }
67 
68  bool SharedColumnCheck::updateColDefs(const string& col, const FlowCoef& fc)
69  {
70  const bool alreadySeen=sharedCol.contains(col);
71  if (alreadySeen)
72  colDef[col][fc.name]-=fc.coef;
73  else
74  colDef[col][fc.name]+=fc.coef;
75  return alreadySeen;
76  }
77 
78  void SharedColumnCheck::checkSharedColDefs() const
79  {
80  // check that shared column definitions sum to zero
81  for (set<string>::iterator i=sharedCol.begin(); i!=sharedCol.end(); ++i)
82  {
83  const map<string, double>& cdef=colDef[*i];
84  for (map<string, double>::const_iterator j=cdef.begin();
85  j!=cdef.end(); ++j)
86  if (abs(j->second)>1e-30)
87  throw error("column %s has mismatched flow %s",
88  i->c_str(), j->first.c_str());
89  }
90  }
91 
92  void EvalGodley::eval(double* sv, const double* fv) const
93  {
94  for (size_t i=0; i<initIdx.size(); ++i)
95  sv[initIdx[i]]=0;
96 
97  for (size_t i=0; i<sidx.size(); ++i)
98  sv[sidx[i]] += fv[fidx[i]] * m[i];
99  }
100 }
void throwInvalidAssetLiabilityPair(const string &name)
Definition: evalGodley.cc:34
std::string name
Definition: flowCoef.h:30
STL namespace.
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
CLASSDESC_ACCESS_EXPLICIT_INSTANTIATION(minsky::EvalGodley)