MUQ  0.4.3
WorkGraph.h
Go to the documentation of this file.
1 #ifndef WORKGRAPH_H_
2 #define WORKGRAPH_H_
3 
5 
6 #include <boost/graph/adjacency_list.hpp>
7 #include <boost/graph/filtered_graph.hpp>
8 
9 #include <memory>
10 
11 namespace muq {
12  namespace Modeling {
13 
14  class WorkGraphPiece;
15  class WorkPiece;
16  class ConstantPiece;
17  class ModGraphPiece;
18 
20  class WorkGraph {
21  public:
22  friend class WorkGraphPiece;
23  friend class ModGraphPiece;
24 
25  WorkGraph();
26 
27  virtual ~WorkGraph();
28 
29  virtual std::shared_ptr<WorkGraph> Clone() const;
30 
32 
35  unsigned int NumNodes() const;
36 
38 
41  unsigned int NumEdges() const;
42 
44 
48  void AddNode(std::shared_ptr<WorkPiece> input, std::string const& name);
49 
50  void RemoveNode(std::string const& name);
51 
53 
59  void AddEdge(std::string const& nameFrom, unsigned int const outputDim, std::string const& nameTo, unsigned int const inputDim);
60 
62 
66  bool HasNode(std::string const& name) const;
67 
74  std::vector<std::pair<int,int>> GetEdges(std::string const& srcName, std::string const& tgtName);
75 
77 
80  void Visualize(std::string const& filename) const;
81 
85  std::vector<std::string> GetParents(std::string const& name) const;
86 
88  std::string GetParent(std::string const& name, int inputIndex) const;
89 
93  std::vector<std::string> GetChildren(std::string const& name) const;
94 
96 
100  std::shared_ptr<WorkGraph> DependentCut(std::string const& nameOut) const;
101 
103 
107  std::shared_ptr<WorkGraphPiece> CreateWorkPiece(std::string const& node) const;
108 
110 
115  std::shared_ptr<ModGraphPiece> CreateModPiece(std::string const& node, std::vector<std::string> const& inNames = std::vector<std::string>()) const;
116 
118 
123  bool Constant(std::string const& node) const;
124 
126 
130  std::vector<boost::any> const& GetConstantOutputs(std::string const& node) const;
131 
133  std::shared_ptr<WorkPiece> GetPiece(std::string const& name);
134 
136  std::string GetName(std::shared_ptr<WorkPiece> piece) const;
137 
138 
140  void Print(std::ostream& fout=std::cout) const;
141 
143 
146  std::vector<std::pair<std::string, int> > GetInputNames() const;
147 
149 
152  std::vector<std::pair<std::string, int> > GetOutputNames() const;
153 
163  void BindNode(std::string const& nodeName,
164  std::vector<boost::any> const& x);
165 
175  void BindEdge(std::string const& nodeName,
176  unsigned int inputDim,
177  boost::any const& x);
178 
179  private:
180 
182 
186  std::vector<boost::any>& GetConstantOutputs(boost::graph_traits<Graph>::vertex_descriptor const& node) const;
187 
189 
194  bool Constant(boost::graph_traits<Graph>::vertex_descriptor const& node) const;
195 
196  std::shared_ptr<WorkPiece> GetPiece(boost::graph_traits<Graph>::vertex_descriptor it);
197 
199 
205  void RecursiveCut(const boost::graph_traits<Graph>::vertex_descriptor& vOld, const boost::graph_traits<Graph>::vertex_descriptor& vNew, std::shared_ptr<WorkGraph>& newGraph) const;
206 
208 
213  bool HasNode(boost::graph_traits<Graph>::vertex_iterator& iter, std::string const& name) const;
214 
216 
222  bool HasEdge(boost::graph_traits<Graph>::vertex_descriptor const& vOut, boost::graph_traits<Graph>::vertex_descriptor const& vIn, int const inputDim) const;
223 
225 
229  boost::graph_traits<Graph>::vertex_iterator GetNodeIterator(std::string const& name) const;
230  boost::graph_traits<Graph>::vertex_iterator GetNodeIterator(std::shared_ptr<WorkPiece> piece) const;
231 
233 
236  std::vector<std::pair<boost::graph_traits<Graph>::vertex_descriptor, int> > GraphInputs() const;
237 
239 
242  std::vector<std::pair<boost::graph_traits<Graph>::vertex_descriptor, int> > GraphOutputs() const;
243 
246  };
247  } // namespace Modeling
248 } // namespace muq
249 
250 #endif
A muq::Modeling::ModPiece created from a muq::Modeling::WorkGraph.
Definition: ModGraphPiece.h:23
A muq::Modeling::WorkPiece created from a muq::Modeling::WorkGraph.
A graph of connected muq::Modeling::WorkPiece's.
Definition: WorkGraph.h:20
std::vector< std::pair< std::string, int > > GetOutputNames() const
Find the outputs to the graph.
Definition: WorkGraph.cpp:164
void AddNode(std::shared_ptr< WorkPiece > input, std::string const &name)
Add a new node to the graph.
Definition: WorkGraph.cpp:195
void AddEdge(std::string const &nameFrom, unsigned int const outputDim, std::string const &nameTo, unsigned int const inputDim)
Add a new edge to the graph.
Definition: WorkGraph.cpp:206
unsigned int NumEdges() const
Get the number of edgess in the graph.
Definition: WorkGraph.cpp:92
std::shared_ptr< WorkGraph > DependentCut(std::string const &nameOut) const
Create a new graph cutting any of the nodes that do not affect the output node.
Definition: WorkGraph.cpp:477
virtual std::shared_ptr< WorkGraph > Clone() const
Definition: WorkGraph.cpp:54
Graph graph
The directed graph that represents this muq::Modeling::Core::WorkGraph.
Definition: WorkGraph.h:245
std::shared_ptr< ModGraphPiece > CreateModPiece(std::string const &node, std::vector< std::string > const &inNames=std::vector< std::string >()) const
Create a muq::Modeling::ModPiece whose output matches a given node.
Definition: WorkGraph.cpp:591
std::shared_ptr< WorkPiece > GetPiece(std::string const &name)
Definition: WorkGraph.cpp:720
void RemoveNode(std::string const &name)
Definition: WorkGraph.cpp:61
void BindEdge(std::string const &nodeName, unsigned int inputDim, boost::any const &x)
Definition: WorkGraph.cpp:777
std::string GetParent(std::string const &name, int inputIndex) const
Definition: WorkGraph.cpp:120
std::vector< std::pair< std::string, int > > GetInputNames() const
Find the inputs to the graph.
Definition: WorkGraph.cpp:153
std::string GetName(std::shared_ptr< WorkPiece > piece) const
Definition: WorkGraph.cpp:749
bool HasEdge(boost::graph_traits< Graph >::vertex_descriptor const &vOut, boost::graph_traits< Graph >::vertex_descriptor const &vIn, int const inputDim) const
Is there an edge between two vertices?
Definition: WorkGraph.cpp:388
void Print(std::ostream &fout=std::cout) const
Definition: WorkGraph.cpp:697
void Visualize(std::string const &filename) const
Visualize the graph.
Definition: WorkGraph.cpp:857
boost::graph_traits< Graph >::vertex_iterator GetNodeIterator(std::string const &name) const
Get a vertex_iterator to the node with name "name".
Definition: WorkGraph.cpp:258
void RecursiveCut(const boost::graph_traits< Graph >::vertex_descriptor &vOld, const boost::graph_traits< Graph >::vertex_descriptor &vNew, std::shared_ptr< WorkGraph > &newGraph) const
Recursively go upstream from a node, copying nodes.
Definition: WorkGraph.cpp:402
std::shared_ptr< WorkGraphPiece > CreateWorkPiece(std::string const &node) const
Create a muq::Modeling::WorkPiece whose output matches a given node.
Definition: WorkGraph.cpp:523
std::vector< std::string > GetChildren(std::string const &name) const
Definition: WorkGraph.cpp:137
std::vector< std::pair< int, int > > GetEdges(std::string const &srcName, std::string const &tgtName)
Returns all edges going from node name1 to node name2.
Definition: WorkGraph.cpp:69
std::vector< boost::any > const & GetConstantOutputs(std::string const &node) const
Get the output values for a constant node.
Definition: WorkGraph.cpp:936
std::vector< std::pair< boost::graph_traits< Graph >::vertex_descriptor, int > > GraphInputs() const
Find the inputs to the graph.
Definition: WorkGraph.cpp:335
std::vector< std::pair< boost::graph_traits< Graph >::vertex_descriptor, int > > GraphOutputs() const
Find the outputs to the graph.
Definition: WorkGraph.cpp:282
std::vector< std::string > GetParents(std::string const &name) const
Definition: WorkGraph.cpp:98
void BindNode(std::string const &nodeName, std::vector< boost::any > const &x)
Definition: WorkGraph.cpp:754
unsigned int NumNodes() const
Get the number of nodes in the graph.
Definition: WorkGraph.cpp:86
bool Constant(std::string const &node) const
Check to see if a node is constant?
Definition: WorkGraph.cpp:1002
bool HasNode(std::string const &name) const
Is the given node in the graph?
Definition: WorkGraph.cpp:177
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, std::shared_ptr< WorkGraphNode >, std::shared_ptr< WorkGraphEdge > > Graph
Define a directed graph type.