Beispiel #1
0
 public function testCloneDoubleInvertedIsOriginal()
 {
     $edgeInverted = $this->edge->createEdgeCloneInverted();
     $this->assertInstanceOf(get_class($this->edge), $edgeInverted);
     $edge = $edgeInverted->createEdgeCloneInverted();
     $this->assertEdgeEquals($this->edge, $edge);
 }
Beispiel #2
0
 /**
  * Will merge all edges that are parallel to to given edge
  *
  * @param Edge $newEdge
  */
 private function mergeParallelEdges(Edge $newEdge)
 {
     $parallelEdges = $newEdge->getEdgesParallel();
     if ($parallelEdges) {
         $mergedCapacity = 0;
         foreach ($parallelEdges as $parallelEdge) {
             $mergedCapacity += $parallelEdge->getCapacity();
         }
         $newEdge->setCapacity($newEdge->getCapacity() + $mergedCapacity);
         foreach ($parallelEdges as $parallelEdge) {
             $parallelEdge->destroy();
         }
     }
 }
Beispiel #3
0
 /**
  * get set of all Edges parallel to this edge (excluding self)
  *
  * @param Edge $edge
  * @return Edges
  * @throws LogicException
  */
 public function getEdgesParallelEdge(Edge $edge)
 {
     if ($edge instanceof DirectedEdge) {
         // get all edges between this edge's endpoints
         $edges = $edge->getVertexStart()->getEdgesTo($edge->getVertexEnd())->getVector();
     } else {
         // edge points into both directions (undirected/bidirectional edge)
         // also get all edges in other direction
         $ends = $edge->getVertices();
         $edges = $ends->getVertexFirst()->getEdges()->getEdgesIntersection($ends->getVertexLast()->getEdges())->getVector();
     }
     $pos = array_search($edge, $edges, true);
     if ($pos === false) {
         // @codeCoverageIgnoreStart
         throw new LogicException('Internal error: Current edge not found');
         // @codeCoverageIgnoreEnd
     }
     // exclude current edge from parallel edges
     unset($edges[$pos]);
     return new Edges(array_values($edges));
 }
Beispiel #4
0
 /**
  * get label for given $edge
  *
  * @param Edge $edge
  * @return string label (may be empty if there's nothing to be described)
  */
 protected function getEdgeLabel(Edge $edge)
 {
     $label = '';
     $flow = $edge->getFlow();
     $capacity = $edge->getCapacity();
     // flow is set
     if ($flow !== NULL) {
         // NULL capacity = infinite capacity
         $label = $flow . '/' . ($capacity === NULL ? '∞' : $capacity);
         // capacity set, but not flow (assume zero flow)
     } elseif ($capacity !== NULL) {
         $label = '0/' . $capacity;
     }
     $weight = $edge->getWeight();
     // weight is set
     if ($weight !== NULL) {
         if ($label === '') {
             $label = $weight;
         } else {
             $label .= '/' . $weight;
         }
     }
     return $label;
 }
Beispiel #5
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testFlowMustBePositive()
 {
     $this->edge->setFlow(-10);
 }
Beispiel #6
0
 /**
  * Extracts inverted edge from this graph
  *
  * @param  Edge               $edge
  * @return Edge
  * @throws UnderflowException if no edge was found
  * @throws OverflowException  if multiple edges match
  */
 public function getEdgeCloneInverted(Edge $edge)
 {
     // Extract endpoints from edge
     $vertices = $edge->getVertices()->getVector();
     return $this->getEdgeCloneInternal($edge, $vertices[1], $vertices[0]);
 }
Beispiel #7
0
 protected function getLayoutEdge(Edge $edge)
 {
     $layout = $edge->getLayout();
     // use flow/capacity/weight as edge label
     $label = NULL;
     $flow = $edge->getFlow();
     $capacity = $edge->getCapacity();
     // flow is set
     if ($flow !== NULL) {
         // NULL capacity = infinite capacity
         $label = $flow . '/' . ($capacity === NULL ? '∞' : $capacity);
         // capacity set, but not flow (assume zero flow)
     } elseif ($capacity !== NULL) {
         $label = '0/' . $capacity;
     }
     $weight = $edge->getWeight();
     // weight is set
     if ($weight !== NULL) {
         if ($label === NULL) {
             $label = $weight;
         } else {
             $label .= '/' . $weight;
         }
     }
     if ($label !== NULL) {
         if (isset($layout['label'])) {
             $layout['label'] .= ' ' . $label;
         } else {
             $layout['label'] = $label;
         }
     }
     return $layout;
 }