COPASI API  4.16.103
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CDotOutput Class Reference

#include <CDotOutput.h>

Collaboration diagram for CDotOutput:
Collaboration graph
[legend]

Classes

class  ObjectData
 

Public Member Functions

 CDotOutput ()
 
void setOnlyAlgebraicDependencies (bool b)
 
void setSkipDependenciesOnCompartments (bool b)
 
void simpleCall (const CModel *pModel)
 
void writeDependencies (std::ostream &os, const CModel *pModel, const CCopasiObject *rootNode=NULL)
 

Protected Member Functions

void findObjectsWithUpdateMethod (const CCopasiObject *obj, std::set< const CCopasiObject * > &objectSet, size_t recursion=0) const
 
ObjectDatagetObjectDataFromRefresh (const Refresh *ref)
 
void updateObjectNodesFromModel (const CModel *model)
 
void writeDotRecursively (const CCopasiObject *obj, std::ostream &os)
 
void writeEdge (std::ostream &os, const CCopasiObject *ptr1, const CCopasiObject *ptr2, bool indirect=false)
 
void writeObjectNode (std::ostream &os, const CCopasiObject *ptr, const ObjectData &od) const
 

Protected Attributes

std::map< const CCopasiObject
*, ObjectData
mObjects
 
bool mOnlyAlgebraicDependencies
 
bool mSkipCompartments
 

Detailed Description

Definition at line 34 of file CDotOutput.h.

Constructor & Destructor Documentation

CDotOutput::CDotOutput ( )

Definition at line 39 of file CDotOutput.cpp.

40  : mSkipCompartments(false),
42 {}
bool mSkipCompartments
Definition: CDotOutput.h:74
bool mOnlyAlgebraicDependencies
Definition: CDotOutput.h:75

Member Function Documentation

void CDotOutput::findObjectsWithUpdateMethod ( const CCopasiObject obj,
std::set< const CCopasiObject * > &  objectSet,
size_t  recursion = 0 
) const
protected

Definition at line 74 of file CDotOutput.cpp.

References CCopasiObject::getDirectDependencies().

Referenced by writeDotRecursively().

75 {
76  if (!obj) return;
77 
78  if (recursion > 10) return; //limit recursion
79 
80  //it is assumed *obj has no UpdateMethod
81 
82  std::set< const CCopasiObject * >::const_iterator it, itEnd = obj->getDirectDependencies().end();
83 
84  for (it = obj->getDirectDependencies().begin(); it != itEnd; ++it)
85  {
86  if ((*it)->hasUpdateMethod())
87  objectSet.insert(*it);
88  else
89  findObjectsWithUpdateMethod(*it, objectSet, recursion + 1);
90  }
91 }
void findObjectsWithUpdateMethod(const CCopasiObject *obj, std::set< const CCopasiObject * > &objectSet, size_t recursion=0) const
Definition: CDotOutput.cpp:74
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
CDotOutput::ObjectData * CDotOutput::getObjectDataFromRefresh ( const Refresh ref)
protected

Definition at line 250 of file CDotOutput.cpp.

References mObjects.

Referenced by updateObjectNodesFromModel().

251 {
252  std::map <const CCopasiObject*, ObjectData>::iterator it, itEnd = mObjects.end();
253 
254  for (it = mObjects.begin(); it != itEnd; ++it)
255  {
256  if (it->first->getRefresh() == ref) return &it->second;
257  }
258 
259  return NULL;
260 }
std::map< const CCopasiObject *, ObjectData > mObjects
Definition: CDotOutput.h:77
void CDotOutput::setOnlyAlgebraicDependencies ( bool  b)
inline

Definition at line 44 of file CDotOutput.h.

References mOnlyAlgebraicDependencies.

Referenced by simpleCall().

bool mOnlyAlgebraicDependencies
Definition: CDotOutput.h:75
void CDotOutput::setSkipDependenciesOnCompartments ( bool  b)
inline

Definition at line 43 of file CDotOutput.h.

References mSkipCompartments.

Referenced by simpleCall().

43 {mSkipCompartments = b;};
bool mSkipCompartments
Definition: CDotOutput.h:74
void CDotOutput::simpleCall ( const CModel pModel)

Definition at line 262 of file CDotOutput.cpp.

