Minsky
schema1::Minsky Struct Reference

#include <schema1.h>

Collaboration diagram for schema1::Minsky:
Collaboration graph

Public Member Functions

 Minsky ()
 
 Minsky (const schema0::Minsky &m)
 
 Minsky (classdesc::xml_unpack_t &data)
 populate schema from XML data More...
 
void removeIntVarOrphans ()
 

Public Attributes

int schemaVersion =Minsky::version
 
MinskyModel model
 
vector< shared_ptr< Layout > > layout
 
double zoomFactor =1
 

Static Public Attributes

static const int version =1
 

Detailed Description

Definition at line 337 of file schema1.h.

Constructor & Destructor Documentation

◆ Minsky() [1/3]

schema1::Minsky::Minsky ( )
inline

Definition at line 344 of file schema1.h.

344 : schemaVersion(-1) {} // schemaVersion defined on read in
int schemaVersion
Definition: schema1.h:340

◆ Minsky() [2/3]

schema1::Minsky::Minsky ( const schema0::Minsky m)

Definition at line 69 of file schema1.cc.

References schema0::Minsky::epsAbs, schema0::Minsky::epsRel, schema0::Minsky::godleyItems, schema0::Minsky::groupItems, schema0::Minsky::nSteps, schema0::Minsky::operations, schema0::Plots::plots, schema0::Minsky::plots, schema0::Minsky::ports, schema0::Minsky::stepMax, schema0::Minsky::stepMin, schema0::VariableManager::values, schema0::Minsky::variables, and schema0::Minsky::wires.

70  {
71  // uniquify all IDs
72  int nextId=0;
73  map<int,int> newPortIds;
74  map<int,int> newOpIds;
75  map<int,int> newVarIds;
76 
77  for (auto& i: m.ports)
78  newPortIds[i.first]=nextId++;
79  for (auto& i: m.wires)
80  {
81  model.wires.emplace_back(nextId, newPortIds[i.second.from], newPortIds[i.second.to]);
82  layout.emplace_back(new WireLayout(nextId++, i.second));
83  }
84  for (auto v: m.variables) //NOLINT - index var mutated in loop body
85  {
86  newVarIds[v.first]=nextId;
87  v.second.m_outPort=newPortIds[v.second.m_outPort];
88  if (v.second.m_inPort>=0)
89  v.second.m_inPort=newPortIds[v.second.m_inPort];
90  // values init field overrides that of the variable's
91  auto value=m.variables.values.find(v.second.name);
92  if (value!=m.variables.values.end())
93  v.second.init=value->second.init;
94  model.variables.emplace_back(nextId, v.second);
95  layout.emplace_back(new ItemLayout(nextId++, v.second));
96  }
97  for (auto i: m.operations)
98  {
99  newOpIds[i.first]=nextId;
100  for (auto& j: i.second.m_ports)
101  j=newPortIds[j];
102  if (i.second.intVar>-1) i.second.intVar=newVarIds[i.second.intVar];
103  model.operations.emplace_back(nextId, i.second);
104  layout.emplace_back(new ItemLayout(nextId++, i.second));
105  }
106 
107  for (auto i: m.plots.plots)
108  {
109  for (auto& j: i.second.ports)
110  j=newPortIds[j];
111  // insert another 6 ports for axis ranges that weren't there in schema 0
112  // move first 4 ports (x ports) to end, and add anothe 4 x ports
113  i.second.ports=(pcoord(6)+nextId)<<
114  i.second.ports[pcoord(8)+4]<<
115  i.second.ports[pcoord(4)]<<
116  (pcoord(4)+nextId+6);
117  nextId+=10;
118  model.plots.emplace_back(nextId, i.second);
119  layout.emplace_back(new PlotLayout(nextId++, i.second));
120  }
121 
122  for (auto g: m.groupItems)
123  {
124  for (auto& i: g.second.operations)
125  i=newOpIds[i];
126  for (auto& i: g.second.variables)
127  i=newVarIds[i];
128  for (auto& j: g.second.m_ports)
129  j=newPortIds[j];
130  // wires not used in new schema, no need to renumber
131  model.groups.emplace_back(nextId, g.second);
132  layout.emplace_back(new GroupLayout(nextId++, g.second));
133  }
134 
135  for (auto g: m.godleyItems)
136  {
137  // need to renumber ports in variables
138  for (auto& v: g.second.flowVars)
139  v.m_inPort=newPortIds[v.m_inPort];
140  for (auto& v: g.second.stockVars)
141  v.m_outPort=newPortIds[v.m_outPort];
142  model.godleys.emplace_back(nextId, g.second);
143  layout.emplace_back(new PositionLayout(nextId++, g.second.x, g.second.y));
144  }
145 
152  }
vector< Plot > plots
Definition: schema1.h:330
int nSteps
number of steps per GUI update
Definition: schema0.h:228
vector< shared_ptr< Layout > > layout
Definition: schema1.h:342
GroupIcons groupItems
Definition: schema0.h:219
VariableValues values
map of ports to variables
Definition: schema0.h:122
void removeIntVarOrphans()
Definition: schema1.cc:47
minsky::Simulation rungeKutta
Definition: schema1.h:334
double epsAbs
absolute error
Definition: schema0.h:229
vector< Godley > godleys
Definition: schema1.h:333
MinskyModel model
Definition: schema1.h:341
double stepMin
Runge-Kutta parameters.
Definition: schema0.h:226
vector< Group > groups
Definition: schema1.h:331
vector< Operation > operations
Definition: schema1.h:328
double epsRel
relative error
Definition: schema0.h:230
double stepMax
maximum step size
Definition: schema0.h:227
vector< Variable > variables
Definition: schema1.h:329
Operations operations
Definition: schema0.h:215
VariableManager variables
Definition: schema0.h:216
vector< Wire > wires
Definition: schema1.h:326
GodleyItems godleyItems
Definition: schema0.h:212

