Minsky
minsky::Minsky Class Reference

#include <minsky.h>

Inheritance diagram for minsky::Minsky:
Inheritance graph
Collaboration diagram for minsky::Minsky:
Collaboration graph

Public Types

enum  CmdData { no_command, is_const, is_setterGetter, generic }
 
enum  MemCheckResult { OK, proceed, abort }
 check whether to proceed or abort, given a request to allocate bytes of memory. Implemented in MinskyTCL More...
 
using AvailableOperationsMapping = classdesc::StringKeyMap< std::vector< OperationType::Type > >
 

Public Member Functions

void addNewPublicationTab (const std::string &name)
 
void addCanvasItemToPublicationTab (size_t i)
 
bool multipleEquities () const
 
bool multipleEquities (const bool &m)
 
bool edited () const
 reflects whether the model has been changed since last save More...
 
bool reset_flag () const
 true if reset needs to be called prior to numerical integration More...
 
void markEdited ()
 indicate model has been changed since last saved More...
 
void requestReset ()
 
void requestRedraw ()
 requests a redraw of the curren active tab More...
 
bool resetIfFlagged () override
 checks whether a reset is required, and resets the simulation if so More...
 
void populateMissingDimensions ()
 fills in dimensions table with all loaded ravel axes More...
 
void populateMissingDimensionsFromVariable (const VariableValue &, bool &incompatibleMessageDisplayed)
 populate missing dimensions from a variableValue More...
 
void populateMissingDimensionsFromVariable (const VariableValue &v)
 
void renameDimension (const std::string &oldName, const std::string &newName)
 
void setGodleyIconResource (const string &s)
 
void setGroupIconResource (const string &s)
 
void setLockIconResource (const string &locked, const string &unlocked)
 
void setRavelIconResource (const string &s)
 
std::set< string > matchingTableColumns (const GodleyIcon &currTable, GodleyAssetClass::AssetClass ac)
 
void importDuplicateColumn (GodleyTable &srcTable, int srcCol)
 find any duplicate column, and use it as a source column for balanceDuplicateColumns More...
 
void balanceDuplicateColumns (const GodleyIcon &srcTable, int srcCol)
 makes all duplicated columns consistent with srcTable, srcCol More...
 
std::vector< std::string > allGodleyFlowVars () const
 
 Minsky ()
 
 ~Minsky ()
 
void clearAllMaps (bool clearHistory)
 
void clearAllMaps ()
 
void clearAllMapsTCL ()
 
VariablePtr definingVar (const std::string &valueId) const
 returns reference to variable defining (ie input wired) for valueId More...
 
void saveCanvasItemAsFile (const string &fileName) const
 
void initGodleys ()
 
void cut ()
 erase items in current selection, put copy into clipboard More...
 
void copy () const
 copy items in current selection into clipboard More...
 
void paste ()
 paste clipboard as a new group or ungrouped items on the canvas. canvas.itemFocus is set to refer to the new group or items. More...
 
bool clipboardEmpty () const
 return true if nothing available in clipboard More...
 
void saveSelectionAsFile (const string &fileName) const
 
void insertGroupFromFile (const string &file)
 
void makeVariablesConsistent ()
 
void imposeDimensions ()
 
void garbageCollect ()
 
bool cycleCheck () const
 checks for presence of illegal cycles in network. Returns true if there are some More...
 
void openLogFile (const string &)
 opens the log file, and writes out a header line describing names of all variables More...
 
void closeLogFile ()
 closes log file More...
 
bool loggingEnabled () const
 returns true if logging is in operation More...
 
void constructEquations ()
 construct the equations based on input data More...
 
void dimensionalAnalysis () const
 performs dimension analysis, throws if there is a problem More...
 
void deleteAllUnits ()
 removes units markup from all variables in model More...
 
bool checkEquationOrder () const
 consistency check of the equation order. Should return true. Outputs the operation number of the invalidly ordered operation. More...
 
double deltaT () const
 
void reset ()
 resets the variables back to their initial values More...
 
std::vector< double > step ()
 step the equations (by n steps, default 1) More...
 
void save (const std::string &filename)
 
void load (const std::string &filename)
 load from a file More...
 
void exportSchema (const std::string &filename, int schemaLevel=1)
 
void displayErrorItem (const Item &op) const
 indicate operation item has error, if visible, otherwise contining group More...
 
std::string ecolabVersion () const
 
std::string ravelVersion () const
 
std::string autoSaveFile () const
 name of an auto save file More...
 
void setAutoSaveFile (const std::string &file)
 initialises auto saving empty file to turn off autosave More...
 
void clearHistory ()
 clear history More...
 
void checkPushHistory ()
 called periodically to ensure history up to date More...
 
bool pushHistory ()
 push current model state onto history if it differs from previous More...
 
bool commandHook (const std::string &command, unsigned nargs)
 Executed after each interpreter command to maintain undo/redo stack, edited flag, autosaving etc. More...
 
virtual CmdData getCommandData (const std::string &command) const
 return meta information on a given command More...
 
long undo (int changes=1)
 restore model to state changes ago More...
 
void convertVarType (const std::string &name, VariableType::Type type)
 Converts variable(s) named by name into a variable of type type. More...
 