References setOnlyAlgebraicDependencies(), setSkipDependenciesOnCompartments(), and writeDependencies().

263 {
264  std::ofstream os;
265  os.open("CopasiDependencies.dot", std::ios::out);
266 
269  writeDependencies(os, pModel);
270 
271  os.close();
272 }
void setOnlyAlgebraicDependencies(bool b)
Definition: CDotOutput.h:44
void writeDependencies(std::ostream &os, const CModel *pModel, const CCopasiObject *rootNode=NULL)
Definition: CDotOutput.cpp:44
void setSkipDependenciesOnCompartments(bool b)
Definition: CDotOutput.h:43
void CDotOutput::updateObjectNodesFromModel ( const CModel model)
protected

Definition at line 204 of file CDotOutput.cpp.

References CModel::getListOfConstantRefreshes(), CModel::getListOfNonSimulatedRefreshes(), CModel::getListOfSimulatedRefreshes(), getObjectDataFromRefresh(), CModel::getUptoDateObjects(), CDotOutput::ObjectData::mConstantRefreshesIndex, CDotOutput::ObjectData::mNonSimulatedRefreshesIndex, mObjects, and CDotOutput::ObjectData::mSimulatedRefreshesIndex.

Referenced by writeDependencies().

205 {
206  const std::set< const CCopasiObject * > & objectSet = model->getUptoDateObjects();
207 
208  std::set< const CCopasiObject * >::const_iterator it, itEnd = objectSet.end();
209 
210  for (it = objectSet.begin(); it != itEnd; ++it)
211  {
212  mObjects[*it].mInUpToDateList = true;
213  }
214 
215  size_t i, imax;
216 
217  imax = model->getListOfSimulatedRefreshes().size();
218 
219  for (i = 0; i < imax; ++i)
220  {
221  ObjectData * pOD = getObjectDataFromRefresh(model->getListOfSimulatedRefreshes()[i]);
222 
223  if (pOD) pOD->mSimulatedRefreshesIndex = i;
224  }
225 
226  imax = model->getListOfNonSimulatedRefreshes().size();
227 
228  for (i = 0; i < imax; ++i)
229  {
230  ObjectData * pOD = getObjectDataFromRefresh(model->getListOfNonSimulatedRefreshes()[i]);
231 
232  if (pOD) pOD->mNonSimulatedRefreshesIndex = i;
233  }
234 
235  imax = model->getListOfConstantRefreshes().size();
236 
237  for (i = 0; i < imax; ++i)
238  {
239  ObjectData * pOD = getObjectDataFromRefresh(model->getListOfConstantRefreshes()[i]);
240 
241  if (pOD) pOD->mConstantRefreshesIndex = i;
242  }
243 
244  /* const std::vector< Refresh * > getListOfSimulatedRefreshes() const; //mSimulatedRefreshes;
245  const std::vector< Refresh * > getListOfConstantRefreshes() const; //mConstantRefreshes;
246  const std::vector< Refresh * > getListOfNonSimulatedRefreshes() const; //mNonSimulatedRefreshes;
247  */
248 }
ObjectData * getObjectDataFromRefresh(const Refresh *ref)
Definition: CDotOutput.cpp:250
std::map< const CCopasiObject *, ObjectData > mObjects
Definition: CDotOutput.h:77
const std::vector< Refresh * > & getListOfConstantRefreshes() const
Definition: CModel.cpp:4139
const std::set< const CCopasiObject * > & getUptoDateObjects() const
Definition: CModel.cpp:1178
size_t mSimulatedRefreshesIndex
Definition: CDotOutput.h:53
const std::vector< Refresh * > & getListOfSimulatedRefreshes() const
Definition: CModel.cpp:4136
const std::vector< Refresh * > & getListOfNonSimulatedRefreshes() const
Definition: CModel.cpp:4142
size_t mNonSimulatedRefreshesIndex
Definition: CDotOutput.h:54
size_t mConstantRefreshesIndex
Definition: CDotOutput.h:55
void CDotOutput::writeDependencies ( std::ostream &  os,
const CModel pModel,
const CCopasiObject rootNode = NULL 
)

Definition at line 44 of file CDotOutput.cpp.

References CCopasiObject::getObjectDataModel(), mObjects, updateObjectNodesFromModel(), writeDotRecursively(), and writeObjectNode().

Referenced by simpleCall().

