/**
  * A subgraph is calculated based on the participants collected based on the given node ids.
  *
  * @param array $ids
  *   The nodes interested in.
  * @return DirectedGraph
  *   The subgraph with all participants
  */
 public function subGraph($ids = array())
 {
     $g = new DirectedGraph();
     $participants = $this->getParticipants($ids);
     foreach ($participants as $id) {
         $g->addNode($id);
         // Only participating links are added.
         $links = $this->getLinks($id);
         if (is_array($links)) {
             $g->addLinks($id, array_intersect($participants, $links));
         }
     }
     return $g;
 }
 /**
  * Converts a DirectedGraph into a DirectedAcyclicGraph.
  *
  * A DirectedGraph can be converted into a DirectedAcyclicGraph when
  * is does not contain any cycle.
  *
  * @param \GraphAPI\Component\Graph\DirectedGraph $g
  * @param type $ignore_exception
  * @throws \GraphAPI\Component\Graph\Exception
  */
 static function fromDirectedGraph(DirectedGraph $g, $ignore_exception = FALSE)
 {
     $d = new DirectedAcyclicGraph();
     foreach ($g->getNodeIds() as $id) {
         $links = $g->getLinks($id);
         foreach ($links as $link) {
             try {
                 $d->addLink($id, $link);
             } catch (\Exception $exc) {
                 if (!$ignore_exception) {
                     throw $exc;
                 }
             }
         }
     }
     return $d;
 }
Exemplo n.º 3
0
function dumpReverse(DirectedGraph $g)
{
    echo "\nReversed: " . $g->getReversedGraph() . "\n";
}