Example #1
0
 /**
  * create new Vertices instance
  *
  * You can pass in just about anything that can be expressed as a Set of
  * Vertices, such as:
  * - an array of Vertex instances
  * - any Algorithm that implements the VerticesAggregate interface
  * - a Graph instance or
  * - an existing Set of Vertices which will be returned as-is
  *
  * @param array|Vertices|VerticesAggregate $vertices
  * @return Vertices
  */
 public static function factory($vertices)
 {
     if ($vertices instanceof VerticesAggregate) {
         return $vertices->getVertices();
     }
     return new self($vertices);
 }
Example #2
0
 public function testGraphTree()
 {
     $graph = $this->createGraphTree();
     $root = $graph->getVertices()->getVertexFirst();
     $nonRoot = $graph->getVertices()->getMap();
     unset($nonRoot[$root->getId()]);
     $nonRoot = new Vertices($nonRoot);
     $c1 = $nonRoot->getVertexFirst();
     $tree = $this->createTreeAlg($graph);
     $this->assertTrue($tree->isTree());
     $this->assertSame($root, $tree->getVertexRoot());
     $this->assertSame($graph->getVertices()->getVector(), $tree->getVerticesSubtree($root)->getVector());
     $this->assertSame($nonRoot->getVector(), $tree->getVerticesChildren($root)->getVector());
     $this->assertSame($nonRoot->getVector(), $tree->getVerticesDescendant($root)->getVector());
     $this->assertSame($nonRoot->getVector(), $tree->getVerticesLeaf()->getVector());
     $this->assertSame(array(), $tree->getVerticesInternal()->getVector());
     $this->assertSame($root, $tree->getVertexParent($c1));
     $this->assertSame(array(), $tree->getVerticesChildren($c1)->getVector());
     $this->assertSame(array(), $tree->getVerticesDescendant($c1)->getVector());
     $this->assertSame(array($c1), $tree->getVerticesSubtree($c1)->getVector());
     $this->assertEquals(2, $tree->getDegree());
     $this->assertEquals(0, $tree->getDepthVertex($root));
     $this->assertEquals(1, $tree->getDepthVertex($c1));
     $this->assertEquals(1, $tree->getHeight());
     $this->assertEquals(1, $tree->getHeightVertex($root));
     $this->assertEquals(0, $tree->getHeightvertex($c1));
     return $tree;
 }
Example #3
0
 /**
  * Outputs a file of the visited tables in order
  *
  * @param Vertices $vertices
  */
 protected function outputVertices(Vertices $vertices)
 {
     if (!$this->exportConstraints) {
         return;
     }
     $path = $this->fileFactory->getPathForFile('constraints', 'txt');
     $this->logger->info('Outputting constraint text to {path}', ['path' => $path]);
     file_put_contents($path, implode("\n", $vertices->getIds()));
 }
Example #4
0
 public function testFactoryEmptyArray()
 {
     $vertices = Vertices::factory(array());
     $this->assertInstanceOf('Fhaculty\\Graph\\Set\\Vertices', $vertices);
     $this->assertTrue($vertices->isEmpty());
 }
Example #5
0
 /**
  * create a new clone/copy of this graph - copy all attributes and given vertices and its edges
  *
  * @param  Vertices $vertices set of vertices to keep
  * @return Graph
  * @uses Graph::createGraphClone() to create a complete clone
  * @uses Vertex::destroy() to remove unneeded vertices again
  */
 public function createGraphCloneVertices($vertices)
 {
     $verticesKeep = Vertices::factory($vertices);
     $graph = $this->createGraphClone();
     foreach ($graph->getVertices()->getMap() as $vid => $vertex) {
         if (!$verticesKeep->hasVertexId($vid)) {
             $vertex->destroy();
         }
     }
     return $graph;
 }
Example #6
0
 /**
  *
  * @param Vertices $verticesTwo
  * @param Vertices $verticesEmpty
  * @depends testTwo
  * @depends testEmpty
  */
 public function testTwoIntersectionEmpty(Vertices $verticesTwo, Vertices $verticesEmpty)
 {
     $verticesIntersection = $verticesTwo->getVerticesIntersection($verticesEmpty);
     $this->assertCount(0, $verticesIntersection);
 }
Example #7
0
 /**
  * get alternating sequence of vertex, edge, vertex, edge, ..., vertex
  *
  * @return array
  */
 public function getAlternatingSequence()
 {
     $edges = $this->edges->getVector();
     $vertices = $this->vertices->getVector();
     $ret = array();
     for ($i = 0, $l = count($this->edges); $i < $l; ++$i) {
         $ret[] = $vertices[$i];
         $ret[] = $edges[$i];
     }
     $ret[] = $vertices[$i];
     return $ret;
 }