45 {
46  const CCopasiObject * obj;
47 
48  if (rootNode)
49  obj = rootNode;
50  else
51  obj = pModel->getObjectDataModel();
52 
53  mObjects.clear();
54 
55  os << "digraph G {\n";
56 
57  //edges
58  writeDotRecursively(obj, os);
59 
60  //this is done after the edges since it requires all relevant object to be in the mObjects map
62 
63  //nodes
64  std::map<const CCopasiObject*, ObjectData>::const_iterator it, itEnd = mObjects.end();
65 
66  for (it = mObjects.begin(); it != itEnd; ++it)
67  {
68  writeObjectNode(os, it->first, it->second);
69  }
70 
71  os << "}" << std::endl;
72 }
CCopasiDataModel * getObjectDataModel()
std::map< const CCopasiObject *, ObjectData > mObjects
Definition: CDotOutput.h:77
void writeObjectNode(std::ostream &os, const CCopasiObject *ptr, const ObjectData &od) const
Definition: CDotOutput.cpp:155
void writeDotRecursively(const CCopasiObject *obj, std::ostream &os)
Definition: CDotOutput.cpp:93
void updateObjectNodesFromModel(const CModel *model)
Definition: CDotOutput.cpp:204
void CDotOutput::writeDotRecursively ( const CCopasiObject obj,
std::ostream &  os 
)
protected

Definition at line 93 of file CDotOutput.cpp.

References findObjectsWithUpdateMethod(), CCopasiObject::getDirectDependencies(), CCopasiContainer::getObjects(), CCopasiObject::hasUpdateMethod(), CCopasiObject::isContainer(), mOnlyAlgebraicDependencies, mSkipCompartments, and writeEdge().

Referenced by writeDependencies().

94 {
95 
97  {
98  std::set< const CCopasiObject * >::const_iterator it, itEnd = obj->getDirectDependencies().end();
99 
100  for (it = obj->getDirectDependencies().begin(); it != itEnd; ++it)
101  {
102  //skip deps on compartments
103  if (mSkipCompartments)
104  if ((*it)->getObjectParent() && ((*it)->getObjectParent()->getObjectType() == "Compartment"
105  || (*it)->getObjectType() == "Compartment")) continue;
106 
108  {
109  if ((*it)->hasUpdateMethod())
110  {
111  writeEdge(os, obj, *it);
112  }
113  else
114  {//find indirect dependencies
115  std::set<const CCopasiObject* > tmpObjectSet;
116  findObjectsWithUpdateMethod(*it, tmpObjectSet);
117  std::set<const CCopasiObject* >::const_iterator tmpIt, tmpItEnd = tmpObjectSet.end();
118 
119  for (tmpIt = tmpObjectSet.begin(); tmpIt != tmpItEnd; ++tmpIt)
120  writeEdge(os, obj, *tmpIt, true); //
121  }
122  }
123  else
124  {
125  writeEdge(os, obj, *it);
126  }
127  }
128  }
129 
130  //recursion
131  if (obj->isContainer())
132  {
133  CCopasiContainer* container;
134  container = (CCopasiContainer*)obj;
135 
136  CCopasiContainer::objectMap::const_iterator it = container->getObjects().begin();
137 
138  for (; it != container->getObjects().end(); ++it)
139  {
140  //the next line skips name references...
141  if (it->second->getObjectName() == "Name") continue;
142 
143  if (it->second->getObjectType() == "Function") continue;
144 
145  //skip if the contained object is not owned by this container
146  if (it->second->getObjectParent() != container) continue;
147 
148  writeDotRecursively(it->second, os);
149  }
150 
151  //return;
152  }
153 }
bool isContainer() const
void findObjectsWithUpdateMethod(const CCopasiObject *obj, std::set< const CCopasiObject * > &objectSet, size_t recursion=0) const
Definition: CDotOutput.cpp:74
virtual const objectMap & getObjects() const
void writeEdge(std::ostream &os, const CCopasiObject *ptr1, const CCopasiObject *ptr2, bool indirect=false)
Definition: CDotOutput.cpp:189
bool mSkipCompartments
Definition: CDotOutput.h:74
void writeDotRecursively(const CCopasiObject *obj, std::ostream &os)
Definition: CDotOutput.cpp:93
bool hasUpdateMethod() const
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
bool mOnlyAlgebraicDependencies
Definition: CDotOutput.h:75
void CDotOutput::writeEdge ( std::ostream &  os,
const CCopasiObject ptr1,
const CCopasiObject ptr2,
bool  indirect = false 
)
protected

