COPASI API  4.16.103
CDependencyGraph.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CDependencyGraph.cpp,v $
3 // $Revision: 1.22 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:34:54 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include "copasi.h"
24 #include "CDependencyGraph.h"
25 #include <algorithm>
26 
27 // node
28 
30  mDependents()
31 {}
32 
34 {}
35 
36 void CDependencyGraphNode::addDependent(const size_t & node_num)
37 {
38  // Ensure that the same node is not added twice
39  // if (find(mDependents.begin(), mDependents.end(), node_num) == mDependents.end())
40  // {
41  // mDependents.push_back(node_num);
42  //}
43  mDependents.insert(node_num);
44 }
45 
46 const std::set <size_t> & CDependencyGraphNode::getDependents() const
47 {
48  return mDependents;
49 }
50 
51 // dependency graph
54 
55 void CDependencyGraph::addNode(const size_t & node)
56 {
57  if (node >= mNodes.size())
58  mNodes.resize(node + 1);
59 
60  // mNodes.push_back(node);
61 }
62 
63 void CDependencyGraph::resize(const size_t & n)
64 {
65  mNodes.resize(n);
66 }
67 
68 void CDependencyGraph::addDependent(const size_t & node, const size_t & dependent)
69 {
70  addNode(node);
71  mNodes[node].addDependent(dependent);
72 }
73 
74 const std::set <size_t> & CDependencyGraph::getDependents(const size_t & node) const
75 {
76  static std::set< size_t > NoDependents;
77 
78  if (mNodes.size() <= node)
79  {
80  return NoDependents;
81  }
82 
83  return mNodes[node].getDependents();
84 }
85 
87 {mNodes.clear();}
88 
89 std::ostream & operator<<(std::ostream &os,
90  const CDependencyGraphNode & d)
91 {
92  std::set <size_t>::const_iterator it;
93 
94  for (it = d.mDependents.begin(); it != d.mDependents.end(); it++)
95  os << *it << " ";
96 
97  os << std::endl;
98 
99  return os;
100 }
101 
102 std::ostream & operator<<(std::ostream &os,
103  const CDependencyGraph & d)
104 {
105  unsigned int i;
106 
107  for (i = 0; i < d.mNodes.size(); i++)
108  os << d.mNodes[i];
109 
110  os << std::endl;
111 
112  return os;
113 }
void addNode(const size_t &node)
void addDependent(const size_t &node, const size_t &dependent)
const std::set< size_t > & getDependents(const size_t &node) const
void addDependent(const size_t &node_num)
void resize(const size_t &n)
std::set< size_t > mDependents
std::vector< CDependencyGraphNode > mNodes
const std::set< size_t > & getDependents() const
std::ostream & operator<<(std::ostream &os, const CDependencyGraphNode &d)