Example #1
0
 /**
  * create a new directed Edge from Vertex $from to Vertex $to
  *
  * @param Vertex $from start/source Vertex
  * @param Vertex $to   end/target Vertex
  * @see Vertex::createEdgeTo() to create directed edges
  * @see Vertex::createEdge() to create undirected edges
  */
 public function __construct(Vertex $from, Vertex $to)
 {
     if ($from->getGraph() !== $to->getGraph()) {
         throw new InvalidArgumentException('Vertices have to be within the same graph');
     }
     $this->from = $from;
     $this->to = $to;
     $from->getGraph()->addEdge($this);
     $from->addEdge($this);
     $to->addEdge($this);
 }
Example #2
0
 /**
  * create a new undirected edge between given vertices
  *
  * @param Vertex $a
  * @param Vertex $b
  * @see Vertex::createEdge() instead
  */
 public function __construct(Vertex $a, Vertex $b)
 {
     if ($a->getGraph() !== $b->getGraph()) {
         throw new InvalidArgumentException('Vertices have to be within the same graph');
     }
     $this->a = $a;
     $this->b = $b;
     $a->getGraph()->addEdge($this);
     $a->addEdge($this);
     $b->addEdge($this);
 }