5 #ifndef BPP_GRAPH_DAGRAPHIMPL_H 6 #define BPP_GRAPH_DAGRAPHIMPL_H 13 #include "../Exceptions.h" 14 #include "../Numeric/VectorTools.h" 20 template<
class GraphImpl>
213 template<
class GraphImpl>
221 template<
class GraphImpl>
228 template<
class GraphImpl>
237 for ( ; !allIt->end(); allIt->next())
251 template<
class GraphImpl>
254 return GraphImpl::isLeaf(node);
257 template<
class GraphImpl>
260 return GraphImpl::getNumberOfIncomingNeighbors(node) >= 1;
263 template<
class GraphImpl>
269 template<
class GraphImpl>
272 return GraphImpl::getNumberOfIncomingNeighbors(node);
275 template<
class GraphImpl>
278 GraphImpl::link(fatherNode, node);
283 template<
class GraphImpl>
286 GraphImpl::link(fatherNode, node, edge);
291 template<
class GraphImpl>
294 std::vector<Graph::NodeId> fathers =
getFathers(node);
295 for (std::vector<Graph::NodeId>::iterator currFather = fathers.begin(); currFather != fathers.end(); currFather++)
302 template<
class GraphImpl>
308 GraphImpl::unlink(father, node);
311 template<
class GraphImpl>
314 std::vector<Graph::NodeId> foundLeaves;
320 template<
class GraphImpl>
323 const std::vector<Graph::NodeId> sons =
getSons(startingNode);
326 for (std::vector<Graph::NodeId>::const_iterator currNeighbor = sons.begin(); currNeighbor != sons.end(); currNeighbor++)
333 foundLeaves.push_back(startingNode);
337 template<
class GraphImpl>
341 throw Exception(
"DAGraphImpl<GraphImpl>: The DAG must be rooted.");
344 template<
class GraphImpl>
348 throw Exception(
"DAGraphImpl<GraphImpl>: The DAG is not valid.");
352 template<
class GraphImpl>
359 template<
class GraphImpl>
366 template<
class GraphImpl>
369 return GraphImpl::getOutgoingNeighbors(node);
372 template<
class GraphImpl>
375 return GraphImpl::getNumberOfOutgoingNeighbors(node);
378 template<
class GraphImpl>
381 GraphImpl::link(node, sonNode);
385 template<
class GraphImpl>
388 GraphImpl::link(node, sonNode, edge);
393 template<
class GraphImpl>
396 std::vector<Graph::NodeId> sons =
getSons(node);
397 for (std::vector<Graph::NodeId>::iterator currSon = sons.begin(); currSon != sons.end(); currSon++)
405 template<
class GraphImpl>
408 GraphImpl::unlink(node, son);
412 template<
class GraphImpl>
415 GraphImpl::setRoot(newRoot);
422 GraphImpl::orientate();
428 template<
class GraphImpl>
431 std::vector<Graph::NodeId> vFat =
getFathers(node);
439 GraphImpl::switchNodes(fat, node);
444 template<
class GraphImpl>
448 std::vector<Graph::EdgeId> metNodes;
453 template<
class GraphImpl>
457 std::vector<Graph::EdgeId> metEdges;
463 template<
class GraphImpl>
466 metNodes.push_back(localRoot);
467 std::vector<Graph::NodeId> sons = GraphImpl::getOutgoingNeighbors(localRoot);
468 for (std::vector<Graph::NodeId>::iterator currSon = sons.begin(); currSon != sons.end(); currSon++)
474 template<
class GraphImpl>
477 std::vector<Graph::EdgeId> edgesToSons = GraphImpl::getOutgoingEdges(localRoot);
478 for (std::vector<Graph::EdgeId>::iterator currEdgeToSon = edgesToSons.begin(); currEdgeToSon != edgesToSons.end(); currEdgeToSon++)
480 metEdges.push_back(*currEdgeToSon);
485 #endif // BPP_GRAPH_DAGRAPHIMPL_H void mustBeValid_() const
std::vector< Graph::NodeId > getLeavesUnderNode(Graph::NodeId node) const
virtual std::unique_ptr< NodeIterator > allNodesIterator()=0
std::vector< Graph::NodeId > getFathers(Graph::NodeId nodeid) const
void addFather(Graph::NodeId node, Graph::NodeId father)
std::vector< Graph::NodeId > getSons(Graph::NodeId node) const
void removeFather(Graph::NodeId node, Graph::NodeId father)
size_t getNumberOfSons(Graph::NodeId node) const
Get the number of sons node.
void fillSubtreeMetEdges_(std::vector< Graph::EdgeId > &metEdges, Graph::NodeId localRoot) const
void propagateDirection_(Graph::NodeId node)
bool isLeaf(Graph::NodeId node) const
void fillListOfLeaves_(Graph::NodeId startingNode, std::vector< Graph::NodeId > &foundLeaves) const
virtual std::vector< NodeId > getIncomingNeighbors(NodeId node) const =0
std::vector< Graph::NodeId > getBelowNodes(Graph::NodeId localRoot) const
void addSon(Graph::NodeId node, Graph::NodeId sonNode)
void orientGraphFrom_(std::set< Graph::NodeId > &metNodes, Graph::NodeId localRoot)
std::vector< Graph::NodeId > removeFathers(Graph::NodeId node)
std::vector< Graph::EdgeId > getBelowEdges(Graph::NodeId localRoot) const
void rootAt(Graph::NodeId newRoot)
virtual void topologyHasChanged_() const
void removeSon(Graph::NodeId node, Graph::NodeId son)
void mustBeRooted_() const
size_t getNumberOfFathers(Graph::NodeId node) const
Get the number of fathers nodes.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
bool hasFather(Graph::NodeId node) const
DAGraphImpl< GlobalGraph > DAGlobalGraph
std::vector< Graph::NodeId > removeSons(Graph::NodeId node)
virtual size_t getNumberOfIncomingNeighbors(const NodeId node) const =0
void fillSubtreeMetNodes_(std::vector< Graph::NodeId > &metNodes, Graph::NodeId localRoot) const