◆ Minsky() [3/3]

schema1::Minsky::Minsky ( classdesc::xml_unpack_t &  data)
inline

populate schema from XML data

Definition at line 348 of file schema1.h.

348  : schemaVersion(0)
349  {
350  minsky::loadSchema<schema0::Minsky>(*this,data,"Minsky");
352  }
void removeIntVarOrphans()
Definition: schema1.cc:47
int schemaVersion
Definition: schema1.h:340

Member Function Documentation

◆ removeIntVarOrphans()

void schema1::Minsky::removeIntVarOrphans ( )

See ticket #329 and references within. At some stage, IntOp had no destructor, which leads to an orphaned, invisible integral variable, with invalid output port. This bit of code deals with corrupt schema files that have been caused by this problem

Definition at line 47 of file schema1.cc.

References minsky::VariableType::integral, and minsky::OperationType::integrate.

48  {
49  set<string> intNames;
50  for (vector<Operation>::const_iterator o=model.operations.begin();
51  o!=model.operations.end(); ++o)
53  intNames.insert(o->name);
54 
55  IsOrphan isOrphan;
56  for (vector<Variable>::const_iterator v=model.variables.begin();
57  v!=model.variables.end(); ++v)
58  // an orphaned variable is an integral variable not attached to an integral and without
59  if (v->type==minsky::VariableType::integral && intNames.contains(v->name)==0)
60  isOrphan.insert(v->id);
61 
62  model.variables.erase
63  (remove_if(model.variables.begin(), model.variables.end(), isOrphan),
64  model.variables.end());
65  layout.erase
66  (remove_if(layout.begin(), layout.end(), isOrphan), layout.end());
67  }
vector< shared_ptr< Layout > > layout
Definition: schema1.h:342
MinskyModel model
Definition: schema1.h:341
vector< Operation > operations
Definition: schema1.h:328
vector< Variable > variables
Definition: schema1.h:329

Member Data Documentation

◆ layout

vector<shared_ptr<Layout> > schema1::Minsky::layout

Definition at line 342 of file schema1.h.

Referenced by schema2::Minsky::Minsky().

◆ model

MinskyModel schema1::Minsky::model

Definition at line 341 of file schema1.h.

Referenced by schema2::Minsky::Minsky().

◆ schemaVersion

int schema1::Minsky::schemaVersion =Minsky::version

Definition at line 340 of file schema1.h.

◆ version

const int schema1::Minsky::version =1
static

Definition at line 339 of file schema1.h.

◆ zoomFactor

double schema1::Minsky::zoomFactor =1

Definition at line 343 of file schema1.h.

Referenced by schema2::Minsky::Minsky().


The documentation for this struct was generated from the following files: