Minsky: 3.17.0
schema0.cc
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2012
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 #include "schema0.h"
20 #include "plot.xcd"
21 #include "minsky_epilogue.h"
22 #include <fstream>
23 using namespace ecolab;
24 using namespace classdesc;
25 using namespace std;
26 
27 namespace schema0
28 {
29  namespace
30  {
31  struct IsOrphan
32  {
33  set<string> ids;
34  void insert(const string& name) {ids.insert(name);}
35  bool operator()(const VariableManager::value_type& v) const {
36  return ids.contains(v.second.name);
37  }
38  bool operator()(const VariableManager::VariableValues::value_type& l) const {
39  return ids.contains(l.first);
40  }
41  };
42  }
43 
44  void Minsky::removeIntVarOrphans()
45  {
46  set<string> intNames;
47  for (Operations::const_iterator o=operations.begin();
48  o!=operations.end(); ++o)
49  if (o->second.m_type==minsky::OperationType::integrate)
50  {
51  if (!o->second.m_description.empty())
52  intNames.insert(o->second.m_description);
53  else
54  if (!o->second.description.empty())
55  intNames.insert(o->second.description);
56  }
57 
58  IsOrphan isOrphan;
59  for (VariableManager::const_iterator v=variables.begin();
60  v!=variables.end(); ++v)
61  // an orphaned variable is an integral variable not attached to an integral and without
62  if (v->second.m_type==minsky::VariableType::integral &&
63  intNames.contains(v->second.name)==0)
64  isOrphan.insert(v->second.name);
65 
66  for (VariableManager::iterator i=variables.begin();
67  i!=variables.end();)
68  {
69  const VariableManager::iterator j=i++;
70  if (isOrphan(*j)) variables.erase(j);
71  }
72 
73  for (VariableManager::VariableValues::iterator i=variables.values.begin();
74  i!=variables.values.end();)
75  {
76  const VariableManager::VariableValues::iterator j=i++;
77  if (isOrphan(*j)) variables.values.erase(j);
78  }
79 
80  }
81 
82 
83 }
STL namespace.
bool operator()(const VariableManager::VariableValues::value_type &l) const
Definition: schema0.cc:38
bool operator()(const VariableManager::value_type &v) const
Definition: schema0.cc:35