22 #ifndef SINGA_UTILS_GRAPH_H_
23 #define SINGA_UTILS_GRAPH_H_
39 explicit Node(std::string name);
49 Node(
const std::string& name,
const std::string&
origin,
int id,
void*
proto);
51 void AddDstNode(
Node* dstnode);
52 void AddSrcNode(
Node* srcnode);
53 void RemoveDstNode(
Node* dst);
54 void RemoveSrcNode(
Node* src);
56 std::string name =
"";
58 std::string origin =
"";
62 void* proto =
nullptr;
63 std::vector<Node*> srcnodes;
64 std::vector<Node*> dstnodes;
79 inline const std::vector<Node*>&
nodes()
const {
86 inline Node*
node(
const std::string& name)
const {
87 return name2node_.at(name);
90 Node* AddNode(
const std::string& name);
91 void AddEdge(
Node* srcnode,
Node* dstnode);
92 void AddEdge(
const std::string& src,
const std::string& dst);
93 void RemoveEdge(
Node* src,
Node* dst);
94 void RemoveEdge(
const std::string &src,
const std::string& dst);
99 std::string
ToJson()
const;
105 std::string
ToJson(
const std::map<std::string, std::string>& info)
const;
112 std::vector<Node*> nodes_;
113 std::map<std::string, Node*> name2node_;
118 #endif // SINGA_UTILS_GRAPH_H_
int partition_id
partition id
Definition: graph.h:60
std::string origin
name of the origin node/layer from which is node is derived
Definition: graph.h:58
void * proto
proto of the corresponding layer
Definition: graph.h:62
const std::vector< Node * > & nodes() const
Definition: graph.h:79
Node(std::string name)
Node constructor.
void Sort()
Do topology sort for all nodes of the graph.
Neuralnet is constructed by creating a graph with each node representing one layer at first...
Definition: graph.h:72
Node * node(const std::string &name) const
Definition: graph.h:86
std::string ToJson() const
Dump the graph into json string which can be used to draw a picture by graphviz.