/** * Adds vertex to a graph. If vertex with the same id already exists, * throws and exception * @param Vertex $vertex * @throws \Exception */ public function addVertex(Vertex $vertex) { $id = $vertex->getId(); if (array_key_exists($id, $this->vertices)) { throw new \Exception('Vertex with ID="' . $id . '" already exists'); } $this->vertices[$id] = $vertex; }