void addIntegral ()
 add integral to current canvas item (which must be variable convertible to an integral variable More...
 
bool inputWired (const std::string &name) const
 returns true if any variable of name name has a wired input More...
 
void renderCanvasToPS (const std::string &filename)
 render canvas to a postscript file More...
 
void renderCanvasToPDF (const std::string &filename)
 render canvas to a PDF file More...
 
void renderCanvasToSVG (const std::string &filename)
 render canvas to an SVG file More...
 
void renderCanvasToPNG (const std::string &filename)
 render canvas to a PNG image file More...
 
void renderCanvasToPNG (const std::string &filename, const Canvas::ZoomCrop &z)
 Render canvas to a PNG file filename, scaling the canvas temporarily by zoom, shifts it to left, top, and crops to width, height (in ZoomCrop struct). More...
 
void renderCanvasToEMF (const std::string &filename)
 render canvas to a EMF image file (Windows only) More...
 
void renderAllPlotsAsSVG (const string &prefix) const
 render all plots More...
 
void exportAllPlotsAsCSV (const string &prefix) const
 export all plots More...
 
void setAllDEmode (bool)
 set DE mode on all godley tables More...
 
void srand (int seed)
 set std library RNG seed More...
 
void setGodleyDisplayValue (bool displayValues, GodleyTable::DisplayStyle displayStyle)
 set display value mode on all godley table editor modes More...
 
void importVensim (const std::string &)
 import a Vensim file More...
 
void redrawAllGodleyTables ()
 request all Godley table windows to redraw More...
 
virtual void setBusyCursor ()
 set/clear busy cursor in GUI More...
 
virtual void clearBusyCursor ()
 
virtual void progress (const std::string &title, int)
 set progress bar, out of 100, labelling the progress bar with title More...
 
virtual void bookmarkRefresh ()
 refresh the bookmark menu after changes More...
 
virtual void resetScroll ()
 reset main window scroll bars after model has been panned More...
 
virtual void message (const std::string &)
 display a message in a popup box on the GUI More...
 
virtual void runItemDeletedCallback (const Item &)
 run callback attached to item More...
 
virtual MemCheckResult checkMemAllocation (size_t bytes) const
 
std::size_t physicalMem () const
 returns amount of memory installed on system More...
 
vector< string > listFonts () const
 
int numOpArgs (OperationType::Type o)
 
OperationType::Group classifyOp (OperationType::Type o) const
 
void latex (const std::string &filename, bool wrapLaTeXLines)
 
void matlab (const std::string &filename)
 
string latex2pango (const std::string &x)
 
std::vector< std::string > availableOperations ()
 list of available operations More...
 
Minsky::AvailableOperationsMapping availableOperationsMapping () const
 
std::vector< std::string > variableTypes ()
 list of available variable types More...
 
std::vector< std::string > assetClasses ()
 return list of available asset classes More...
 
void autoLayout ()
 auto layout current open group and recentre More...
 
void randomLayout ()
 randomly layout current open group and recentre reinitialises canvas to the group located in item More...
 
void openGroupInCanvas ()
 
void openModelInCanvas ()
 reinitialises canvas to the toplevel group More...
 
void listAllInstances ()
 
void nameCurrentItem (const std::string &name)
 
void itemFromNamedItem (const std::string &name)
 
bool triggerCheckMemAllocationCallback () const
 trigger checkMem callback for testing purposes More...
 
char getc () const
 Used to implement a pause until return pressed for attaching debugger purposes. More...
 
void setDefinition (const std::string &valueId, const std::string &definition)
 add/replace a definition for a flow variable given by valueId More...
 
void pushFlags ()
 push and pop state of the flags More...
 
void popFlags ()
 push and pop state of the flags More...
 
std::string defaultFont ()
 the default used by Pango More...
 
std::string defaultFont (const std::string &x)
 the default used by Pango More...
 
double fontScale ()
 an extra scaling factor of Pango fonts More...
 
double fontScale (double)
 an extra scaling factor of Pango fonts More...
 
- Public Member Functions inherited from minsky::RungeKutta
virtual ~RungeKutta ()=default
 
void rkreset ()
 reset the simulation More...
 
void rkstep ()
 step the equations (by n steps, default 1) evaluate the flow equations without stepping. More...
 
void evalEquations ()
 
- Public Member Functions inherited from minsky::Minsky_multipleEquities
 Minsky_multipleEquities (const std::string &name, ecolab::TCLAccessor< Minsky, bool >::Getter g, ecolab::TCLAccessor< Minsky, bool >::Setter s)
 

Static Public Member Functions

static void saveGroupAsFile (const Group &, const string &fileName)
 
static bool ravelAvailable ()
 
static bool ravelExpired ()
 
static int daysUntilRavelExpires ()
 

Public Attributes

PannableTab< EquationDisplayequationDisplay
 
FontDisplay fontSampler
 
PhillipsDiagram phillipsDiagram
 
std::vector< PubTabpublicationTabs
 
VariableValues variableValues
 
Dimensions dimensions
 
Conversions conversions
 
std::map< Units, double > maxValue
 stash the maximum absolute value obtained by a dimensioned quantity More...
 
std::map< Units, double > maxFlowValue
 
SVGRenderer histogramResource
 
Exclude< std::map< std::string, std::shared_ptr< CallableFunction > > > userFunctions
 
GroupPtr model {new Group}
 
Canvas canvas {model}
 
std::set< string > logVarList
 set of variables (valueIds) to log More...
 
double lastT {0}
 previous timestep More...
 
int numBackups =1
 number of previous versions of saved files to keep save to a file More...
 
std::string fileVersion
 Minsky version file was saved under. More...
 
unsigned maxHistory {100}
 maximum no. of history states to save More...
 
int maxWaitMS =100
 maximum wait in millisecond between redrawing canvas during simulation More...
 
bool doPushHistory =true
 flag to indicate whether a TCL should be pushed onto the history stack, or logged in a recording. This is used to avoid movements being added to recordings and undo history More...
 
bool displayValues =false
 
GodleyTable::DisplayStyle displayStyle =GodleyTable::sign
 
std::shared_ptr< VariableInstanceListvariableInstanceList
 supports navigation to all instances of current variable More...
 
std::map< std::string, std::weak_ptr< Item > > namedItems
 
VariablePane variablePane
 
- Public Attributes inherited from minsky::RungeKutta
double t {0}
 time More...
 
bool running =false
 controls whether simulation is running More...
 
bool reverse =false
 reverse direction of simulation More...
 
EvalGodley evalGodley
 
- Public Attributes inherited from minsky::Simulation
double stepMin {0}
 
double stepMax {0.01}
 
int nSteps {1}
 
double epsRel {1e-2}
 
double epsAbs {1e-3}
 
int order {4}
 
bool implicit {false}
 
int simulationDelay {0}
 
std::string timeUnit
 
double tmax {INFINITY}
 
double t0 {0}
 

Static Public Attributes

static const std::string minskyVersion =MINSKY_VERSION
 return the AEGIS assigned version number More...
 
- Static Public Attributes inherited from minsky::ValueVector
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
 vector of variables that are integrated via Runge-Kutta. These variables label the columns of the Godley table More...
 
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
 variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table More...
 

Private Member Functions

 CLASSDESC_ACCESS (Minsky)
 
std::string diagnoseNonFinite () const
 returns a diagnostic about an item that is infinite or NaN. Either a variable name, or and operator type. More...
 
void logVariables () const
 write current state of all variables to the log file More...
 
void balanceColumns (const GodleyIcon &srcGodley, int srcCol, GodleyIcon &destGodley, int destCol) const
 balance two Godley columns More...
 
void removeItems (Wire &wire)
 remove the definition network from wire, up to, but not including attached variables. More...
 

Private Attributes

Exclude< ptime > lastRedraw
 
bool m_multipleEquities =false
 

Additional Inherited Members

- Protected Member Functions inherited from minsky::RungeKutta
void evalEquations (double result[], double, const double vars[])
 
void evalJacobian (Matrix &, double, const double vars[])
 
- Static Protected Member Functions inherited from minsky::RungeKutta
static int RKfunction (double, const double y[], double f[], void *)
 function to be integrated (internal use) More...
 
static int jacobian (double, const double y[], double *, double dfdt[], void *)
 compute jacobian (internal use) More...
 

Detailed Description

Definition at line 131 of file minsky.h.

Member Typedef Documentation

◆ AvailableOperationsMapping

using minsky::Minsky::AvailableOperationsMapping = classdesc::StringKeyMap<std::vector<OperationType::Type> >

Definition at line 510 of file minsky.h.

Member Enumeration Documentation

◆ CmdData

Enumerator
no_command 
is_const 
is_setterGetter 
generic 

Definition at line 376 of file minsky.h.

◆ MemCheckResult

check whether to proceed or abort, given a request to allocate bytes of memory. Implemented in MinskyTCL

Enumerator
OK 
proceed 
abort 

Definition at line 463 of file minsky.h.

Constructor & Destructor Documentation

◆ Minsky()

minsky::Minsky::Minsky ( )
inline

Definition at line 241 of file minsky.h.

241  :
242  ECOLAB_ACESSOR_INIT(Minsky, multipleEquities),
243  equationDisplay(*this) {
244  lastRedraw=boost::posix_time::microsec_clock::local_time();
245  model->iHeight(std::numeric_limits<float>::max());
246  model->iWidth(std::numeric_limits<float>::max());
247  model->self=model;
248  publicationTabs.emplace_back("Publication");
249  }
PannableTab< EquationDisplay > equationDisplay
Definition: minsky.h:153
Exclude< ptime > lastRedraw
Definition: minsky.h:142
std::vector< PubTab > publicationTabs
Definition: minsky.h:156
bool multipleEquities() const
Definition: minsky.h:165
GroupPtr model
Definition: minsky.h:255

◆ ~Minsky()

minsky::Minsky::~Minsky ( )

Definition at line 120 of file minsky.cc.

References minsky::remove().

121  {
122  if (edited() && autoSaver)
123  // if we're at this point, then the user has already been asked to save, and chosen no.
124  boost::filesystem::remove(autoSaver->fileName);
125  }
bool edited() const
reflects whether the model has been changed since last save
Definition: minsky.h:169
void remove(std::vector< T > &x, const V &v)
remove an element from a vector. V must be comparable to a T
Definition: str.h:89
Here is the call graph for this function:

Member Function Documentation

◆ addCanvasItemToPublicationTab()

void minsky::Minsky::addCanvasItemToPublicationTab ( size_t  i)
inline

Definition at line 159 of file minsky.h.

159  {
160  if (canvas.item && i<publicationTabs.size())
161  publicationTabs[i].items.emplace_back(canvas.item);
162  }
std::vector< PubTab > publicationTabs
Definition: minsky.h:156
Canvas canvas
Definition: minsky.h:256
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ addIntegral()

void minsky::Minsky::addIntegral ( )

add integral to current canvas item (which must be variable convertible to an integral variable

Definition at line 1527 of file minsky.cc.

References minsky::Item::moveTo().

Referenced by minsky::MinskyTCL::addIntegral().

1528  {
1529  if (auto v=canvas.item->variableCast())
1530  if (auto g=v->group.lock())
1531  {
1532  // nb throws if conversion cannot be performed
1533  convertVarType(v->valueId(),VariableType::integral);
1534  auto integ=new IntOp;
1535  g->addItem(integ);
1536  integ->moveTo(canvas.item->x(), canvas.item->y());
1537  // remove intVar from its group
1538  if (auto g=integ->intVar->group.lock())
1539  g->removeItem(*integ->intVar);
1540  integ->intVar=dynamic_pointer_cast<VariableBase>(canvas.item);
1541  integ->toggleCoupled();
1542 
1544  }
1545  }
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
void convertVarType(const std::string &name, VariableType::Type type)
Converts variable(s) named by name into a variable of type type.
Definition: minsky.cc:1457
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNewPublicationTab()

void minsky::Minsky::addNewPublicationTab ( const std::string &  name)
inline

Definition at line 158 of file minsky.h.

158 {publicationTabs.emplace_back(name);}
std::vector< PubTab > publicationTabs
Definition: minsky.h:156

◆ allGodleyFlowVars()

vector< string > minsky::Minsky::allGodleyFlowVars ( ) const

Definition at line 820 of file minsky.cc.

821  {
822  set<string> r;
823  model->recursiveDo(&GroupItems::items, [&](const Items&, Items::const_iterator i) {
824  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
825  {
826  auto flowVars=g->table.getVariables();
827  r.insert(flowVars.begin(),flowVars.end());
828  }
829  return false;
830  });
831  return {r.begin(),r.end()};
832  }
std::vector< ItemPtr > Items
Definition: item.h:366
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
GroupPtr model
Definition: minsky.h:255

◆ assetClasses()

vector< string > minsky::Minsky::assetClasses ( )

return list of available asset classes

Definition at line 1610 of file minsky.cc.

1611  {return enumVals<GodleyTable::AssetClass>();}

◆ autoLayout()

void minsky::Minsky::autoLayout ( )

auto layout current open group and recentre

Definition at line 1625 of file minsky.cc.

1626  {
1627  canvas.model->autoLayout();
1628  canvas.recentre();
1629  }
void recentre()
adjust canvas so that -ve coordinates appear on canvas
Definition: canvas.cc:927
Model model
Definition: canvas.h:103
Canvas canvas
Definition: minsky.h:256

◆ autoSaveFile()

std::string minsky::Minsky::autoSaveFile ( ) const
inline

name of an auto save file

Definition at line 357 of file minsky.h.

357 {return autoSaver? autoSaver->fileName: std::string();}

◆ availableOperations()

vector< string > minsky::Minsky::availableOperations ( )

list of available operations

Definition at line 1606 of file minsky.cc.

1607  {return enumVals<OperationType::Type>();}

◆ availableOperationsMapping()

Minsky::AvailableOperationsMapping minsky::Minsky::availableOperationsMapping ( ) const

Definition at line 1613 of file minsky.cc.

References minsky::op, and minsky::to_string().

1614  {
1617  {
1618  if (classifyOp(op)==OperationType::general) continue;
1619  if (op==OperationType::copy) continue;
1620  r[classdesc::to_string(classifyOp(op))].push_back(op);
1621  }
1622  return r;
1623  }
OperationType::Group classifyOp(OperationType::Type o) const
Definition: minsky.h:495
classdesc::StringKeyMap< std::vector< OperationType::Type > > AvailableOperationsMapping
Definition: minsky.h:510
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
Here is the call graph for this function:

◆ balanceColumns()

void minsky::Minsky::balanceColumns ( const GodleyIcon srcGodley,
int  srcCol,
GodleyIcon destGodley,
int  destCol 
) const
private

balance two Godley columns

Definition at line 645 of file minsky.cc.

References minsky::FlowCoef::coef, minsky::GodleyIcon::flowSignature(), minsky::FlowCoef::name, minsky::scope(), minsky::FlowCoef::str(), minsky::GodleyIcon::table, minsky::trimWS(), minsky::uqName(), and minsky::GodleyIcon::valueId().

646  {
647  auto& srcTable=srcGodley.table;
648  auto& destTable=destGodley.table;
649  // reverse lookup tables for mapping flow variable to destination row numbers via row labels
650  map<string,string> srcRowLabels;
651  map<string, int> destRowLabels;
652  set<string> uniqueSrcRowLabels; // check for uniqueness of source row labels
653  for (size_t row=1; row!=srcTable.rows(); ++row)
654  if (!srcTable.initialConditionRow(row) && !srcTable.cell(row,0).empty() &&
655  !srcTable.cell(row,srcCol).empty())
656  {
657  if (!uniqueSrcRowLabels.insert(srcTable.cell(row,0)).second)
658  throw runtime_error("Duplicate source row label: "+srcTable.cell(row,0));
659  const FlowCoef fc(srcTable.cell(row,srcCol));
660  if (!fc.name.empty())
661  srcRowLabels[srcGodley.valueId(fc.name)]=
662  trimWS(srcTable.cell(row,0));
663  }
664  else if (srcTable.initialConditionRow(row))
665  // copy directly into destination initial condition,
666  for (size_t r=1; r<destTable.rows(); ++r)
667  if (destTable.initialConditionRow(r))
668  destTable.cell(r,destCol)=srcTable.cell(row,srcCol);
669  for (size_t row=1; row!=destTable.rows(); ++row)
670  if (!destTable.initialConditionRow(row) && !destTable.cell(row,0).empty())
671  destRowLabels[trimWS(destTable.cell(row,0))]=row;
672 
673 
674  // compute column signature for both src and destination columns
675  map<string,double> srcFlows=srcGodley.flowSignature(srcCol),
676  destFlows=destGodley.flowSignature(destCol);
677  // items to add
678  for (map<string,double>::iterator i=srcFlows.begin(); i!=srcFlows.end(); ++i)
679  if (i->second != destFlows[i->first])
680  {
681  const int scope=-1;
682  if (i->first.find(':')!=string::npos)
683  minsky::scope(i->first);
684  FlowCoef df;
685  if (scope==-1 || !variableValues.count(i->first))
686  df.name=uqName(i->first);
687  else
688  df.name=variableValues[i->first]->name;
689  df.coef=i->second-destFlows[i->first];
690  if (df.coef==0) continue;
691  const string flowEntry=df.str();
692  const string rowLabel=srcRowLabels[srcGodley.valueId(i->first)];
693  const map<string,int>::iterator dr=destRowLabels.find(rowLabel);
694  if (dr!=destRowLabels.end())
695  if (FlowCoef(destTable.cell(dr->second, destCol)).coef==0)
696  destTable.cell(dr->second, destCol) = flowEntry;
697  else
698  // add a new blank labelled flow line
699  {
700  destTable.resize(destTable.rows()+1,destTable.cols());
701  destTable.cell(destTable.rows()-1, destCol) = flowEntry;
702  }
703  else
704  // labels don't match, so add a new labelled line
705  {
706  destTable.resize(destTable.rows()+1,destTable.cols());
707  destTable.cell(destTable.rows()-1, 0) = rowLabel;
708  destRowLabels[rowLabel] = destTable.rows()-1;
709  destTable.cell(destTable.rows()-1, destCol) = flowEntry;
710  }
711  }
712  // items to delete
713  set<size_t> rowsToDelete;
714  for (map<string,double>::iterator i=destFlows.begin(); i!=destFlows.end(); ++i)
715  if (i->second!=0 && srcFlows[i->first]==0)
716  for (size_t row=1; row<destTable.rows(); ++row)
717  {
718  FlowCoef fc(destTable.cell(row, destCol));
719  if (!fc.name.empty())
720  fc.name=destGodley.valueId(fc.name);
721  if (fc.name==destGodley.valueId(i->first))
722  {
723  destTable.cell(row, destCol).clear();
724  // if this leaves an empty row, delete entire row
725  for (size_t c=0; c<destTable.cols(); ++c)
726  if (!destTable.cell(row, c).empty())
727  goto rowNotEmpty;
728  rowsToDelete.insert(row);
729  rowNotEmpty:;
730  }
731  }
732  // amalgamate unlabelled rows with singular value
733  map<string,double> unlabelledSigs;
734  for (size_t row=1; row<destTable.rows(); ++row)
735  {
736  if (!destTable.singularRow(row, destCol)) continue;
737  const FlowCoef fc(destTable.cell(row, destCol));
738  unlabelledSigs[fc.name]+=fc.coef;
739  rowsToDelete.insert(row);
740  }
741  // append amalgamated rows
742  for (auto& i: unlabelledSigs)
743  if (i.second!=0)
744  {
745  destTable.insertRow(destTable.rows());
746  destTable.cell(destTable.rows()-1,destCol)=FlowCoef(i.second,i.first).str();
747  }
748 
749  for (auto row=rowsToDelete.rbegin(); row!=rowsToDelete.rend(); ++row)
750  destTable.deleteRow(*row);
751  }
VariableValues variableValues
Definition: minsky.h:200
size_t scope(const string &name)
extract scope from a qualified variable name
Definition: valueId.cc:83
std::string uqName(const std::string &name)
extract unqualified portion of name
Definition: valueId.cc:135
std::string trimWS(const std::string &s)
Definition: str.h:49
Here is the call graph for this function:

◆ balanceDuplicateColumns()

void minsky::Minsky::balanceDuplicateColumns ( const GodleyIcon srcTable,
int  srcCol 
)

makes all duplicated columns consistent with srcTable, srcCol

Definition at line 753 of file minsky.cc.

References minsky::GodleyTable::_assetClass(), minsky::GodleyTable::cell(), minsky::GodleyTable::cols(), minsky::GodleyIcon::table, minsky::trimWS(), and minsky::GodleyIcon::valueId().

Referenced by minsky::GodleyIcon::deleteRow(), minsky::GodleyTableEditor::mouseUp(), minsky::GodleyIcon::setCell(), and minsky::GodleyTableEditor::update().

754  {
755  const GodleyTable& srcTable=srcGodley.table;
756  if (srcCol<0 || size_t(srcCol)>=srcTable.cols()) return;
757  // find if there is a matching column
758  const string& colName=srcGodley.valueId(trimWS(srcTable.cell(0,srcCol)));
759  if (colName.empty() || colName==":_") return; //ignore blank columns
760 
761  bool matchFound=false;
762  model->recursiveDo
763  (&Group::items,
764  [&](Items& m, Items::iterator i)
765  {
766  if (auto gi=dynamic_cast<GodleyIcon*>(i->get()))
767  {
768  if (&gi->table==&srcTable) // if source table, then check for duplicated asset/equity columns
769  {
770  for (size_t col=1; col<gi->table.cols(); col++)
771  if (col==size_t(srcCol)) continue; // skip over source column
772  else if (srcGodley.valueId(trimWS(srcTable.cell(0,col)))==colName)
773  {
774  switch (srcGodley.table._assetClass(srcCol))
775  {
777  if (srcTable._assetClass(col)!=GodleyAssetClass::equity)
778  throw error("asset column %s matches a non-liability column",colName.c_str());
779  break;
781  if (srcTable._assetClass(col)!=GodleyAssetClass::asset)
782  throw error("equity column %s matches a non-asset column",colName.c_str());
783  break;
784  default:
785  throw error("invalid asset class for duplicate column %s",colName.c_str());
786  }
787  balanceColumns(srcGodley, srcCol, *gi, col);
788  }
789  }
790  else // match asset/liability columns on different Godley tables
791  for (size_t col=1; col<gi->table.cols(); col++)
792  if (gi->valueId(trimWS(gi->table.cell(0,col)))==colName) // we have a match
793  {
794  // checks asset class rules
795  switch (srcGodley.table._assetClass(srcCol))
796  {
798  if (gi->table._assetClass(col)!=GodleyAssetClass::liability)
799  throw error("asset column %s matches a non-liability column",colName.c_str());
800  break;
802  if (gi->table._assetClass(col)!=GodleyAssetClass::asset)
803  throw error("liability column %s matches a non-asset column",colName.c_str());
804  break;
805  default:
806  throw error("invalid asset class for duplicate column %s",colName.c_str());
807  }
808 
809  // checks that nom more than two duplicated columns exist
810  if (matchFound)
811  throw error("more than one duplicated column detected for %s",colName.c_str());
812  matchFound=true;
813  balanceColumns(srcGodley, srcCol, *gi, col);
814  }
815  }
816  return false;
817  }); // TODO - this lambda is FAR too long!
818  }
void balanceColumns(const GodleyIcon &srcGodley, int srcCol, GodleyIcon &destGodley, int destCol) const
balance two Godley columns
Definition: minsky.cc:645
std::vector< ItemPtr > Items
Definition: item.h:366
std::string trimWS(const std::string &s)
Definition: str.h:49
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bookmarkRefresh()

virtual void minsky::Minsky::bookmarkRefresh ( )
inlinevirtual

refresh the bookmark menu after changes

Reimplemented in minsky::anonymous_namespace{addon.cc}::AddOnMinsky.

Definition at line 450 of file minsky.h.

Referenced by minsky::GroupItems::addItem(), minsky::Item::adjustBookmark(), minsky::Group::deleteItem(), and minsky::Canvas::openGroupInCanvas().

450 {}
Here is the caller graph for this function:

◆ checkEquationOrder()

bool minsky::Minsky::checkEquationOrder ( ) const

consistency check of the equation order. Should return true. Outputs the operation number of the invalidly ordered operation.

Definition at line 1177 of file minsky.cc.

References minsky::op.

1178  {
1179  ecolab::array<bool> fvInit(flowVars.size(), false);
1180  // firstly, find all flowVars that are constants
1181  for (auto& v: variableValues)
1182  if (!inputWired(v.first) && v.second->idx()>=0)
1183  fvInit[v.second->idx()]=true;
1184 
1185  for (auto& e: equations)
1186  if (auto eo=dynamic_cast<const ScalarEvalOp*>(e.get()))
1187  {
1188  if (eo->out < 0|| (eo->numArgs()>0 && eo->in1.empty()) ||
1189  (eo->numArgs() > 1 && eo->in2.empty()))
1190  {
1191  return false;
1192  }
1193  switch (eo->numArgs())
1194  {
1195  case 0:
1196  fvInit[eo->out]=true;
1197  break;
1198  case 1:
1199  fvInit[eo->out]=!eo->flow1 || fvInit[eo->in1[0]];
1200  break;
1201  case 2:
1202  // we need to check if an associated binary operator has
1203  // an unwired input, and if so, treat its input as
1204  // initialised, since it has already been initialised in
1205  // getInputFromVar()
1206  if (auto op=eo->state)
1207  switch (op->type())
1208  {
1211  fvInit[eo->in1[0]] |= op->ports(1).lock()->wires().empty();
1212  fvInit[eo->in2[0][0].idx] |= op->ports(3).lock()->wires().empty();
1213  break;
1214  default: break;
1215  }
1216 
1217  fvInit[eo->out]=
1218  (!eo->flow1 || fvInit[eo->in1[0]]) && (!eo->flow2 || fvInit[eo->in2[0][0].idx]);
1219  break;
1220  default: break;
1221  }
1222  // if (!fvInit[eo.out])
1223  // cerr << "Operation "<<opIdOfEvalOp(eo)<<" out of order"<<endl;
1224  }
1225 
1226  return all(fvInit);
1227  }
bool inputWired(const std::string &name) const
returns true if any variable of name name has a wired input
Definition: minsky.h:399
VariableValues variableValues
Definition: minsky.h:200
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table

◆ checkMemAllocation()

virtual MemCheckResult minsky::Minsky::checkMemAllocation ( size_t  bytes) const
inlinevirtual

Definition at line 464 of file minsky.h.

464 {return OK;}

◆ checkPushHistory()

void minsky::Minsky::checkPushHistory ( )
inline

called periodically to ensure history up to date

Definition at line 365 of file minsky.h.

365 {if (historyPtr==history.size()) pushHistory();}
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265

◆ CLASSDESC_ACCESS()

minsky::Minsky::CLASSDESC_ACCESS ( Minsky  )
private

◆ classifyOp()

OperationType::Group minsky::Minsky::classifyOp ( OperationType::Type  o) const
inline

Definition at line 495 of file minsky.h.

References minsky::OperationType::classify().

495 {return OperationType::classify(o);}
static Group classify(Type t)
Here is the call graph for this function:

◆ clearAllMaps() [1/2]

void minsky::Minsky::clearAllMaps ( bool  clearHistory)

Definition at line 127 of file minsky.cc.

References variablePane().

128  {
129  model->clear();
131  equations.clear();
132  integrals.clear();
135  maxValue.clear();
136  PhillipsFlow::maxFlow.clear();
137  PhillipsStock::maxStock.clear();
139  publicationTabs.clear();
140  publicationTabs.emplace_back("Publication");
141  userFunctions.clear();
143 
144  flowVars.clear();
145  stockVars.clear();
146 
147  dimensions.clear();
148  namedItems.clear();
149  flags=reset_needed|fullEqnDisplay_needed;
151  if (doClearHistory) clearHistory();
152  }
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
VariableValues variableValues
Definition: minsky.h:200
void update()
update variables from model, using previous height value
Definition: variablePane.cc:89
std::map< Units, double > maxValue
stash the maximum absolute value obtained by a dimensioned quantity
Definition: minsky.h:204
static std::map< Units, double > maxFlow
void openGroupInCanvas(const ItemPtr &item)
reinitialises canvas to the group located in item
Definition: canvas.cc:692
static std::map< Units, double > maxStock
VariablePane variablePane
Definition: minsky.h:537
std::vector< PubTab > publicationTabs
Definition: minsky.h:156
Canvas canvas
Definition: minsky.h:256
static const std::string minskyVersion
return the AEGIS assigned version number
Definition: minsky.h:337
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
Exclude< std::map< std::string, std::shared_ptr< CallableFunction > > > userFunctions
Definition: minsky.h:253
std::map< std::string, std::weak_ptr< Item > > namedItems
Definition: minsky.h:529
PhillipsDiagram phillipsDiagram
Definition: minsky.h:155
GroupPtr model
Definition: minsky.h:255
Dimensions dimensions
Definition: minsky.h:201
std::string fileVersion
Minsky version file was saved under.
Definition: minsky.h:351
void clearHistory()
clear history
Definition: minsky.h:363
Here is the call graph for this function:

◆ clearAllMaps() [2/2]

void minsky::Minsky::clearAllMaps ( )
inline

Definition at line 259 of file minsky.h.

References clearAllMaps().

Referenced by clearAllMaps().

259 {clearAllMaps(true);}
void clearAllMaps()
Definition: minsky.h:259
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearAllMapsTCL()

void minsky::Minsky::clearAllMapsTCL ( )
inline

Definition at line 261 of file minsky.h.

261 {clearAllMaps(true);}
void clearAllMaps()
Definition: minsky.h:259

◆ clearBusyCursor()

virtual void minsky::Minsky::clearBusyCursor ( )
inlinevirtual

Reimplemented in minsky::anonymous_namespace{addon.cc}::AddOnMinsky, and minsky::MinskyTCL.

Definition at line 445 of file minsky.h.

445 {}

◆ clearHistory()

void minsky::Minsky::clearHistory ( )
inline

clear history

Definition at line 363 of file minsky.h.

363 {history.clear(); historyPtr=0;}

◆ clipboardEmpty()

bool minsky::Minsky::clipboardEmpty ( ) const
inline

return true if nothing available in clipboard

Definition at line 280 of file minsky.h.

280 {return clipboard.getClipboard().empty();}

◆ closeLogFile()

void minsky::Minsky::closeLogFile ( )
inline

closes log file

Definition at line 300 of file minsky.h.

300 {outputDataFile.reset();}

◆ commandHook()

bool minsky::Minsky::commandHook ( const std::string &  command,
unsigned  nargs 
)

Executed after each interpreter command to maintain undo/redo stack, edited flag, autosaving etc.

Parameters
command'.' separated command
nargsnumber of arguments
Returns
whether to save the command when recording events

Definition at line 1326 of file minsky.cc.

References minsky::getCommandData().

Referenced by minsky::RESTMinsky::commandHook(), and minsky::member_entry_hook().

1327  {
1328  static const set<string> constableCommands={ // commands that should not trigger the edit flag
1329  "minsky.availableOperations",
1330  "minsky.canvas.displayDelayedTooltip",
1331  "minsky.canvas.findVariableDefinition",
1332  "minsky.canvas.focusFollowsMouse",
1333  "minsky.canvas.moveTo",
1334  "minsky.canvas.model.moveTo",
1335  "minsky.canvas.model.zoom",
1336  /* we record mouse movements, but filter from history */
1337  "minsky.canvas.mouseDown",
1338  "minsky.canvas.mouseMove",
1339  "minsky.canvas.position",
1340  "minsky.canvas.recentre",
1341  "minsky.canvas.select",
1342  "minsky.canvas.selectVar",
1343  "minsky.canvas.scaleFactor",
1344  "minsky.canvas.zoom",
1345  "minsky.canvas.zoomToFit",
1346  "minsky.histogramResource.setResource",
1347  "minsky.model.moveTo",
1348  "minsky.clearAllMaps",
1349  "minsky.doPushHistory",
1350  "minsky.fontScale",
1351  "minsky.load",
1352  "minsky.model.zoom",
1353  "minsky.multipleEquities",
1354  "minsky.openGroupInCanvas",
1355  "minsky.openModelInCanvas",
1356  "minsky.popFlags",
1357  "minsky.pushFlags",
1358  "minsky.pushHistory",
1359  "minsky.redrawAllGodleyTables",
1360  "minsky.reverse",
1361  "minsky.running",
1362  "minsky.save",
1363  "minsky.select",
1364  "minsky.selectVar",
1365  "minsky.setGodleyDisplayValue",
1366  "minsky.setGodleyIconResource",
1367  "minsky.setGroupIconResource",
1368  "minsky.setLockIconResource",
1369  "minsky.setRavelIconResource",
1370  "minsky.setAutoSaveFile",
1371  "minsky.step",
1372  "minsky.undo"
1373  };
1374  if (doPushHistory && !constableCommands.contains(command) &&
1375  command.find("minsky.phillipsDiagram")==string::npos &&
1376  command.find("minsky.equationDisplay")==string::npos &&
1377  command.find("minsky.publicationTabs")==string::npos &&
1378  command.find(".renderFrame")==string::npos &&
1379  command.find(".requestRedraw")==string::npos &&
1380  command.find(".backgroundColour")==string::npos &&
1381  command.find(".get")==string::npos &&
1382  command.find(".@elem")==string::npos &&
1383  command.find(".mouseFocus")==string::npos
1384  )
1385  {
1386  auto t=getCommandData(command);
1387  if (t==generic || (t==is_setterGetter && nargs>0))
1388  {
1389  const bool modelChanged=pushHistory();
1390  if (modelChanged && command.find(".keyPress")==string::npos)
1391  {
1392  markEdited();
1393  }
1394  return modelChanged;
1395  }
1396  }
1397  return command=="minsky.canvas.requestRedraw" || command=="minsky.canvas.mouseDown" || command=="minsky.canvas.mouseMove" || command.find(".get")!=string::npos;
1398  }
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
void markEdited()
indicate model has been changed since last saved
Definition: minsky.h:173
virtual CmdData getCommandData(const std::string &command) const
return meta information on a given command
Definition: minsky.h:379
bool doPushHistory
flag to indicate whether a TCL should be pushed onto the history stack, or logged in a recording...
Definition: minsky.h:384
double t
time
Definition: rungeKutta.h:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ constructEquations()

void minsky::Minsky::constructEquations ( )

construct the equations based on input data

Exceptions
ecolab::errorif the data is inconsistent

Definition at line 393 of file minsky.cc.

References minsky::canonicalName(), f, MathDAG::SystemOfEquations::populateEvalOpVector(), minsky::timeUnit, MathDAG::SystemOfEquations::updatePortVariableValue(), and minsky::valueIdFromScope().

394  {
395  if (cycleCheck()) throw error("cyclic network detected");
396 
397  const ProgressUpdater pu(progressState,"Construct equations",8);
398  garbageCollect();
399  equations.clear();
400  integrals.clear();
401  ++progressState;
402 
403  // add all user defined functions to the global symbol tables
404  userFunctions.clear();
405  model->recursiveDo
406  (&Group::items,
407  [this](const Items&, Items::const_iterator it){
408  if (auto f=dynamic_pointer_cast<CallableFunction>(*it))
409  userFunctions[valueIdFromScope((*it)->group.lock(), canonicalName(f->name()))]=f;
410  return false;
411  });
412  ++progressState;
413  model->recursiveDo
414  (&Group::groups,
415  [this](const Groups&, Groups::const_iterator it){
416  userFunctions[valueIdFromScope((*it)->group.lock(), canonicalName((*it)->name()))]=*it;
417  return false;
418  });
419  ++progressState;
420 
422 
423  MathDAG::SystemOfEquations system(*this);
424  ++progressState;
425  assert(variableValues.validEntries());
426  system.populateEvalOpVector(equations, integrals);
427  ++progressState;
428  assert(variableValues.validEntries());
429  system.updatePortVariableValue(equations);
430  }
function f
Definition: canvas.m:1
bool validEntries() const
checks that all entry names are valid
VariableValues variableValues
Definition: minsky.h:200
std::string timeUnit
Definition: simulation.h:35
std::vector< ItemPtr > Items
Definition: item.h:366
std::vector< GroupPtr > Groups
Definition: group.h:54
void garbageCollect()
Definition: minsky.cc:375
string canonicalName(const string &name)
convert a raw name into a canonical name - this is not idempotent.
Definition: valueId.cc:63
bool cycleCheck() const
checks for presence of illegal cycles in network. Returns true if there are some
Definition: minsky.cc:1159
Groups groups
Definition: group.h:79
Exclude< std::map< std::string, std::shared_ptr< CallableFunction > > > userFunctions
Definition: minsky.h:253
string valueIdFromScope(const GroupPtr &scope, const std::string &name)
value Id from scope and canonical name name
Definition: valueId.cc:128
GroupPtr model
Definition: minsky.h:255
static std::string timeUnit
Definition: evalOp.h:54
Here is the call graph for this function:

◆ convertVarType()

void minsky::Minsky::convertVarType ( const std::string &  name,
VariableType::Type  type 
)

Converts variable(s) named by name into a variable of type type.

Exceptions
ifconversion is disallowed

Definition at line 1457 of file minsky.cc.

References TCLcmd::trap::init, minsky::isValueId(), and minsky::var.

Referenced by minsky::MinskyTCL::convertVarType(), minsky::IntOp::description(), minsky::VariableBase::retype(), and minsky::GodleyIcon::updateVars().

1458  {
1459  assert(isValueId(name));
1460  const VariableValues::iterator i=variableValues.find(name);
1461  if (i==variableValues.end())
1462  throw error("variable %s doesn't exist",name.c_str());
1463  if (i->second->type()==type) return; // nothing to do!
1464 
1465  string newName=name; // useful for checking flows and stocks with same name and renaming them as the case may be. for ticket 1272
1466  model->recursiveDo
1468  [&](const Items&,Items::const_iterator i)
1469  {
1470  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1471  {
1472  if (type!=VariableType::flow)
1473  for (auto& v: g->flowVars())
1474  if (v->valueId()==name)
1475  {
1476  newName=v->name()+"^{Flow}";
1477  const VariableValues::iterator iv=variableValues.find(newName);
1478  if (iv==variableValues.end()) {g->table.renameFlows(v->name(),newName); v->retype(VariableType::flow);}
1479  else throw error("flow variables in Godley tables cannot be converted to a different type");
1480  }
1481  if (type!=VariableType::stock)
1482  for (auto& v: g->stockVars())
1483  if (v->valueId()==name)
1484  {
1485  newName=v->name()+"^{Stock}";
1486  const VariableValues::iterator iv=variableValues.find(newName);
1487  if (iv==variableValues.end()) {g->table.renameStock(v->name(),newName); v->retype(VariableType::stock);}
1488  else throw error("stock variables in Godley tables cannot be converted to a different type");
1489  }
1490  }
1491  return false;
1492  });
1493 
1494  if (auto var=definingVar(name))
1495  // we want to be able to convert stock vars to flow vars when their input is wired. condition is only met when newName has not been changed above. for ticket 1272
1496  if (name==newName && var->type() != type && (!var->isStock() || var->controller.lock()))
1497  throw error("cannot convert a variable to a type other than its defined type");
1498 
1499  // filter out invalid targets
1500  switch (type)
1501  {
1504  throw error("convertVarType not supported for type=%s",
1505  VariableType::typeName(type).c_str());
1506  default: break;
1507  }
1508 
1509  // convert all references
1510  model->recursiveDo(&Group::items,
1511  [&](Items&, Items::iterator i) {
1512  if (auto v=VariablePtr(*i))
1513  if (v->valueId()==name)
1514  {
1515  v.retype(type);
1516  if (*i==canvas.item)
1517  canvas.item=v;
1518  *i=v;
1519  }
1520  return false;
1521  });
1522  auto init=i->second->init();
1523  i->second=VariableValuePtr(type,i->second->name);
1524  i->second->init(init);
1525  }
VariableValues variableValues
Definition: minsky.h:200
struct TCLcmd::trap::init_t init
std::vector< ItemPtr > Items
Definition: item.h:366
Canvas canvas
Definition: minsky.h:256
static std::string typeName(int t)
Definition: variableType.cc:30
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:205
bool isValueId(const string &name)
check that name is a valid valueId (useful for assertions)
Definition: valueId.cc:33
GroupPtr model
Definition: minsky.h:255
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy()

void minsky::Minsky::copy ( ) const

copy items in current selection into clipboard

Definition at line 191 of file minsky.cc.

References minsky::schemaURL, and classdesc::xml_pack().

Referenced by minsky::Canvas::select().

192  {
193  if (canvas.selection.empty())
194  clipboard.putClipboard(""); // clear clipboard
195  else
196  {
198  ostringstream os;
199  xml_pack_t packer(os, schemaURL);
200  xml_pack(packer, "Minsky", m);
201  clipboard.putClipboard(os.str());
202  }
203  }
Canvas canvas
Definition: minsky.h:256
bool empty() const
Definition: group.h:102
const char * schemaURL
Definition: saver.cc:26
void xml_pack(xml_pack_t &t, const string &d, minsky::Optional< T > &a)
Definition: optional.h:84
Selection selection
Definition: canvas.h:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cut()

void minsky::Minsky::cut ( )

erase items in current selection, put copy into clipboard

Definition at line 157 of file minsky.cc.

158  {
159  copy();
160  for (auto& i: canvas.selection.items)
161  {
162  if (auto v=i->variableCast())
163  if (v->controller.lock())
164  continue; // do not delete a variable controlled by another item
165  model->deleteItem(*i);
166  }
167  for (auto& i: canvas.selection.groups)
168  model->removeGroup(*i);
169  for (auto& i: canvas.selection.wires)
170  model->removeWire(*i);
171  canvas.item.reset();
172  canvas.itemFocus.reset();
173 #ifndef NDEBUG
174  garbageCollect();
175  for (auto& i: canvas.selection.items)
176  {
177  if (auto v=i->variableCast())
178  if (v->controller.lock())
179  continue; // variable controlled by another item is not being destroyed
180  assert(i.use_count()==1);
181  }
182  for (auto& i: canvas.selection.groups)
183  assert(i.use_count()==1);
184  for (auto& i: canvas.selection.wires)
185  assert(i.use_count()==1);
186 #endif
189  }
void copy() const
copy items in current selection into clipboard
Definition: minsky.cc:191
Canvas canvas
Definition: minsky.h:256
void garbageCollect()
Definition: minsky.cc:375
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
Groups groups
Definition: group.h:79
ItemPtr itemFocus
item selected by clicking
Definition: canvas.h:106
Selection selection
Definition: canvas.h:105
GroupPtr model
Definition: minsky.h:255
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ cycleCheck()

bool minsky::Minsky::cycleCheck ( ) const

checks for presence of illegal cycles in network. Returns true if there are some

Definition at line 1159 of file minsky.cc.

1160  {
1161  // construct the network schematic
1162  Network net;
1163  for (auto& w: model->findWires([](const WirePtr&){return true;}))
1164  net.emplace(w->from().get(), w->to().get());
1165  for (auto& i: model->findItems([](const ItemPtr&){return true;}))
1166  if (!dynamic_cast<IntOp*>(i.get()) && !dynamic_cast<GodleyIcon*>(i.get()))
1167  for (unsigned j=1; j<i->portsSize(); ++j)
1168  net.emplace(i->ports(j).lock().get(), i->ports(0).lock().get());
1169 
1170  for (auto& i: net)
1171  if (!i.first->input() && !net.portsVisited.contains(i.first))
1172  if (net.followWire(i.first))
1173  return true;
1174  return false;
1175  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
std::shared_ptr< Wire > WirePtr
Definition: wire.h:102
GroupPtr model
Definition: minsky.h:255

◆ daysUntilRavelExpires()

static int minsky::Minsky::daysUntilRavelExpires ( )
inlinestatic

Definition at line 349 of file minsky.h.

349 {return ravel::Ravel::daysUntilExpired();}

◆ defaultFont() [1/2]

string minsky::Minsky::defaultFont ( )

the default used by Pango

Definition at line 1738 of file minsky.cc.

References minsky::_defaultFont.

1739  {return _defaultFont? _defaultFont.get(): "";}
static std::unique_ptr< char[]> _defaultFont
Definition: minsky.cc:1736

◆ defaultFont() [2/2]

string minsky::Minsky::defaultFont ( const std::string &  x)

the default used by Pango

Definition at line 1741 of file minsky.cc.

References minsky::_defaultFont.

1742  {
1743  _defaultFont.reset(new char[x.length()+1]);
1744  strncpy(_defaultFont.get(),x.c_str(),x.length()+1);
1745  ecolab::Pango::defaultFamily=_defaultFont.get();
1746  return x;
1747  }
static std::unique_ptr< char[]> _defaultFont
Definition: minsky.cc:1736

◆ definingVar()

VariablePtr minsky::Minsky::definingVar ( const std::string &  valueId) const

returns reference to variable defining (ie input wired) for valueId

Definition at line 205 of file minsky.cc.

References minsky::valueId().

Referenced by minsky::VariableValue::hypercube(), minsky::VariableValue::init(), minsky::Canvas::renameItem(), minsky::VariableValues::resetValue(), minsky::VariableBase::sliderVisible(), and minsky::GodleyIcon::update().

206  {
207  return dynamic_pointer_cast<VariableBase>
208  (model->findAny(&Group::items, [&](const ItemPtr& x) {
209  auto v=x->variableCast();
210  return v && v->valueId()==valueId && v->defined();
211  }));
212  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteAllUnits()

void minsky::Minsky::deleteAllUnits ( )

removes units markup from all variables in model

Definition at line 460 of file minsky.cc.

References minsky::timeUnit.

461  {
462  for (auto& i: variableValues)
463  i.second->units.clear();
464  timeUnit.clear();
465  }
VariableValues variableValues
Definition: minsky.h:200
std::string timeUnit
Definition: simulation.h:35

◆ deltaT()

double minsky::Minsky::deltaT ( ) const
inline

Definition at line 321 of file minsky.h.

321 {return t-lastT;}
double lastT
previous timestep
Definition: minsky.h:320
double t
time
Definition: rungeKutta.h:57

◆ diagnoseNonFinite()

string minsky::Minsky::diagnoseNonFinite ( ) const
private

returns a diagnostic about an item that is infinite or NaN. Either a variable name, or and operator type.

Definition at line 999 of file minsky.cc.

References minsky::anonymous_namespace{userFunction.cc}::isfinite().

1000  {
1001  // firstly check if any variables are not finite
1002  for (VariableValues::const_iterator v=variableValues.begin();
1003  v!=variableValues.end(); ++v)
1004  if (!isfinite(v->second->value()))
1005  return v->first;
1006 
1007  // now check operator equations
1008  for (EvalOpVector::const_iterator e=equations.begin(); e!=equations.end(); ++e)
1009  if (!isfinite(flowVars[(*e)->out]))
1010  return OperationType::typeName((*e)->type());
1011  return "";
1012  }
VariableValues variableValues
Definition: minsky.h:200
static std::string typeName(int type)
return the symbolic name of type
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
Here is the call graph for this function:

◆ dimensionalAnalysis()

void minsky::Minsky::dimensionalAnalysis ( ) const

performs dimension analysis, throws if there is a problem

Definition at line 432 of file minsky.cc.

433  {
434  const_cast<Minsky*>(this)->variableValues.resetUnitsCache();
435  // increment varsPassed by one to prevent resettting the cache on each check
436  const IncrDecrCounter vpIdc(VariableBase::varsPassed);
437  model->recursiveDo
438  (&Group::items,
439  [&](Items& m, Items::iterator i)
440  {
441  if (auto v=(*i)->variableCast())
442  {
443  // check only the defining variables
444  if (v->isStock() && (v->inputWired() || v->controller.lock().get()))
445  v->checkUnits();
446  }
447  else if ((*i)->portsSize()>0 && !(*i)->ports(0).lock()->input() &&
448  (*i)->ports(0).lock()->wires().empty())
449  (*i)->checkUnits(); // check anything with an unwired output port
450  else if (auto p=(*i)->plotWidgetCast())
451  for (size_t j=0; j<p->portsSize(); ++j)
452  p->ports(j).lock()->checkUnits();
453  else if (auto p=dynamic_cast<Sheet*>(i->get()))
454  for (size_t j=0; j<p->portsSize(); ++j)
455  p->ports(j).lock()->checkUnits();
456  return false;
457  });
458  }
VariableValues variableValues
Definition: minsky.h:200
std::vector< ItemPtr > Items
Definition: item.h:366
static int varsPassed
for caching units calculation factory method
Definition: variable.h:116
GroupPtr model
Definition: minsky.h:255

◆ displayErrorItem()

void minsky::Minsky::displayErrorItem ( const Item op) const

indicate operation item has error, if visible, otherwise contining group

Definition at line 1230 of file minsky.cc.

References minsky::Canvas::itemIndicator, pyminsky::minsky, minsky::op, and resetScroll().

Referenced by MathDAG::OperationDAGBase::addEvalOps(), minsky::TensorOpFactory::create(), minsky::RungeKutta::evalEquations(), minsky::anonymous_namespace{minsky.cc}::Network::followWire(), MathDAG::SystemOfEquations::makeDAG(), MathDAG::anonymous_namespace{equations.cc}::NoArgument::NoArgument(), and minsky::Item::throw_error().

1231  {
1232  // this method is logically const, but because of the way
1233  // canvas rendering is done, canvas state needs updating
1234  auto& canvas=const_cast<Canvas&>(this->canvas);
1235  if (op.visible())
1236  canvas.itemIndicator=canvas.model->findItem(op);
1237  else if (auto v=op.variableCast())
1238  if (auto c=v->controller.lock())
1239  displayErrorItem(*c);
1240 
1241  if (!canvas.itemIndicator)
1242  if (auto g=op.group.lock())
1243  {
1244  while (g && !g->visible()) g=g->group.lock();
1245  if (g && g->visible())
1247  }
1248 
1249  if (canvas.itemIndicator)
1250  {
1251  auto physX=canvas.itemIndicator->x();
1252  auto physY=canvas.itemIndicator->y();
1253  if (physX<100 || physX>canvas.frameArgs().childWidth-100 ||
1254  physY<100 || physY>canvas.frameArgs().childHeight-100)
1255  {
1256  canvas.model->moveTo(0.5*canvas.frameArgs().childWidth-physX+canvas.model->x(),
1257  0.5*canvas.frameArgs().childHeight-physY+canvas.model->y());
1258  minsky().resetScroll();
1259  }
1260  }
1261  //requestRedraw calls back into TCL, so don't call it from the simulation thread. See ticket #973
1262  if (!RKThreadRunning) canvas.requestRedraw();
1263  }
const RenderFrameArgs & frameArgs() const
void displayErrorItem(const Item &op) const
indicate operation item has error, if visible, otherwise contining group
Definition: minsky.cc:1230
Model model
Definition: canvas.h:103
ItemPtr itemIndicator
for drawing error indicator on the canvas
Definition: canvas.h:120
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
virtual void resetScroll()
reset main window scroll bars after model has been panned
Definition: minsky.h:453
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecolabVersion()

std::string minsky::Minsky::ecolabVersion ( ) const
inline

Definition at line 338 of file minsky.h.

338 {return VERSION;}

◆ edited()

bool minsky::Minsky::edited ( ) const
inline

reflects whether the model has been changed since last save

Definition at line 169 of file minsky.h.

169 {return flags & is_edited;}

◆ exportAllPlotsAsCSV()

void minsky::Minsky::exportAllPlotsAsCSV ( const string &  prefix) const

export all plots

Definition at line 1563 of file minsky.cc.

References minsky::str().

1564  {
1565  unsigned plotNum=0;
1566  model->recursiveDo(&Group::items,
1567  [&](Items&, Items::iterator i) {
1568  if (auto p=(*i)->plotWidgetCast())
1569  {
1570  if (!p->title.empty())
1571  p->exportAsCSV((prefix+"-"+p->title+".csv"));
1572  else
1573  p->exportAsCSV((prefix+"-"+str(plotNum++)+".csv"));
1574  }
1575  return false;
1576  });
1577  }
std::vector< ItemPtr > Items
Definition: item.h:366
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:

◆ exportSchema()

void minsky::Minsky::exportSchema ( const std::string &  filename,
int  schemaLevel = 1 
)

Definition at line 1106 of file minsky.cc.

References f, minsky::schemaURL, and classdesc::xsd_generate().

1107  {
1108  xsd_generate_t x;
1109  switch (schemaLevel)
1110  {
1111  case 0:
1112  xsd_generate(x,"Minsky",schema0::Minsky());
1113  break;
1114  case 1:
1115  xsd_generate(x,"Minsky",schema1::Minsky());
1116  break;
1117  case 2:
1118  xsd_generate(x,"Minsky",schema2::Minsky());
1119  break;
1120  case 3:
1121  xsd_generate(x,"Minsky",schema3::Minsky());
1122  break;
1123  }
1124  ofstream f(filename);
1125  x.output(f,schemaURL);
1126  }
function f
Definition: canvas.m:1
void xsd_generate(xsd_generate_t &g, const string &d, const minsky::Optional< T > &a)
Definition: optional.h:77
const char * schemaURL
Definition: saver.cc:26
Here is the call graph for this function:

◆ fontScale() [1/2]

double minsky::Minsky::fontScale ( )

an extra scaling factor of Pango fonts

Definition at line 1749 of file minsky.cc.

1750  {return ecolab::Pango::scaleFactor;}

◆ fontScale() [2/2]

double minsky::Minsky::fontScale ( double  s)

an extra scaling factor of Pango fonts

Definition at line 1752 of file minsky.cc.

1753  {return ecolab::Pango::scaleFactor=s;}

◆ garbageCollect()

void minsky::Minsky::garbageCollect ( )

Definition at line 375 of file minsky.cc.

376  {
378  stockVars.clear();
379  flowVars.clear();
380  equations.clear();
381  integrals.clear();
382 
383  // remove all temporaries
384  for (auto v=variableValues.begin(); v!=variableValues.end();)
385  if (v->second->temp())
386  variableValues.erase(v++);
387  else
388  ++v;
389 
391  }
void makeVariablesConsistent()
Definition: minsky.cc:338
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
VariableValues variableValues
Definition: minsky.h:200
void reset()
reset all variableValues to their initial conditions
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table

◆ getc()

char minsky::Minsky::getc ( ) const
inline

Used to implement a pause until return pressed for attaching debugger purposes.

Definition at line 540 of file minsky.h.

540 {return std::getc(stdin);}

◆ getCommandData()

virtual CmdData minsky::Minsky::getCommandData ( const std::string &  command) const
inlinevirtual

return meta information on a given command

Reimplemented in minsky::MinskyTCL, and minsky::RESTMinsky.

Definition at line 379 of file minsky.h.

379 {return generic;}

◆ importDuplicateColumn()

void minsky::Minsky::importDuplicateColumn ( GodleyTable srcTable,
int  srcCol 
)

find any duplicate column, and use it as a source column for balanceDuplicateColumns

Definition at line 618 of file minsky.cc.

References minsky::GodleyTable::cell(), minsky::GodleyTable::cols(), and minsky::trimWS().

Referenced by minsky::GodleyTableEditor::importStockVarByCol(), minsky::GodleyIcon::setCell(), and minsky::GodleyTableEditor::update().

619  {
620  if (srcCol<0 || size_t(srcCol)>=srcTable.cols()) return;
621  // find any duplicate column, and use it to do balanceDuplicateColumns
622  const string& colName=trimWS(srcTable.cell(0,srcCol));
623  if (colName.empty()) return; //ignore blank columns
624 
625  try
626  {
627  model->recursiveDo
628  (&Group::items,
629  [&](Items& m, Items::iterator i)
630  {
631  if (auto gi=dynamic_cast<GodleyIcon*>(i->get()))
632  for (size_t col=1; col<gi->table.cols(); col++)
633  if ((&gi->table!=&srcTable || int(col)!=srcCol) && trimWS(gi->table.cell(0,col))==colName) // we have a match
634  balanceDuplicateColumns(*gi, col);
635  return false;
636  });
637  }
638  catch (...) // in the event of business rules being violated, delete column name
639  {
640  srcTable.cell(0,srcCol).clear();
641  throw;
642  }
643  }
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:753
std::vector< ItemPtr > Items
Definition: item.h:366
std::string trimWS(const std::string &s)
Definition: str.h:49
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:
Here is the caller graph for this function:

◆ importVensim()

void minsky::Minsky::importVensim ( const std::string &  filename)

import a Vensim file

Definition at line 1599 of file minsky.cc.

References f, and minsky::readMdl().

1600  {
1601  ifstream f(filename);
1602  readMdl(*model,*this,f);
1604  }
function f
Definition: canvas.m:1
void readMdl(Group &group, Simulation &simParms, istream &mdlFile)
import a Vensim mdl file into group, also populating simParms from the control block ...
Definition: mdlReader.cc:250
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:

◆ imposeDimensions()

void minsky::Minsky::imposeDimensions ( )

Definition at line 365 of file minsky.cc.

Referenced by minsky::Ravel::setDimension().

366  {
367  for (auto& v: variableValues)
368  {
369  v.second->imposeDimensions(dimensions);
370  v.second->tensorInit.imposeDimensions(dimensions);
371  }
372  }
VariableValues variableValues
Definition: minsky.h:200
Dimensions dimensions
Definition: minsky.h:201
Here is the caller graph for this function:

◆ initGodleys()

void minsky::Minsky::initGodleys ( )

Definition at line 857 of file minsky.cc.

858  {
859  auto toGodleyIcon=[](const ItemPtr& i) {return dynamic_cast<GodleyIcon*>(i.get());};
860  auto godleyItems=model->findAll<GodleyIcon*>
861  (toGodleyIcon, &GroupItems::items, toGodleyIcon);
862  evalGodley.initialiseGodleys(GodleyIt(godleyItems.begin()),
863  GodleyIt(godleyItems.end()), variableValues);
864  }
EvalGodley evalGodley
Definition: rungeKutta.h:60
VariableValues variableValues
Definition: minsky.h:200
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
void initialiseGodleys(const GodleyIterator &begin, const GodleyIterator &end, const VariableValues &values)
initialise this to a sequence of Godley tables - adaptors provided below
Definition: evalGodley.h:121
GroupPtr model
Definition: minsky.h:255

◆ inputWired()

bool minsky::Minsky::inputWired ( const std::string &  name) const
inline

returns true if any variable of name name has a wired input

Definition at line 399 of file minsky.h.

Referenced by minsky::GroupItems::addWire().

399 {return definingVar(name).get();}
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:205
Here is the caller graph for this function:

◆ insertGroupFromFile()

void minsky::Minsky::insertGroupFromFile ( const string &  file)

Definition at line 323 of file minsky.cc.

References schema3::Minsky::populateGroup(), and minsky::stripByteOrderingMarker().

324  {
325  ifstream inf(file);
326  if (!inf)
327  throw runtime_error(string("failed to open ")+file);
329  xml_unpack_t saveFile(inf);
330  const schema3::Minsky currentSchema(saveFile);
331 
332  const GroupPtr g(new Group);
333  currentSchema.populateGroup(*model->addGroup(g));
334  g->resizeOnContents();
335  canvas.itemFocus=g;
336  }
Canvas canvas
Definition: minsky.h:256
ItemPtr itemFocus
item selected by clicking
Definition: canvas.h:106
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
GroupPtr model
Definition: minsky.h:255
void stripByteOrderingMarker(std::istream &s)
checks if the input stream has the UTF-8 byte ordering marker, and removes it if present ...
Definition: str.h:147
Here is the call graph for this function:

◆ itemFromNamedItem()

void minsky::Minsky::itemFromNamedItem ( const std::string &  name)
inline

Definition at line 531 of file minsky.h.

531 {canvas.item=namedItems[name].lock();}
Canvas canvas
Definition: minsky.h:256
std::map< std::string, std::weak_ptr< Item > > namedItems
Definition: minsky.h:529
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ latex()

void minsky::Minsky::latex ( const std::string &  filename,
bool  wrapLaTeXLines 
)

Definition at line 1755 of file minsky.cc.

References f, MathDAG::SystemOfEquations::latex(), and MathDAG::SystemOfEquations::latexWrapped().

1756  {
1757  if (cycleCheck()) throw error("cyclic network detected");
1758  ofstream f(filename);
1759 
1760  f<<"\\documentclass{article}\n";
1761  if (wrapLaTeXLines)
1762  {
1763  f<<"\\usepackage{breqn}\n\\begin{document}\n";
1765  }
1766  else
1767  {
1768  f<<"\\begin{document}\n";
1770  }
1771  f<<"\\end{document}\n";
1772  }
function f
Definition: canvas.m:1
ostream & latexWrapped(ostream &) const
Definition: equations.cc:933
bool cycleCheck() const
checks for presence of illegal cycles in network. Returns true if there are some
Definition: minsky.cc:1159
ostream & latex(ostream &) const
render as a LaTeX eqnarray Use LaTeX brqn environment to wrap long lines
Definition: equations.cc:902
Here is the call graph for this function:

◆ latex2pango()

string minsky::Minsky::latex2pango ( const std::string &  x)
inline

Definition at line 506 of file minsky.h.

References minsky::latexToPango().

506 {return latexToPango(x.c_str());}
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
Here is the call graph for this function:

◆ listAllInstances()

void minsky::Minsky::listAllInstances ( )

Definition at line 1637 of file minsky.cc.

1638  {
1639  if (canvas.item)
1640  if (auto v=canvas.item->variableCast())
1641  {
1642  variableInstanceList=std::make_shared<VariableInstanceList>(*canvas.model, v->valueId());
1643  return;
1644  }
1645  variableInstanceList.reset();
1646  }
Model model
Definition: canvas.h:103
Canvas canvas
Definition: minsky.h:256
std::shared_ptr< VariableInstanceList > variableInstanceList
supports navigation to all instances of current variable
Definition: minsky.h:526
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ listFonts()

vector<string> minsky::Minsky::listFonts ( ) const
inline

Definition at line 469 of file minsky.h.

469  {
470  vector<string> r;
471 #ifdef PANGO
472  PangoFontFamily **families;
473  int num;
474  pango_font_map_list_families(pango_cairo_font_map_get_default(),
475  &families,&num);
476  for (int i=0; i<num; ++i)
477  r.push_back(pango_font_family_get_name(families[i]));
478  g_free(families);
479  std::sort(r.begin(),r.end());
480 #endif
481  return r;
482  }

◆ load()

void minsky::Minsky::load ( const std::string &  filename)

load from a file

Definition at line 1048 of file minsky.cc.

References schema3::Minsky::populateMinsky(), reset(), schema3::Minsky::schemaVersion, minsky::stripByteOrderingMarker(), and schema3::Minsky::version.

Referenced by minsky::MinskyTCL::load().

1049  {
1050  running=false;
1051  clearAllMaps(true);
1052 
1053  ifstream inf(filename);
1054  if (!inf)
1055  throw runtime_error("failed to open "+filename);
1057 
1058  {
1059  const BusyCursor busy(*this);
1060  xml_unpack_t saveFile(inf);
1061  const schema3::Minsky currentSchema(saveFile);
1062  currentSchema.populateMinsky(*this);
1063  if (currentSchema.schemaVersion<currentSchema.version)
1064  message("You are converting the model from an older version of Minsky. "
1065  "Once you save this file, you may not be able to open this file"
1066  " in older versions of Minsky.");
1067  }
1068 
1069  const LocalMinsky lm(*this); // populateMinsky resets the local minsky pointer, so restore it here
1070  flags=fullEqnDisplay_needed;
1071 
1072  // try balancing all Godley tables
1073  try
1074  {
1075  model->recursiveDo(&Group::items,
1076  [this](Items&,Items::iterator i) {
1077  try
1078  {
1079  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1080  {
1081  for (unsigned j=1; j<g->table.cols(); ++j)
1083  }
1084  (*i)->adjustBookmark();
1085  }
1086  catch (...) {}
1087  return false;
1088  });
1089 
1090  // try resetting the system, but ignore any errors
1091  reset();
1093  }
1094  catch (...) {flags|=reset_needed;}
1096  canvas.moveTo(0,0); // force placement of ports
1097  // sometimes we need to recalculate the bounding boxes
1098  model->recursiveDo(&Group::items,
1099  [](Items&,Items::iterator i) {
1100  (*i)->updateBoundingBox();
1101  return false;
1102  });
1103  pushHistory();
1104  }
virtual void message(const std::string &)
display a message in a popup box on the GUI
Definition: minsky.h:456
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:753
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
void reset()
resets the variables back to their initial values
Definition: minsky.cc:866
void populateMissingDimensions()
fills in dimensions table with all loaded ravel axes
Definition: minsky.cc:497
std::vector< ItemPtr > Items
Definition: item.h:366
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
void moveTo(float x, float y) override
move this so that (x,y) is centred
Definition: canvas.h:129
void clearAllMaps()
Definition: minsky.h:259
GroupPtr model
Definition: minsky.h:255
void stripByteOrderingMarker(std::istream &s)
checks if the input stream has the UTF-8 byte ordering marker, and removes it if present ...
Definition: str.h:147
bool running
controls whether simulation is running
Definition: rungeKutta.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loggingEnabled()

bool minsky::Minsky::loggingEnabled ( ) const
inline

returns true if logging is in operation

Definition at line 304 of file minsky.h.

304 {return outputDataFile.get();}

◆ logVariables()

void minsky::Minsky::logVariables ( ) const
private

write current state of all variables to the log file

Definition at line 108 of file minsky.cc.

109  {
110  if (outputDataFile)
111  {
112  *outputDataFile<<t;
113  for (auto& v: variableValues)
114  if (logVarList.contains(v.first))
115  *outputDataFile<<" "<<v.second->value();
116  *outputDataFile<<endl;
117  }
118  }
std::set< string > logVarList
set of variables (valueIds) to log
Definition: minsky.h:302
VariableValues variableValues
Definition: minsky.h:200
double t
time
Definition: rungeKutta.h:57

◆ makeVariablesConsistent()

void minsky::Minsky::makeVariablesConsistent ( )

Definition at line 338 of file minsky.cc.

339  {
340  // remove variableValues not in variables
341  set<string> existingNames;
342  existingNames.insert("constant:zero");
343  existingNames.insert("constant:one");
344  vector<GodleyIcon*> godleysToUpdate;
345  model->recursiveDo(&Group::items,
346  [&](Items&,Items::iterator i) {
347  if (auto v=(*i)->variableCast())
348  existingNames.insert(v->valueId());
349  // ensure Godley table variables are the correct types
350  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
351  godleysToUpdate.push_back(g);
352  return false;
353  }
354  );
355 
356  for (auto g: godleysToUpdate) g->update();
357  for (auto i=variableValues.begin(); i!=variableValues.end(); )
358  if (existingNames.contains(i->first))
359  ++i;
360  else
361  variableValues.erase(i++);
362 
363  }
VariableValues variableValues
Definition: minsky.h:200
std::vector< ItemPtr > Items
Definition: item.h:366
GroupPtr model
Definition: minsky.h:255

◆ markEdited()

void minsky::Minsky::markEdited ( )
inline

indicate model has been changed since last saved

Definition at line 173 of file minsky.h.

References variablePane().

Referenced by minsky::Canvas::keyPress(), and minsky::GodleyTable::markEdited().

173  {
174  flags |= is_edited | fullEqnDisplay_needed;
175  if (!running) flags|=reset_needed; // don't reset when running
179  }
void update()
update variables from model, using previous height value
Definition: variablePane.cc:89
Model model
Definition: canvas.h:103
VariablePane variablePane
Definition: minsky.h:537
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
bool running
controls whether simulation is running
Definition: rungeKutta.h:58
void updateTimestamp()
Definition: canvas.h:72
Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchingTableColumns()

std::set< string > minsky::Minsky::matchingTableColumns ( const GodleyIcon currTable,
GodleyAssetClass::AssetClass  ac 
)
Returns
available matching columns from other Godley tables
Parameters
currTable- this table, not included in the matching process

Definition at line 567 of file minsky.cc.

References minsky::godley, and minsky::scope().

Referenced by minsky::MinskyTCL::matchingTableColumns(), and minsky::GodleyTableEditor::matchingTableColumnsByCol().

568  {
569  std::set<string> r;
571  // matching liability with assets and vice-versa
572  switch (ac)
573  {
576  target_ac=GodleyAssetClass::asset;
577  break;
579  target_ac=GodleyAssetClass::liability;
580  break;
581  default:
582  return r; // other types do not match anything
583  }
584 
585  std::set<string> duplicatedColumns;
586  model->recursiveDo
587  (&Group::items,
588  [&](Items& m, Items::iterator it)
589  {
590  if (auto gi=dynamic_cast<GodleyIcon*>(it->get()))
591  {
592  for (size_t i=1; i<gi->table.cols(); ++i)
593  if (!gi->table.cell(0,i).empty())
594  {
595  auto v=gi->table.cell(0,i);
596  auto scope=minsky::scope(gi->group.lock(),v);
597  if (scope->higher(*godley.group.lock()))
598  v=':'+v; //NOLINT
599  else if (scope!=godley.group.lock())
600  continue; // variable is inaccessible
601  if (r.contains(v) || gi->table._assetClass(i)!=target_ac)
602  {
603  r.erase(v); // column already duplicated, or in current, nothing to match
604  duplicatedColumns.insert(v);
605  }
606  else if (!duplicatedColumns.contains(v) && gi->table._assetClass(i)==target_ac &&
607  // insert unmatched asset columns from this table only for equity (feature #174)
608  // otherwise matches are between separate tables
609  ((ac!=GodleyAssetClass::equity && gi!=&godley) || (ac==GodleyAssetClass::equity && gi==&godley) ))
610  r.insert(v);
611  }
612  }
613  return false;
614  });
615  return r;
616  }
size_t scope(const string &name)
extract scope from a qualified variable name
Definition: valueId.cc:83
std::vector< ItemPtr > Items
Definition: item.h:366
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:
Here is the caller graph for this function:

◆ matlab()

void minsky::Minsky::matlab ( const std::string &  filename)
inline

Definition at line 499 of file minsky.h.

References f, and MathDAG::SystemOfEquations::matlab().

499  {
500  if (cycleCheck()) throw error("cyclic network detected");
501  ofstream f(filename);
503  }
function f
Definition: canvas.m:1
ostream & matlab(ostream &) const
render as MatLab code create equations suitable for Runge-Kutta solver
Definition: equations.cc:963
bool cycleCheck() const
checks for presence of illegal cycles in network. Returns true if there are some
Definition: minsky.cc:1159
Here is the call graph for this function:

◆ message()

virtual void minsky::Minsky::message ( const std::string &  )
inlinevirtual

display a message in a popup box on the GUI

Reimplemented in minsky::anonymous_namespace{addon.cc}::AddOnMinsky, and minsky::MinskyTCL.

Definition at line 456 of file minsky.h.

456 {}

◆ multipleEquities() [1/2]

bool minsky::Minsky::multipleEquities ( ) const
inline

Definition at line 165 of file minsky.h.

165 {return m_multipleEquities;}
bool m_multipleEquities
Definition: minsky.h:144

◆ multipleEquities() [2/2]

bool minsky::Minsky::multipleEquities ( const bool &  m)

Definition at line 90 of file minsky.cc.

90  {
94  return m_multipleEquities;
95  }
void redrawAllGodleyTables()
request all Godley table windows to redraw
Definition: minsky.cc:1703
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
bool m_multipleEquities
Definition: minsky.h:144

◆ nameCurrentItem()

void minsky::Minsky::nameCurrentItem ( const std::string &  name)
inline

Definition at line 530 of file minsky.h.

530 {namedItems[name]=canvas.item;}
Canvas canvas
Definition: minsky.h:256
std::map< std::string, std::weak_ptr< Item > > namedItems
Definition: minsky.h:529
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ numOpArgs()

int minsky::Minsky::numOpArgs ( OperationType::Type  o)

Definition at line 1774 of file minsky.cc.

References minsky::op.

1775  {
1776  const OperationPtr op(o);
1777  return op->numPorts()-1;
1778  }

◆ openGroupInCanvas()

void minsky::Minsky::openGroupInCanvas ( )
inline

Definition at line 521 of file minsky.h.

void openGroupInCanvas(const ItemPtr &item)
reinitialises canvas to the group located in item
Definition: canvas.cc:692
Canvas canvas
Definition: minsky.h:256
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ openLogFile()

void minsky::Minsky::openLogFile ( const string &  name)

opens the log file, and writes out a header line describing names of all variables

Definition at line 97 of file minsky.cc.

References minsky::CSVQuote().

98  {
99  outputDataFile.reset(new ofstream(name));
100  *outputDataFile<< "#time";
101  for (auto& v: variableValues)
102  if (logVarList.contains(v.first))
103  *outputDataFile<<" "<<CSVQuote(v.second->name,' ');
104  *outputDataFile<<endl;
105  }
std::set< string > logVarList
set of variables (valueIds) to log
Definition: minsky.h:302
VariableValues variableValues
Definition: minsky.h:200
std::string CSVQuote(const std::string &x, char sep)
quotes a string if it contains a separator character, and double quotes quotes
Definition: str.h:162
Here is the call graph for this function:

◆ openModelInCanvas()

void minsky::Minsky::openModelInCanvas ( )
inline

reinitialises canvas to the toplevel group

Definition at line 523 of file minsky.h.

void openGroupInCanvas(const ItemPtr &item)
reinitialises canvas to the group located in item
Definition: canvas.cc:692
Canvas canvas
Definition: minsky.h:256
GroupPtr model
Definition: minsky.h:255

◆ paste()

void minsky::Minsky::paste ( )

paste clipboard as a new group or ungrouped items on the canvas. canvas.itemFocus is set to refer to the new group or items.

Definition at line 220 of file minsky.cc.

References schema3::Minsky::populateGroup(), and minsky::valueId().

222  {
223  // don't paste if previous created item hasn't been placed yet.
224  if (canvas.itemFocus) return;
225  map<string,string> existingParms;
226  // preserve initial conditions.
227  for (auto& [valueId,vv]: variableValues)
228  existingParms.emplace(valueId,vv->init());
229 
230  istringstream is(clipboard.getClipboard());
231  xml_unpack_t unpacker(is);
232  schema3::Minsky m(unpacker);
233  GroupPtr g(new Group);
234  g->self=g;
235  m.populateGroup(*g);
236 
237  // stash values of parameters in the copied group, for ticket 1258
238  for (auto& i: g->items)
239  if (auto v=i->variableCast(); v && v->type()==VariableType::parameter)
240  existingParms.emplace(v->valueId(),v->init());
241 
242  // Default pasting no longer occurs as grouped items or as a group within a group. Fix for tickets 1080/1098
244  // The following is only necessary if one pastes into an existing model. For ticket 1258
245  if (!history.empty() || !canvas.model.get()->empty()) {
246  bool alreadyDefinedMessageDisplayed=false;
247 
248  // convert stock variables that aren't defined to flow variables, and other fix up multiply defined vars
249  g->recursiveDo(&GroupItems::items,
250  [&](Items&, Items::iterator i) {
251  if (auto v=(*i)->variableCast())
252  if (v->defined() || v->isStock())
253  {
254  // if defined, check no other defining variable exists
255  auto alreadyDefined = canvas.model->findAny
257  [&v](const ItemPtr& j)
258  {return j.get()!=v && j->variableCast() && j->variableCast()->defined();});
259  if (v->isStock())
260  {
261  if (v->defined() && alreadyDefined && !alreadyDefinedMessageDisplayed)
262  {
263  message("Integral/Stock variable "+v->name()+" already defined.");
264  alreadyDefinedMessageDisplayed=true;
265  }
266  else if (!v->defined() && !alreadyDefined)
267  {
268  // need to do this var explicitly, as not currently part of model structure
269  if (auto vp=VariablePtr(*i))
270  {
271  vp.retype(VariableType::flow);
272  *i=vp;
273  convertVarType(vp->valueId(), VariableType::flow);
274  }
275  }
276  }
277  else if (alreadyDefined)
278  {
279  // delete defining wire from this
280  assert(v->portsSize()>1 && !v->ports(1).lock()->wires().empty());
281  g->removeWire(*v->ports(1).lock()->wires()[0]);
282  }
283  }
284  return false;
285  });
286  }
287 
288  canvas.model->addGroup(g); // needed to ensure wires are correctly handled
289  auto copyOfItems=g->items;
290  auto copyOfGroups=g->groups;
291 
292  // ungroup g, putting all its contents on the canvas
293  canvas.model->moveContents(*g);
294 
295  // leave newly ungrouped items in selection
296  for (auto& i: copyOfItems)
298 
299  // ensure that initial values of pasted parameters are correct. for ticket 1258
300  for (auto& p: existingParms)
301  if (auto vv=variableValues.find(p.first); vv!=variableValues.end())
302  vv->second->init(p.second);
303  existingParms.clear();
304 
305  // Attach mouse focus only to first visible item in selection. For ticket 1098.
306  for (auto& i: canvas.selection.items)
307  if (i->visible())
308  {
309  canvas.setItemFocus(i);
310  break;
311  }
312 
313  if (!copyOfGroups.empty()) canvas.setItemFocus(copyOfGroups[0]);
314 
315  canvas.model->removeGroup(*g);
317  }
318  catch (...)
319  {
320  throw runtime_error("clipboard data invalid");
321  }
virtual void message(const std::string &)
display a message in a popup box on the GUI
Definition: minsky.h:456
VariableValues variableValues
Definition: minsky.h:200
void setItemFocus(const ItemPtr &x)
sets itemFocus, and resets mouse offset for placement
Definition: canvas.h:167
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
Model model
Definition: canvas.h:103
std::vector< ItemPtr > Items
Definition: item.h:366
Canvas canvas
Definition: minsky.h:256
void ensureItemInserted(const ItemPtr &item)
check if item already present, and if not, inserts item delegates to ensureGroupInserted if passed a ...
Definition: selection.cc:60
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
ItemPtr itemFocus
item selected by clicking
Definition: canvas.h:106
Selection selection
Definition: canvas.h:105
std::shared_ptr< Group > GroupPtr
Definition: port.h:32
void convertVarType(const std::string &name, VariableType::Type type)
Converts variable(s) named by name into a variable of type type.
Definition: minsky.cc:1457
Here is the call graph for this function:

◆ physicalMem()

size_t minsky::Minsky::physicalMem ( ) const

returns amount of memory installed on system

Definition at line 1713 of file minsky.cc.

Referenced by minsky::MinskyTCL::checkMemAllocation().

1714  {
1715 #if defined(__linux__)
1716  struct sysinfo s;
1717  sysinfo(&s);
1718  return s.totalram;
1719 #elif defined(WIN32)
1720  MEMORYSTATUSEX s{sizeof(MEMORYSTATUSEX)};
1721  GlobalMemoryStatusEx(&s);
1722  return s.ullTotalPhys;
1723 #elif defined(__APPLE__)
1724  int mib[]={CTL_HW,HW_MEMSIZE};
1725  uint64_t physical_memory;
1726  size_t length = sizeof(uint64_t);
1727  if (sysctl(mib, sizeof(mib)/sizeof(int), &physical_memory, &length, NULL, 0))
1728  perror("physicalMem:");
1729  return physical_memory;
1730 #else
1731  // all else fails, return max value
1732  return ~0UL;
1733 #endif
1734  }
Here is the caller graph for this function:

◆ popFlags()

void minsky::Minsky::popFlags ( )
inline

push and pop state of the flags

Definition at line 186 of file minsky.h.

186  {
187  if (!flagStack.empty()) {
188  flags=flagStack.back();
189  flagStack.pop_back();
190  }
191  }

◆ populateMissingDimensions()

void minsky::Minsky::populateMissingDimensions ( )

fills in dimensions table with all loaded ravel axes

Definition at line 497 of file minsky.cc.

497  {
498  // populate from variable value table first, then override by ravels
499  bool incompatibleMessageDisplayed=false;
500  for (auto& v: variableValues)
501  populateMissingDimensionsFromVariable(*v.second, incompatibleMessageDisplayed);
502  model->recursiveDo
503  (&Group::items,[&](Items& m, Items::iterator it)
504  {
505  if (auto ri=dynamic_cast<Ravel*>(it->get()))
506  {
507  auto state=ri->getState();
508  for (auto& j: state.handleStates)
509  dimensions.emplace(j.description,Dimension());
510  }
511  return false;
512  });
513  requestReset();
514  }
void requestReset()
Definition: minsky.cc:467
VariableValues variableValues
Definition: minsky.h:200
std::vector< ItemPtr > Items
Definition: item.h:366
void populateMissingDimensionsFromVariable(const VariableValue &, bool &incompatibleMessageDisplayed)
populate missing dimensions from a variableValue
Definition: minsky.cc:516
GroupPtr model
Definition: minsky.h:255
Dimensions dimensions
Definition: minsky.h:201

◆ populateMissingDimensionsFromVariable() [1/2]

void minsky::Minsky::populateMissingDimensionsFromVariable ( const VariableValue v,
bool &  incompatibleMessageDisplayed 
)

populate missing dimensions from a variableValue

Parameters
incompatibleMessageDisplayedboolean flag to make message display single shot

Definition at line 516 of file minsky.cc.

References minsky::VariableValue::hypercube().

Referenced by minsky::VariableBase::importFromCSV().

517  {
518  set<string> varDimensions;
519  for (auto& xv: v.hypercube().xvectors)
520  {
521  auto d=dimensions.find(xv.name);
522  if (d==dimensions.end())
523  {
524  dimensions.emplace(xv.name, xv.dimension);
525  varDimensions.insert(xv.name);
526  }
527  else if (d->second.type!=xv.dimension.type && !incompatibleMessageDisplayed)
528  {
529  message("Incompatible dimension type for dimension "+d->first+". Please adjust the global dimension in the dimensions dialog, which can be found under the Edit menu.");
530  incompatibleMessageDisplayed=true;
531  }
532  }
533  // set all newly populated dimensions on Ravels to forward sort order
534  model->recursiveDo
535  (&Group::items,[&](Items& m, Items::iterator it)
536  {
537  if (auto ri=dynamic_cast<Ravel*>(it->get()))
538  for (size_t i=0; i<ri->numHandles(); ++i)
539  if (varDimensions.contains(ri->handleDescription(i)))
540  ri->setHandleSortOrder(ravel::HandleSort::forward, i);
541  return false;
542  });
543  }
virtual void message(const std::string &)
display a message in a popup box on the GUI
Definition: minsky.h:456
std::vector< ItemPtr > Items
Definition: item.h:366
GroupPtr model
Definition: minsky.h:255
Dimensions dimensions
Definition: minsky.h:201
Here is the call graph for this function:
Here is the caller graph for this function:

◆ populateMissingDimensionsFromVariable() [2/2]

void minsky::Minsky::populateMissingDimensionsFromVariable ( const VariableValue v)
inline

Definition at line 211 of file minsky.h.

212  {bool dummy; populateMissingDimensionsFromVariable(v,dummy);}
void populateMissingDimensionsFromVariable(const VariableValue &, bool &incompatibleMessageDisplayed)
populate missing dimensions from a variableValue
Definition: minsky.cc:516

◆ progress()

virtual void minsky::Minsky::progress ( const std::string &  title,
int   
)
inlinevirtual

set progress bar, out of 100, labelling the progress bar with title

Reimplemented in minsky::anonymous_namespace{addon.cc}::AddOnMinsky.

Definition at line 447 of file minsky.h.

Referenced by minsky::Progress::displayProgress().

447 {}
Here is the caller graph for this function:

◆ pushFlags()

void minsky::Minsky::pushFlags ( )
inline

push and pop state of the flags

Definition at line 185 of file minsky.h.

185 {flagStack.push_back(flags);}

◆ pushHistory()

bool minsky::Minsky::pushHistory ( )

push current model state onto history if it differs from previous

Definition at line 1265 of file minsky.cc.

References classdesc::xml_pack().

Referenced by minsky::PubTab::addNote(), minsky::Canvas::copyItem(), minsky::PhillipsDiagram::init(), minsky::member_entry_hook(), minsky::PubTab::mouseUp(), minsky::PhillipsDiagram::mouseUp(), minsky::VariableBase::onMouseMotion(), minsky::PubTab::removeItemAt(), and minsky::PubTab::removeSelf().

1266  {
1267  // do not pushHistory after undo or redo
1268  if (undone)
1269  return undone=false;
1270 
1271  // go via a schema object, as serialising minsky::Minsky has
1272  // problems due to port management
1273  schema3::Minsky m(*this, false /* don't pack tensor data */);
1274  pack_t buf;
1275  buf<<m;
1276  if (history.empty())
1277  {
1278  history.emplace_back();
1279  buf.swap(history.back());
1280  historyPtr=history.size();
1281  return true;
1282  }
1283  while (history.size()>maxHistory)
1284  history.pop_front();
1285  if (history.empty() || history.back().size()!=buf.size() || memcmp(buf.data(), history.back().data(), buf.size())!=0)
1286  {
1287  // check XML versions differ (slower)
1288  ostringstream prev, curr;
1289  xml_pack_t prevXbuf(prev), currXbuf(curr);
1290  xml_pack(currXbuf,"Minsky",m);
1291  schema3::Minsky previousMinsky;
1292  history.back().reseto()>>previousMinsky;
1293  xml_pack(prevXbuf,"Minsky",previousMinsky);
1294 
1295  if (curr.str()!=prev.str())
1296  {
1297  // This bit of code outputs an XML representation that can be
1298  // used for debugging issues related to unnecessary
1299  // history pushes.
1300  //buf.reseto()>>m;
1301  //xml_pack_t tb(cout);
1302  //tb.prettyPrint=true;
1303  //xml_pack(tb,"Minsky",m);
1304  //cout<<"------"<<endl;
1305  history.emplace_back();
1306  buf.swap(history.back());
1307  historyPtr=history.size();
1308  if (autoSaver && doPushHistory)
1309  try
1310  {
1311  //autoSaver->packer.prettyPrint=true;
1312  autoSaver->save(m);
1313  }
1314  catch (...)
1315  {
1316  autoSaver.reset();
1317  throw;
1318  }
1319  return true;
1320  }
1321  }
1322  historyPtr=history.size();
1323  return false;
1324  }
unsigned maxHistory
maximum no. of history states to save
Definition: minsky.h:353
bool doPushHistory
flag to indicate whether a TCL should be pushed onto the history stack, or logged in a recording...
Definition: minsky.h:384
void xml_pack(xml_pack_t &t, const string &d, minsky::Optional< T > &a)
Definition: optional.h:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomLayout()

void minsky::Minsky::randomLayout ( )

randomly layout current open group and recentre reinitialises canvas to the group located in item

Definition at line 1631 of file minsky.cc.

1632  {
1633  canvas.model->randomLayout();
1634  canvas.recentre();
1635  }
void recentre()
adjust canvas so that -ve coordinates appear on canvas
Definition: canvas.cc:927
Model model
Definition: canvas.h:103
Canvas canvas
Definition: minsky.h:256

◆ ravelAvailable()

static bool minsky::Minsky::ravelAvailable ( )
inlinestatic

Definition at line 347 of file minsky.h.

347 {return ravel::Ravel::available();}

◆ ravelExpired()

static bool minsky::Minsky::ravelExpired ( )
inlinestatic

Definition at line 348 of file minsky.h.

348 {return ravel::Ravel::available() && ravel::Ravel::daysUntilExpired()<0;}

◆ ravelVersion()

std::string minsky::Minsky::ravelVersion ( ) const
inline

Definition at line 339 of file minsky.h.

References minsky::to_string().

339  {
340  if (ravel::Ravel::available())
341  {
342  int d=ravel::Ravel::daysUntilExpired();
343  return ravel::Ravel::version() + ": "+((d>=0)?("Expires in "+std::to_string(d)+" day"+(d!=1?"s":"")): "Expired");
344  }
345  else return "unavailable";
346  }
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
Here is the call graph for this function:

◆ redrawAllGodleyTables()

void minsky::Minsky::redrawAllGodleyTables ( )

request all Godley table windows to redraw

Definition at line 1703 of file minsky.cc.

Referenced by minsky::GodleyTableEditor::update().

1704  {
1705  model->recursiveDo(&Group::items,
1706  [&](Items&,Items::iterator i) {
1707  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1708  g->popup.requestRedraw();
1709  return false;
1710  });
1711  }
std::vector< ItemPtr > Items
Definition: item.h:366
GroupPtr model
Definition: minsky.h:255
Here is the caller graph for this function:

◆ removeItems()

void minsky::Minsky::removeItems ( Wire wire)
private

remove the definition network from wire, up to, but not including attached variables.

Definition at line 1648 of file minsky.cc.

References minsky::wire.

1649  {
1650  if (wire.from()->wires().size()==1)
1651  { // only remove higher up the network if this item is the only item feeding from it
1652  auto& item=wire.from()->item();
1653  if (!item.variableCast())
1654  {
1655  for (size_t i=1; i<item.portsSize(); ++i)
1656  if (auto p=item.ports(i).lock())
1657  for (auto w: p->wires())
1658  removeItems(*w);
1659  model->removeItem(item);
1660  }
1661  else if (auto p=item.ports(1).lock())
1662  if (p->wires().empty())
1663  model->removeItem(item); // remove non-definition variables as well
1664  }
1665  model->removeWire(wire);
1666  }
void removeItems(Wire &wire)
remove the definition network from wire, up to, but not including attached variables.
Definition: minsky.cc:1648
GroupPtr model
Definition: minsky.h:255

◆ renameDimension()

void minsky::Minsky::renameDimension ( const std::string &  oldName,
const std::string &  newName 
)

Definition at line 545 of file minsky.cc.

546  {
547  auto i=dimensions.find(oldName);
548  if (i!=dimensions.end())
549  {
550  dimensions[newName]=i->second;
551  dimensions.erase(i);
552  }
553 
554  for (auto& v: variableValues)
555  {
556  auto hc=v.second->tensorInit.hypercube();
557  for (auto& x: hc.xvectors)
558  if (x.name==oldName)
559  {
560  x.name=newName;
561  }
562  v.second->tensorInit.hypercube(hc);
563  }
564  }
VariableValues variableValues
Definition: minsky.h:200
Dimensions dimensions
Definition: minsky.h:201

◆ renderAllPlotsAsSVG()

void minsky::Minsky::renderAllPlotsAsSVG ( const string &  prefix) const

render all plots

Definition at line 1548 of file minsky.cc.

References minsky::str().

1549  {
1550  unsigned plotNum=0;
1551  model->recursiveDo(&Group::items,
1552  [&](Items&, Items::iterator i) {
1553  if (auto p=(*i)->plotWidgetCast())
1554  {
1555  if (!p->title.empty())
1556  p->renderToSVG(prefix+"-"+p->title+".svg");
1557  else
1558  p->renderToSVG(prefix+"-"+str(plotNum++)+".svg");
1559  }
1560  return false;
1561  });
1562  }
std::vector< ItemPtr > Items
Definition: item.h:366
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GroupPtr model
Definition: minsky.h:255
Here is the call graph for this function:

◆ renderCanvasToEMF()

void minsky::Minsky::renderCanvasToEMF ( const std::string &  filename)
inline

render canvas to a EMF image file (Windows only)

Definition at line 418 of file minsky.h.

418 {canvas.renderToEMF(filename);}
Canvas canvas
Definition: minsky.h:256

◆ renderCanvasToPDF()

void minsky::Minsky::renderCanvasToPDF ( const std::string &  filename)
inline

render canvas to a PDF file

Definition at line 404 of file minsky.h.

404 {canvas.renderToPDF(filename);}
Canvas canvas
Definition: minsky.h:256

◆ renderCanvasToPNG() [1/2]

void minsky::Minsky::renderCanvasToPNG ( const std::string &  filename)
inline

render canvas to a PNG image file

Definition at line 408 of file minsky.h.

408 {canvas.renderToPNG(filename);}
Canvas canvas
Definition: minsky.h:256

◆ renderCanvasToPNG() [2/2]

void minsky::Minsky::renderCanvasToPNG ( const std::string &  filename,
const Canvas::ZoomCrop z 
)
inline

Render canvas to a PNG file filename, scaling the canvas temporarily by zoom, shifts it to left, top, and crops to width, height (in ZoomCrop struct).

Definition at line 414 of file minsky.h.

415  {canvas.renderToPNGCropped(filename,z);}
Canvas canvas
Definition: minsky.h:256
void renderToPNGCropped(const std::string &filename, const ZoomCrop &)
Render to a PNG file filename, scaling the canvas temporarily by zoom, shifts it to left...
Definition: canvas.cc:943

◆ renderCanvasToPS()

void minsky::Minsky::renderCanvasToPS ( const std::string &  filename)
inline

render canvas to a postscript file

Definition at line 402 of file minsky.h.

402 {canvas.renderToPS(filename);}
Canvas canvas
Definition: minsky.h:256

◆ renderCanvasToSVG()

void minsky::Minsky::renderCanvasToSVG ( const std::string &  filename)
inline

render canvas to an SVG file

Definition at line 406 of file minsky.h.

406 {canvas.renderToSVG(filename);}
Canvas canvas
Definition: minsky.h:256

◆ requestRedraw()

void minsky::Minsky::requestRedraw ( )

requests a redraw of the curren active tab

Definition at line 487 of file minsky.cc.

488  {
489  // requestRedraw on all tabs - only the active one will actually do anything
491  equationDisplay.requestRedraw();
493  for (auto& pub: publicationTabs)
494  pub.requestRedraw();
495  }
PannableTab< EquationDisplay > equationDisplay
Definition: minsky.h:153
std::vector< PubTab > publicationTabs
Definition: minsky.h:156
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
PhillipsDiagram phillipsDiagram
Definition: minsky.h:155

◆ requestReset()

void minsky::Minsky::requestReset ( )

Definition at line 467 of file minsky.cc.

References reset().

Referenced by minsky::Ravel::collapseAllHandles(), minsky::Canvas::deleteItem(), minsky::Canvas::deleteWire(), minsky::Sheet::draw(), minsky::RavelPopup::mouseOver(), minsky::PubTab::mouseUp(), minsky::Canvas::mouseUp(), minsky::Ravel::onKeyPress(), minsky::VariableBase::onKeyPress(), minsky::VariableBase::onMouseMotion(), minsky::Ravel::pickSliceLabels(), minsky::Group::renameAllInstances(), and minsky::Ravel::sortByValue().

468  {
469  if (resetDuration<resetNowThreshold)
470  {
471  try
472  {
473  reset();
474  }
475  catch (...)
476  {}
477  return;
478  }
479  flags|=reset_needed;
480  // schedule reset for some time in the future
481  if (resetDuration<resetPostponedThreshold)
482  resetAt=std::chrono::system_clock::now()+resetPostponedThreshold;
483  else // postpone "indefinitely"
484  resetAt=std::chrono::time_point<std::chrono::system_clock>::max();
485  }
void reset()
resets the variables back to their initial values
Definition: minsky.cc:866
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void minsky::Minsky::reset ( )

resets the variables back to their initial values

Definition at line 866 of file minsky.cc.

References minsky::onStackExit(), and minsky::wire.

Referenced by minsky::Lock::toggleLocked().

868  {
869  // do not reset while simulation is running
870  if (RKThreadRunning)
871  {
872  flags |= reset_needed;
873  if (RKThreadRunning) return;
874  }
875 
876  auto start=chrono::high_resolution_clock::now();
877  auto updateResetDuration=onStackExit([&]{resetDuration=chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()-start);});
878  canvas.itemIndicator.reset();
879  const BusyCursor busy(*this);
881  lastT=t0;
882  const ProgressUpdater pu(progressState,"Resetting",5);
885  ++progressState;
886  // if no stock variables in system, add a dummy stock variable to
887  // make the simulation proceed
888  if (stockVars.empty()) stockVars.resize(1,0);
889 
890  initGodleys();
891  ++progressState;
892 
893  if (!stockVars.empty())
894  rkreset();
895 
896  // update flow variable
897  evalEquations();
898  ++progressState;
899 
900  // populate ravel hypercubes first, before reattaching plots.
901  model->recursiveDo
902  (&Group::items,
903  [&](Items& m, Items::iterator i)
904  {
905  if (auto r=dynamic_cast<Ravel*>(i->get()))
906  {
907  if (r->ports(1).lock()->numWires()>0)
908  if (auto vv=r->ports(1).lock()->getVariableValue())
909  r->populateHypercube(vv->hypercube());
910  }
911  else if (auto v=(*i)->variableCast())
912  v->resetMiniPlot();
913  return false;
914  });
915 
916  // attach the plots
917  model->recursiveDo
918  (&Group::items,
919  [&](Items& m, Items::iterator it)
920  {
921  if (auto p=(*it)->plotWidgetCast())
922  {
923  p->disconnectAllVars();// clear any old associations
924  p->clearPenAttributes();
925  p->autoScale();
926  for (size_t i=0; i<p->portsSize(); ++i)
927  {
928  auto pp=p->ports(i).lock();
929  for (auto wire: pp->wires())
930  if (auto fromPort=wire->from())
931  if (auto vv=wire->from()->getVariableValue())
932  if (vv->idx()>=0)
933  p->connectVar(vv, i);
934  }
935  p->clear();
936  if (running)
937  p->updateIcon(t);
938  else
939  p->addConstantCurves();
940  p->requestRedraw();
941  }
942  return false;
943  });
944  ++progressState;
945 
946  // if (running)
947  flags &= ~reset_needed; // clear reset flag
948  resetAt=std::chrono::time_point<std::chrono::system_clock>::max();
949  // else
950  // flags |= reset_needed; // enforce another reset at simulation start
951  running=false;
952 
953  requestRedraw();
954 
955  // update maxValues
956  PhillipsFlow::maxFlow.clear();
957  PhillipsStock::maxStock.clear();
958  for (auto& v: variableValues)
959  {
960  if (v.second->type()==VariableType::stock)
961  {
962  PhillipsStock::maxStock[v.second->units]+=v.second->value();
963  }
964  }
965  for (auto& i: PhillipsStock::maxStock) i.second=abs(i.second);
966  }
967  catch (...)
968  {
969  // in the event of an exception, clear reset flag
970  flags &= ~reset_needed; // clear reset flag
971  resetAt=std::chrono::time_point<std::chrono::system_clock>::max();
972  resetDuration=chrono::milliseconds::max();
973  throw;
974  }
double lastT
previous timestep
Definition: minsky.h:320
void rkreset()
reset the simulation
Definition: rungeKutta.cc:122
void constructEquations()
construct the equations based on input data
Definition: minsky.cc:393
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
static double t
Definition: evalOp.h:53
VariableValues variableValues
Definition: minsky.h:200
static std::map< Units, double > maxFlow
static std::map< Units, double > maxStock
ItemPtr itemIndicator
for drawing error indicator on the canvas
Definition: canvas.h:120
std::vector< ItemPtr > Items
Definition: item.h:366
Canvas canvas
Definition: minsky.h:256
void initGodleys()
Definition: minsky.cc:857
OnStackExit< F > onStackExit(F f)
generator function
Definition: str.h:85
double t
time
Definition: rungeKutta.h:57
GroupPtr model
Definition: minsky.h:255
void evalEquations()
Definition: rungeKutta.h:70
bool running
controls whether simulation is running
Definition: rungeKutta.h:58
void requestRedraw()
requests a redraw of the curren active tab
Definition: minsky.cc:487
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_flag()

bool minsky::Minsky::reset_flag ( ) const
inline

true if reset needs to be called prior to numerical integration

Definition at line 171 of file minsky.h.

Referenced by minsky::Canvas::mouseMove().

171 {return flags & reset_needed;}
Here is the caller graph for this function:

◆ resetIfFlagged()

bool minsky::Minsky::resetIfFlagged ( )
inlineoverridevirtual

checks whether a reset is required, and resets the simulation if so

Returns
whether simulation was reset

Reimplemented from minsky::RungeKutta.

Definition at line 194 of file minsky.h.

References reset().

194  {
195  if (reset_flag())
196  reset();
197  return reset_flag();
198  }
void reset()
resets the variables back to their initial values
Definition: minsky.cc:866
bool reset_flag() const
true if reset needs to be called prior to numerical integration
Definition: minsky.h:171
Here is the call graph for this function:

◆ resetScroll()

virtual void minsky::Minsky::resetScroll ( )
inlinevirtual

reset main window scroll bars after model has been panned

Reimplemented in minsky::anonymous_namespace{addon.cc}::AddOnMinsky.

Definition at line 453 of file minsky.h.

Referenced by displayErrorItem(), minsky::VariableInstanceList::gotoInstance(), and minsky::Canvas::zoomToDisplay().

453 {}
Here is the caller graph for this function:

◆ runItemDeletedCallback()

virtual void minsky::Minsky::runItemDeletedCallback ( const Item )
inlinevirtual

run callback attached to item

Reimplemented in minsky::MinskyTCL.

Definition at line 459 of file minsky.h.

Referenced by minsky::Group::deleteItem().

459 {}
Here is the caller graph for this function:

◆ save()

void minsky::Minsky::save ( const std::string &  filename)

Definition at line 1014 of file minsky.cc.

References minsky::Saver::os, minsky::Saver::packer, minsky::remove(), minsky::Saver::save(), and minsky::to_string().

1015  {
1016  // back up to temporary file name
1017  rename(filename.c_str(), (filename+"~").c_str());
1018 
1019  const schema3::Minsky m(*this);
1020  Saver saver(filename);
1021  saver.packer.prettyPrint=true;
1022  try
1023  {
1024  saver.save(m);
1025  }
1026  catch (...) {
1027  // rename backup in place
1028  rename((filename+"~").c_str(), filename.c_str());
1029  // if exception is due to file error, provide a more useful message
1030  if (!saver.os)
1031  throw runtime_error("cannot save to "+filename);
1032  throw;
1033  }
1034  pushHistory(); // ensure history is up to date to prevent trivial setting of dirty flag
1035  flags &= ~is_edited;
1037  if (autoSaver)
1038  boost::filesystem::remove(autoSaver->fileName);
1039  // rotate saved versions
1040  for (int i=numBackups; i>1; --i)
1041  rename((filename+";"+to_string(i-1)).c_str(), (filename+";"+to_string(i)).c_str());
1042  if (numBackups>0)
1043  rename((filename+"~").c_str(), (filename+";1").c_str());
1044  else
1045  ::remove((filename+"~").c_str());
1046  }
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
void remove(std::vector< T > &x, const V &v)
remove an element from a vector. V must be comparable to a T
Definition: str.h:89
int numBackups
number of previous versions of saved files to keep save to a file
Definition: minsky.h:325
static const std::string minskyVersion
return the AEGIS assigned version number
Definition: minsky.h:337
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
std::string fileVersion
Minsky version file was saved under.
Definition: minsky.h:351
Here is the call graph for this function:

◆ saveCanvasItemAsFile()

void minsky::Minsky::saveCanvasItemAsFile ( const string &  fileName) const
inline

Definition at line 267 of file minsky.h.

268  {if (auto g=dynamic_cast<Group*>(canvas.item.get())) saveGroupAsFile(*g,fileName);}
static void saveGroupAsFile(const Group &, const string &fileName)
Definition: minsky.cc:214
Canvas canvas
Definition: minsky.h:256
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175

◆ saveGroupAsFile()

void minsky::Minsky::saveGroupAsFile ( const Group g,
const string &  fileName 
)
static

Definition at line 214 of file minsky.cc.

References minsky::Saver::save().

215  {
216  const schema3::Minsky m(g);
217  Saver(fileName).save(m);
218  }
Here is the call graph for this function:

◆ saveSelectionAsFile()

void minsky::Minsky::saveSelectionAsFile ( const string &  fileName) const
inline

Definition at line 281 of file minsky.h.

281 {saveGroupAsFile(canvas.selection,fileName);}
static void saveGroupAsFile(const Group &, const string &fileName)
Definition: minsky.cc:214
Canvas canvas
Definition: minsky.h:256
Selection selection
Definition: canvas.h:105

◆ setAllDEmode()

void minsky::Minsky::setAllDEmode ( bool  mode)

set DE mode on all godley tables

Definition at line 1579 of file minsky.cc.

1579  {
1580  model->recursiveDo(&GroupItems::items, [mode](Items&,Items::iterator i) {
1581  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1582  g->table.setDEmode(mode);
1583  return false;
1584  });
1585  }
std::vector< ItemPtr > Items
Definition: item.h:366
GroupPtr model
Definition: minsky.h:255

◆ setAutoSaveFile()

void minsky::Minsky::setAutoSaveFile ( const std::string &  file)

initialises auto saving empty file to turn off autosave

Definition at line 1780 of file minsky.cc.

1780  {
1781  if (file.empty())
1782  autoSaver.reset();
1783  else
1784  autoSaver.reset(new BackgroundSaver(file));
1785  }

◆ setBusyCursor()

virtual void minsky::Minsky::setBusyCursor ( )
inlinevirtual

set/clear busy cursor in GUI

Reimplemented in minsky::anonymous_namespace{addon.cc}::AddOnMinsky, and minsky::MinskyTCL.

Definition at line 444 of file minsky.h.

444 {}

◆ setDefinition()

void minsky::Minsky::setDefinition ( const std::string &  valueId,
const std::string &  definition 
)

add/replace a definition for a flow variable given by valueId

Definition at line 1668 of file minsky.cc.

References minsky::UserFunction::expression, minsky::flipped(), minsky::Item::moveTo(), minsky::Item::ports(), minsky::valueId(), minsky::var, and minsky::Item::width().

1669  {
1670  auto var=definingVar(valueId);
1671  if (!var) // find
1672  var=dynamic_pointer_cast<VariableBase>(model->findAny(&GroupItems::items, [&](const ItemPtr& it) {
1673  if (auto v=it->variableCast())
1674  return v->valueId()==valueId;
1675  return false;
1676  }));
1677  if (var)
1678  if (auto p=var->ports(1).lock())
1679  {
1680  auto group=var->group.lock();
1681  if (!group) group=model;
1682  UserFunction* udf=p->wires().empty()? nullptr: dynamic_cast<UserFunction*>(&p->wires().front()->from()->item());
1683  if (!udf)
1684  {
1685  // remove previous definition network
1686  for (auto w: p->wires())
1687  {
1688  assert(w);
1689  removeItems(*w);
1690  }
1691 
1692  udf=new UserFunction(var->name()+"()");
1693  group->addItem(udf); // ownership passed
1694  const bool notFlipped=!flipped(var->rotation());
1695  udf->moveTo(var->x()+(notFlipped? -1:1)*0.6*(var->width()+udf->width()), var->y());
1696  group->addWire(udf->ports(0), var->ports(1));
1697  }
1698  udf->expression=definition;
1699  }
1700  }
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
void removeItems(Wire &wire)
remove the definition network from wire, up to, but not including attached variables.
Definition: minsky.cc:1648
bool flipped(double rotation)
returns if the angle (in degrees) is in the second or third quadrant
Definition: geometry.h:102
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:205
GroupPtr model
Definition: minsky.h:255
Definition: group.tcl:84
Here is the call graph for this function:

◆ setGodleyDisplayValue()

void minsky::Minsky::setGodleyDisplayValue ( bool  displayValues,
GodleyTable::DisplayStyle  displayStyle 
)

set display value mode on all godley table editor modes

Definition at line 1587 of file minsky.cc.

1588  {
1590  this->displayStyle=displayStyle;
1592  model->recursiveDo(&GroupItems::items, [](Items&,Items::iterator i) {
1593  if (auto g=dynamic_cast<GodleyIcon*>(i->get()))
1594  g->popup.requestRedraw();
1595  return false;
1596  });
1597  }
bool displayValues
Definition: minsky.h:431
GodleyTable::DisplayStyle displayStyle
Definition: minsky.h:432
std::vector< ItemPtr > Items
Definition: item.h:366
Canvas canvas
Definition: minsky.h:256
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
GroupPtr model
Definition: minsky.h:255

◆ setGodleyIconResource()

void minsky::Minsky::setGodleyIconResource ( const string &  s)
inline

Definition at line 215 of file minsky.h.

References minsky::SVGRenderer::setResource(), and minsky::GodleyIcon::svgRenderer.

void setResource(const std::string &resource)
initialise object from an SVG file
Definition: SVGItem.cc:57
static SVGRenderer svgRenderer
SVG icon to display when not in editor mode.
Definition: godleyIcon.h:62
Here is the call graph for this function:

◆ setGroupIconResource()

void minsky::Minsky::setGroupIconResource ( const string &  s)
inline

Definition at line 217 of file minsky.h.

References minsky::SVGRenderer::setResource(), and minsky::Group::svgRenderer.

static SVGRenderer svgRenderer
Definition: group.h:259
void setResource(const std::string &resource)
initialise object from an SVG file
Definition: SVGItem.cc:57
Here is the call graph for this function:

◆ setLockIconResource()

void minsky::Minsky::setLockIconResource ( const string &  locked,
const string &  unlocked 
)
inline

Definition at line 219 of file minsky.h.

References minsky::Lock::lockedIcon, minsky::SVGRenderer::setResource(), and minsky::Lock::unlockedIcon.

219  {
222  }
void setResource(const std::string &resource)
initialise object from an SVG file
Definition: SVGItem.cc:57
static SVGRenderer lockedIcon
Definition: lock.h:42
static SVGRenderer unlockedIcon
Definition: lock.h:43
Here is the call graph for this function:

◆ setRavelIconResource()

void minsky::Minsky::setRavelIconResource ( const string &  s)
inline

Definition at line 223 of file minsky.h.

References minsky::SVGRenderer::setResource(), and minsky::Ravel::svgRenderer.

void setResource(const std::string &resource)
initialise object from an SVG file
Definition: SVGItem.cc:57
static SVGRenderer svgRenderer
SVG icon to display when not in editor mode.
Definition: ravelWrap.h:83
Here is the call graph for this function:

◆ srand()

void minsky::Minsky::srand ( int  seed)
inline

set std library RNG seed

Definition at line 428 of file minsky.h.

428 {::srand(seed);}
void srand(int seed)
set std library RNG seed
Definition: minsky.h:428

◆ step()

vector< double > minsky::Minsky::step ( )

step the equations (by n steps, default 1)

Definition at line 976 of file minsky.cc.

977  {
978  lastT=t;
979  rkstep();
980 
981  logVariables();
982 
983  model->recursiveDo
984  (&Group::items,
985  [&](Items&, Items::iterator i)
986  {(*i)->updateIcon(t); return false;});
987 
988  // throttle redraws
989  const time_duration maxWait=milliseconds(maxWaitMS);
990  if ((microsec_clock::local_time()-(ptime&)lastRedraw) > maxWait)
991  {
992  requestRedraw();
993  lastRedraw=microsec_clock::local_time();
994  }
995 
996  return {t, deltaT()};
997  }
void rkstep()
step the equations (by n steps, default 1) evaluate the flow equations without stepping.
Definition: rungeKutta.cc:130
double lastT
previous timestep
Definition: minsky.h:320
void logVariables() const
write current state of all variables to the log file
Definition: minsky.cc:108
Exclude< ptime > lastRedraw
Definition: minsky.h:142
std::vector< ItemPtr > Items
Definition: item.h:366
double deltaT() const
Definition: minsky.h:321
double t
time
Definition: rungeKutta.h:57
GroupPtr model
Definition: minsky.h:255
int maxWaitMS
maximum wait in millisecond between redrawing canvas during simulation
Definition: minsky.h:354
void requestRedraw()
requests a redraw of the curren active tab
Definition: minsky.cc:487

◆ triggerCheckMemAllocationCallback()

bool minsky::Minsky::triggerCheckMemAllocationCallback ( ) const
inline

trigger checkMem callback for testing purposes

Definition at line 534 of file minsky.h.

535  {return checkMemAllocation(std::numeric_limits<size_t>::max());}
virtual MemCheckResult checkMemAllocation(size_t bytes) const
Definition: minsky.h:464

◆ undo()

long minsky::Minsky::undo ( int  changes = 1)

restore model to state changes ago

Returns
index of current state in history

Definition at line 1401 of file minsky.cc.

References schema3::Minsky::phillipsDiagram, schema3::Minsky::populateGroup(), schema3::PhillipsDiagram::populatePhillipsDiagram(), schema3::Minsky::populatePublicationTabs(), and schema3::Minsky::zoomFactor.

Referenced by minsky::Canvas::copyItem(), and minsky::MinskyTCL::undo().

1402  {
1403  // save current state for later restoration if needed
1404  if (historyPtr==history.size())
1405  pushHistory();
1406  historyPtr-=changes;
1407  if (historyPtr > 0 && historyPtr <= history.size())
1408  {
1409  schema3::Minsky m;
1410  history[historyPtr-1].reseto()>>m;
1411  // stash tensorInit data for later restoration
1412  auto stashedValues=std::move(variableValues);
1413  // preserve bookmarks. For now, we can only preserve model and canvas.model bookmarks
1414  // count the total number of bookmarks
1415  unsigned numBookmarks=0;
1416  model->recursiveDo(&GroupItems::groups, [&](const Groups&,const Groups::const_iterator i) {
1417  numBookmarks+=(*i)->bookmarks.size();
1418  return false;
1419  });
1420  auto stashedGlobalBookmarks=model->bookmarks;
1421  auto stashedCanvasBookmarks=canvas.model->bookmarks;
1422  clearAllMaps(false);
1423  model->clear();
1424  m.populateGroup(*model);
1425  model->setZoom(m.zoomFactor);
1428  requestRedraw();
1429 
1430  // restore tensorInit data
1431  for (auto& v: variableValues)
1432  {
1433  auto stashedValue=stashedValues.find(v.first);
1434  if (stashedValue!=stashedValues.end())
1435  v.second->tensorInit=std::move(stashedValue->second->tensorInit);
1436  }
1437  // restore bookmarks
1438  model->bookmarks=std::move(stashedGlobalBookmarks);
1439  canvas.model->bookmarks=std::move(stashedCanvasBookmarks);
1440  unsigned numBookmarksAfterwards=0;
1441  model->recursiveDo(&GroupItems::groups, [&](const Groups&,const Groups::const_iterator i) {
1442  numBookmarksAfterwards+=(*i)->bookmarks.size();
1443  return false;
1444  });
1445  if (numBookmarksAfterwards!=numBookmarks)
1446  message("This undo/redo operation potentially deletes some bookmarks");
1447  try {requestReset();}
1448  catch (...) {}
1449 
1450  }
1451  else
1452  historyPtr+=changes; // revert
1453  undone=true; //ensure next pushHistory is ignored
1454  return historyPtr;
1455  }
virtual void message(const std::string &)
display a message in a popup box on the GUI
Definition: minsky.h:456
void populatePublicationTabs(std::vector< minsky::PubTab > &) const
Definition: schema3.cc:610
double zoomFactor
Definition: schema3.h:255
void requestReset()
Definition: minsky.cc:467
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
void populatePhillipsDiagram(minsky::PhillipsDiagram &) const
populate a Phillips Diagram from this
Definition: schema3.cc:850
VariableValues variableValues
Definition: minsky.h:200
void populateGroup(minsky::Group &g) const
populate a group object from this. This mutates the ids in a consistent way into the free id space of...
Definition: schema3.cc:636
PhillipsDiagram phillipsDiagram
Definition: schema3.h:259
Model model
Definition: canvas.h:103
std::vector< PubTab > publicationTabs
Definition: minsky.h:156
Canvas canvas
Definition: minsky.h:256
std::vector< GroupPtr > Groups
Definition: group.h:54
Groups groups
Definition: group.h:79
PhillipsDiagram phillipsDiagram
Definition: minsky.h:155
void clearAllMaps()
Definition: minsky.h:259
GroupPtr model
Definition: minsky.h:255
void requestRedraw()
requests a redraw of the curren active tab
Definition: minsky.cc:487
Here is the call graph for this function:
Here is the caller graph for this function:

◆ variableTypes()

vector< string > minsky::Minsky::variableTypes ( )

list of available variable types

Definition at line 1608 of file minsky.cc.

1609  {return enumVals<VariableType::Type>();}

Member Data Documentation

◆ canvas

◆ conversions

Conversions minsky::Minsky::conversions

Definition at line 202 of file minsky.h.

Referenced by schema3::Minsky::Minsky(), and schema3::Minsky::populateMinsky().

◆ dimensions

◆ displayStyle

GodleyTable::DisplayStyle minsky::Minsky::displayStyle =GodleyTable::sign

Definition at line 432 of file minsky.h.

◆ displayValues

bool minsky::Minsky::displayValues =false

Definition at line 431 of file minsky.h.

Referenced by minsky::GodleyTableEditor::draw().

◆ doPushHistory

bool minsky::Minsky::doPushHistory =true

flag to indicate whether a TCL should be pushed onto the history stack, or logged in a recording. This is used to avoid movements being added to recordings and undo history

Definition at line 384 of file minsky.h.

◆ equationDisplay

PannableTab<EquationDisplay> minsky::Minsky::equationDisplay

Definition at line 153 of file minsky.h.

◆ fileVersion

std::string minsky::Minsky::fileVersion

Minsky version file was saved under.

Definition at line 351 of file minsky.h.

Referenced by schema3::Minsky::populateMinsky().

◆ fontSampler

FontDisplay minsky::Minsky::fontSampler

Definition at line 154 of file minsky.h.

◆ histogramResource

SVGRenderer minsky::Minsky::histogramResource

◆ lastRedraw

Exclude<ptime> minsky::Minsky::lastRedraw
private

Definition at line 142 of file minsky.h.

◆ lastT

double minsky::Minsky::lastT {0}

previous timestep

Definition at line 320 of file minsky.h.

◆ logVarList

std::set<string> minsky::Minsky::logVarList

set of variables (valueIds) to log

Definition at line 302 of file minsky.h.

◆ m_multipleEquities

bool minsky::Minsky::m_multipleEquities =false
private

Definition at line 144 of file minsky.h.

◆ maxFlowValue

std::map<Units, double> minsky::Minsky::maxFlowValue

Definition at line 205 of file minsky.h.

◆ maxHistory

unsigned minsky::Minsky::maxHistory {100}

maximum no. of history states to save

Definition at line 353 of file minsky.h.

◆ maxValue

std::map<Units, double> minsky::Minsky::maxValue

stash the maximum absolute value obtained by a dimensioned quantity

Definition at line 204 of file minsky.h.

◆ maxWaitMS

int minsky::Minsky::maxWaitMS =100

maximum wait in millisecond between redrawing canvas during simulation

Definition at line 354 of file minsky.h.

Referenced by minsky::Canvas::reportDrawTime().

◆ minskyVersion

const std::string minsky::Minsky::minskyVersion =MINSKY_VERSION
static

return the AEGIS assigned version number

Definition at line 337 of file minsky.h.

Referenced by schema3::Minsky::Minsky(), and minsky::MinskyTCL::startRecording().

◆ model

◆ namedItems

std::map<std::string,std::weak_ptr<Item> > minsky::Minsky::namedItems

Definition at line 529 of file minsky.h.

◆ numBackups

int minsky::Minsky::numBackups =1

number of previous versions of saved files to keep save to a file

Definition at line 325 of file minsky.h.

◆ phillipsDiagram

PhillipsDiagram minsky::Minsky::phillipsDiagram

Definition at line 155 of file minsky.h.

Referenced by schema3::Minsky::Minsky(), and schema3::Minsky::populateMinsky().

◆ publicationTabs

std::vector<PubTab> minsky::Minsky::publicationTabs

◆ userFunctions

Exclude<std::map<std::string, std::shared_ptr<CallableFunction> > > minsky::Minsky::userFunctions

Definition at line 253 of file minsky.h.

Referenced by minsky::UserFunction::compile(), and minsky::UserFunction::units().

◆ variableInstanceList

std::shared_ptr<VariableInstanceList> minsky::Minsky::variableInstanceList

supports navigation to all instances of current variable

Definition at line 526 of file minsky.h.

◆ variablePane

VariablePane minsky::Minsky::variablePane

Definition at line 537 of file minsky.h.

◆ variableValues


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