Minsky
schema0.h
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 
20 
30 #ifndef SCHEMA_SCHEMA_0
31 #define SCHEMA_SCHEMA_0
32 
33 #include "operationType.h"
34 #include "variableType.h"
35 #include "assetClass.h"
36 #include <arrays.h>
37 #include <plot.h>
38 
39 namespace schema0
40 {
41  struct Port
42  {
43  bool input; //true if input port
44  double x,y;
45  Port(float x=0, float y=0, bool input=false): input(input), x(x), y(y) {}
46  };
47 
48  struct Wire
49  {
51  int from, to;
52  bool visible;
53  ecolab::array<float> coords;
55  Wire(int from=0, int to=0): from(from), to(to), visible(true) {}
56  };
57 
58 
59  struct Operation
60  {
61  double x{10}, y{10};
62  double value{0};
63  double rotation{0};
64 
65  bool visible{true};
67 
68  bool sliderVisible{false}, sliderBoundsSet{false}, sliderStepRel{false};
70 
71  std::string m_description;
72  std::string description;
73  std::vector<int> m_ports;
75  int intVar{-1};
76  };
77 
78  struct VariablePtr
79  {
81 
82  double x{0}, y{0};
83  std::string init{"0"};
84  std::string name;
85  double rotation{0};
86 
91  bool visible{true};
93  bool m_godley{false};
94 
95  bool operator<(const VariablePtr& x) const
96  {return name<x.name;}
97  };
98 
99  // used to support an older schema
100  struct Variable: public VariablePtr {};
101 
103  {
105  int m_idx{-1};
106 
107  std::string init;
108  bool godleyOverridden{false};
109 
111  const std::string& init="0"): m_type(type), init(init) {}
112  };
113 
114 
115  struct VariableManager: public std::map<int,Variable>
116  {
117  typedef std::map<int,Variable> Variables;
118  typedef std::map<std::string, VariableValue> VariableValues;
119 
120  std::set<std::string> wiredVariables;
121  std::map<int, int> portToVariable;
123  };
124 
125  struct GodleyTable
126  {
127  std::vector<std::vector<std::string> > data;
129  std::vector<minsky::GodleyAssetClass::AssetClass> m_assetClass;
131  std::string title;
132 
134  std::size_t rows() const {return data.size();}
135  };
136 
137  struct GodleyIcon
138  {
139  double adjustHoriz, adjustVert; // difference between where variables are displayed and screen coordinates
140  double x, y;
141  double scale;
142  std::vector<VariablePtr> flowVars, stockVars;
144  };
145 
146  class GroupIcon
147  {
148  std::vector<int> inVariables, outVariables;
150  public:
151  std::vector<int> operations;
152  std::vector<int> variables;
153  std::vector<int> wires;
154  ecolab::array<int> m_ports;
155 
156  std::string name;
157  double x,y; //icon position
158  double width, height; // size of icon
159  double rotation; // orientation of icon
160 
161  GroupIcon(): width(100), height(100), rotation(0) {}
162  };
163 
164 
165 
166  // a place to put helper classes to manage XML evolution
167  namespace xml_conversions
168  {
169  struct GodleyIcon
170  {
171  std::set<Variable> flowVars, stockVars;
172  };
173  }
174 
175  struct PlotWidget
176  {
178  double fontScale;
179  double offx, offy;
180  bool logx, logy;
181  bool grid;
183  bool autoscale;
184  ecolab::Plot::PlotType plotType;
185  double minx, maxx, miny, maxy;
186  ecolab::array<int> ports;
187  std::vector<VariableValue> yvars;
188  std::vector<VariableValue> xvars;
190 
191  std::vector<std::string> images;
192 
193  double x,y;
194  };
195 
196 
197  struct Plots
198  {
199  typedef std::map<std::string, PlotWidget> Map;
201  };
202 
203  struct Minsky
204  {
205  typedef std::map<int, Port> Ports;
206  typedef std::map<int, Wire> Wires;
209 
210  GodleyTable godley; // deprecated - needed for Minsky.1 capability
211  typedef std::map<int, GodleyIcon> GodleyItems;
213 
214  typedef std::map<int, Operation> Operations;
217 
218  typedef std::map<int, GroupIcon> GroupIcons;
220 
222 
223  Minsky() {}
224 
226  double stepMin=0;
227  double stepMax=1;
228  int nSteps=1;
229  double epsAbs=1e-3;
230  double epsRel=1e-2;
231 
232  Minsky(classdesc::xml_unpack_t& data)
233  {
234  ::xml_unpack(data,"root",*this);
236  }
237 
245  void removeIntVarOrphans();
246  };
247 
248 }
249 
250 namespace classdesc
251 {
252  template <class T>
253  void xml_unpackp(xml_unpack_t& t, const string& d, ecolab::array<T>& a)
254  {
255  string x; xml_unpack(t,d,x);
256  std::istringstream is(x);
257  is>>a;
258  }
259 }
260 
261 #include "schema0.xcd"
262 #endif
std::set< Variable > flowVars
Definition: schema0.h:171
double sliderMax
Definition: schema0.h:69
VariableValue yminVar
Definition: schema0.h:189
double adjustHoriz
Definition: schema0.h:139
bool sliderVisible
Definition: schema0.h:68
double scale
scale factor of the XGL image
Definition: schema0.h:141
double rotation
for constants
Definition: schema0.h:63
std::vector< int > operations
Definition: schema0.h:151
void xml_unpack(classdesc::xml_unpack_t &, const classdesc::string &, classdesc::ref< ecolab::urand > &)
std::map< int, Operation > Operations
Definition: schema0.h:214
Definition: input.py:1
VariableValue xminVar
Definition: schema0.h:189
int nSteps
number of steps per GUI update
Definition: schema0.h:228
double sliderStep
Definition: schema0.h:69
ecolab::array< int > ports
Definition: schema0.h:186
bool operator<(const VariablePtr &x) const
Definition: schema0.h:95
std::vector< std::string > images
Definition: schema0.h:191
bool grid
draw grid
Definition: schema0.h:181
std::map< int, Wire > Wires
Definition: schema0.h:206
GroupIcons groupItems
Definition: schema0.h:219
VariableValues values
map of ports to variables
Definition: schema0.h:122
std::map< int, Variable > Variables
Definition: schema0.h:117
VariableValue xmaxVar
Definition: schema0.h:189
std::vector< int > m_ports
older version of name
Definition: schema0.h:73
double epsAbs
absolute error
Definition: schema0.h:229
std::map< std::string, PlotWidget > Map
Definition: schema0.h:199
Port(float x=0, float y=0, bool input=false)
Definition: schema0.h:45
std::set< std::string > wiredVariables
Definition: schema0.h:120
int intVar
integration variable associated with this op. -1 if not used
Definition: schema0.h:75
double x
Definition: schema0.h:44
void xml_unpackp(xml_unpack_t &t, const string &d, ecolab::array< T > &a)
Definition: schema0.h:253
std::map< int, GodleyIcon > GodleyItems
Definition: schema0.h:211
double stepMin
Runge-Kutta parameters.
Definition: schema0.h:226
minsky::VariableType::Type m_type
Definition: schema0.h:104
Minsky(classdesc::xml_unpack_t &data)
Definition: schema0.h:232
minsky::VariableType::Type m_type
Definition: schema0.h:80
std::string description
name of constant, variable
Definition: schema0.h:72
bool visible
whether wire is visible on Canvas display coordinates
Definition: schema0.h:52
GodleyTable godley
Definition: schema0.h:210
std::string m_description
Definition: schema0.h:71
VariableValue ymaxVar
Definition: schema0.h:189
double sliderMin
Definition: schema0.h:69
VariableValue(minsky::VariableType::Type type=minsky::VariableType::undefined, const std::string &init="0")
Definition: schema0.h:110
std::string name
variable name
Definition: schema0.h:84
double offy
origin of plot within image
Definition: schema0.h:179
double fontScale
scale tick labels
Definition: schema0.h:178
double epsRel
relative error
Definition: schema0.h:230
std::vector< int > inVariables
Definition: schema0.h:148
std::map< int, int > portToVariable
variables whose input port is wired
Definition: schema0.h:121
bool doubleEntryCompliant
Definition: schema0.h:130
double rotation
rotation if icon, in degrees
Definition: schema0.h:85
std::set< Variable > stockVars
Definition: schema0.h:171
std::string name
Definition: schema0.h:156
int m_inPort
where wires connect to
Definition: schema0.h:92
double stepMax
maximum step size
Definition: schema0.h:227
int from
ports this wire connects
Definition: schema0.h:51
ecolab::array< int > m_ports
Definition: schema0.h:154
bool logy
logarithmic plots (x/y axes)
Definition: schema0.h:180
double y
position in canvas
Definition: schema0.h:82
bool input
Definition: schema0.h:43
std::map< std::string, VariableValue > VariableValues
Definition: schema0.h:118
minsky::OperationType::Type m_type
Definition: schema0.h:66
std::size_t rows() const
Definition: schema0.h:134
bool leadingMarker
draw a leading marker on the curve (full draw only)
Definition: schema0.h:182
Wire(int from=0, int to=0)
Definition: schema0.h:55
std::vector< VariableValue > yvars
Definition: schema0.h:187
std::vector< VariableValue > xvars
Definition: schema0.h:188
bool m_godley
variable is in a Godley table
Definition: schema0.h:93
Operations operations
Definition: schema0.h:215
std::vector< VariablePtr > stockVars
Definition: schema0.h:142
std::string init
initial value of variable
Definition: schema0.h:83
std::vector< minsky::GodleyAssetClass::AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: schema0.h:129
bool visible
rotation if icon, in degrees
Definition: schema0.h:65
void removeIntVarOrphans()
Definition: schema0.cc:43
std::string init
index into value vector
Definition: schema0.h:107
std::vector< VariablePtr > flowVars
Definition: schema0.h:142
ecolab::array< float > coords
Definition: schema0.h:54
VariableManager variables
Definition: schema0.h:216
std::vector< int > outVariables
Definition: schema0.h:148
std::string title
Definition: schema0.h:131
ecolab::Plot::PlotType plotType
Definition: schema0.h:184
std::vector< int > wires
Definition: schema0.h:153
std::map< int, GroupIcon > GroupIcons
Definition: schema0.h:218
std::map< int, Port > Ports
Definition: schema0.h:205
CLASSDESC_ACCESS(GroupIcon)
bool autoscale
autoscale plot to data
Definition: schema0.h:183
bool sliderBoundsSet
Definition: schema0.h:68
double y
Definition: schema0.h:44
GodleyItems godleyItems
Definition: schema0.h:212
double y
position of Godley icon
Definition: schema0.h:140
std::vector< std::vector< std::string > > data
Definition: schema0.h:127
int nyTicks
number of x/y-axis ticks
Definition: schema0.h:177
GodleyTable table
Definition: schema0.h:143
std::vector< int > variables
Definition: schema0.h:152
bool sliderStepRel
Definition: schema0.h:68