Example #1
0
File: Loop.php Project: feffi/graph
 /**
  * checks whether this vertex has a loop (edge to itself)
  *
  * @return boolean
  * @uses Edge::isLoop()
  */
 public function hasLoopVertex(Vertex $vertex)
 {
     foreach ($vertex->getEdges() as $edge) {
         if ($edge->isLoop()) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param Vertex $vertex
  * @return \Fhaculty\Graph\Edge\Directed
  */
 private function createEdgeToAdtRootVertexBy(Vertex $vertex)
 {
     foreach ($this->adtRootVertex->getEdges() as $edge) {
         /** @var \Fhaculty\Graph\Edge\Directed $edge */
         if ($edge->isConnection($this->adtRootVertex, $vertex)) {
             return $edge;
         }
     }
     return $this->adtRootVertex->createEdgeTo($vertex);
 }
Example #3
0
File: Flow.php Project: feffi/graph
 /**
  * Calculates the flow for this Vertex: sum(outflow) - sum(inflow)
  *
  * Usually, vertices should have a resulting flow of 0: The sum of flows
  * entering a vertex must equal the sum of flows leaving a vertex. If the
  * resulting flow is < 0, this vertex is considered a sink (i.e. there's
  * more flow into this vertex). If the resulting flow is > 0, this vertex
  * is considered a "source" (i.e. there's more flow leaving this vertex).
  *
  * @param Vertex $vertex
  * @return float
  * @throws UnexpectedValueException if they are undirected edges
  * @see Vertex::getBalance()
  * @uses Vertex::getEdges()
  * @uses Edge::getFlow()
  */
 public function getFlowVertex(Vertex $vertex)
 {
     $sumOfFlow = 0;
     foreach ($vertex->getEdges() as $edge) {
         if (!$edge instanceof EdgeDirected) {
             throw new UnexpectedValueException("TODO: undirected edges not suported yet");
         }
         // edge is an outgoing edge of this vertex
         if ($edge->hasVertexStart($vertex)) {
             // flowing out (flow is "pointing away")
             $sumOfFlow += $edge->getFlow();
             // this is an ingoing edge
         } else {
             // flowing in
             $sumOfFlow -= $edge->getFlow();
         }
     }
     return $sumOfFlow;
 }
Example #4
0
 /**
  * get neighbor vertices for given start vertex
  *
  * @param Vertex $vertex
  * @throws UnexpectedValueException for directed edges
  * @return Vertices (might include possible duplicates)
  * @uses Vertex::getEdges()
  * @uses Edge::getVertexToFrom()
  * @see Vertex::getVerticesEdge()
  */
 private function getVerticesNeighbor(Vertex $vertex)
 {
     $vertices = array();
     foreach ($vertex->getEdges() as $edge) {
         /* @var Edge $edge */
         if (!$edge instanceof UndirectedEdge) {
             throw new UnexpectedValueException('Directed edge encountered');
         }
         $vertices[] = $edge->getVertexToFrom($vertex);
     }
     return new Vertices($vertices);
 }
Example #5
0
 /**
  * get outdegree of this vertex (number of edges FROM this vertex TO other vertices)
  *
  * @param Vertex $vertex
  * @return int
  * @uses Edge::hasVertexStart()
  * @see self::getDegreeVertex()
  */
 public function getDegreeOutVertex(Vertex $vertex)
 {
     $n = 0;
     foreach ($vertex->getEdges() as $edge) {
         if ($edge->hasVertexStart($vertex)) {
             ++$n;
         }
     }
     return $n;
 }