Definition at line 189 of file CDotOutput.cpp.

References CCopasiObject::getObjectDisplayName(), and mObjects.

Referenced by writeDotRecursively().

190 {
191  assert(ptr1);
192  assert(ptr2);
193 
194  mObjects[ptr1];
195  mObjects[ptr2];
196 
197  os << "\"" << ptr1->getObjectDisplayName() << "\" -> \"" << ptr2->getObjectDisplayName() << "\"";
198 
199  if (indirect) os << " [color=blue]";
200 
201  os << "\n";
202 }
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
std::map< const CCopasiObject *, ObjectData > mObjects
Definition: CDotOutput.h:77
void CDotOutput::writeObjectNode ( std::ostream &  os,
const CCopasiObject ptr,
const ObjectData od 
) const
protected

Definition at line 155 of file CDotOutput.cpp.

References C_INVALID_INDEX, CCopasiObject::getObjectDisplayName(), CCopasiObject::getRefresh(), CCopasiObject::hasUpdateMethod(), CDotOutput::ObjectData::mConstantRefreshesIndex, CDotOutput::ObjectData::mInUpToDateList, CDotOutput::ObjectData::mNonSimulatedRefreshesIndex, and CDotOutput::ObjectData::mSimulatedRefreshesIndex.

Referenced by writeDependencies().

156 {
157  os << "//" << std::endl;
158 
159  bool flagUM = ptr->hasUpdateMethod();
160  bool flagRM = ptr->getRefresh() != NULL;
161  bool flagInUpToDateList = od.mInUpToDateList;
162 
163  std::ostringstream oss;
164 
165  if (od.mSimulatedRefreshesIndex != C_INVALID_INDEX)
166  oss << "SR=" << od.mSimulatedRefreshesIndex << " ";
167 
168  if (od.mNonSimulatedRefreshesIndex != C_INVALID_INDEX)
169  oss << "NSR=" << od.mNonSimulatedRefreshesIndex << " ";
170 
171  if (od.mConstantRefreshesIndex != C_INVALID_INDEX)
172  oss << "CR=" << od.mConstantRefreshesIndex << " ";
173 
174  os << "\"" << ptr->getObjectDisplayName() << "\" [shape=plaintext, color=blue, " << std::endl;
175  os << "label=<\n";
176  os << "<TABLE CELLSPACING=\"0\">\n";
177  os << " <TR><TD COLSPAN=\"4\">" << ptr->getObjectDisplayName() << "</TD></TR>\n";
178  os << " <TR>\n";
179  os << " <TD " << (flagUM ? "BGCOLOR=\"red\"" : " ") << "><FONT POINT-SIZE=\"7.0\">UM</FONT>" << "" << "</TD>\n";
180  os << " <TD " << (flagRM ? "BGCOLOR=\"green\"" : " ") << "><FONT POINT-SIZE=\"7.0\">RM</FONT>" << "" << "</TD>\n";
181  os << " <TD " << (flagInUpToDateList ? "BGCOLOR=\"blue\"" : " ") << "><FONT POINT-SIZE=\"7.0\">UtD</FONT>" << "" << "</TD>\n";
182  os << " <TD><FONT POINT-SIZE=\"7.0\">" << oss.str() << " </FONT></TD>\n";
183  os << " </TR>\n";
184  os << "</TABLE>\n";
185  os << "\n";
186  os << ">];\n";
187 }
virtual Refresh * getRefresh() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define C_INVALID_INDEX
Definition: copasi.h:222
bool hasUpdateMethod() const

Member Data Documentation

std::map<const CCopasiObject*, ObjectData> CDotOutput::mObjects
protected
bool CDotOutput::mOnlyAlgebraicDependencies
protected

Definition at line 75 of file CDotOutput.h.

Referenced by setOnlyAlgebraicDependencies(), and writeDotRecursively().

bool CDotOutput::mSkipCompartments
protected

Definition at line 74 of file CDotOutput.h.

Referenced by setSkipDependenciesOnCompartments(), and writeDotRecursively().


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