当前位置: 首页>>代码示例>>PHP>>正文


PHP Graph::getVertex方法代码示例

本文整理汇总了PHP中Fhaculty\Graph\Graph::getVertex方法的典型用法代码示例。如果您正苦于以下问题:PHP Graph::getVertex方法的具体用法?PHP Graph::getVertex怎么用?PHP Graph::getVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fhaculty\Graph\Graph的用法示例。


在下文中一共展示了Graph::getVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getEdges

 /**
  *
  * @return Edges
  */
 public function getEdges()
 {
     $returnEdges = array();
     // Create minimum spanning tree
     $minimumSpanningTreeAlgorithm = new MstKruskal($this->graph);
     $minimumSpanningTree = $minimumSpanningTreeAlgorithm->createGraph();
     $alg = new SearchDepthFirst($minimumSpanningTree->getVertices()->getVertexFirst());
     // Depth first search in minmum spanning tree (for the eulerian path)
     $startVertex = NULL;
     $oldVertex = NULL;
     // connect vertices in order of the depth first search
     foreach ($alg->getVertices() as $vertex) {
         // get vertex from the original graph (not from the depth first search)
         $vertex = $this->graph->getVertex($vertex->getId());
         // need to clone the edge from the original graph, therefore i need the original edge
         if ($startVertex === NULL) {
             $startVertex = $vertex;
         } else {
             // get edge(s) to clone, multiple edges are possible (returns an array if undirected edge)
             $returnEdges[] = $oldVertex->getEdgesTo($vertex)->getEdgeFirst();
         }
         $oldVertex = $vertex;
     }
     // connect last vertex with start vertex
     // multiple edges are possible (returns an array if undirected edge)
     $returnEdges[] = $oldVertex->getEdgesTo($startVertex)->getEdgeFirst();
     return new Edges($returnEdges);
 }
开发者ID:faozimipa,项目名称:algorithms,代码行数:32,代码来源:MinimumSpanningTree.php

示例2: filterConnected

 /**
  * Filters the graph so that only entities connected to the root are left
  *
  * Should be run after you've added some set of associations with from()
  *
  * @return void
  */
 public function filterConnected()
 {
     $alg = new BreadthFirst($this->graph->getVertex($this->root));
     $alg->setDirection(BreadthFirst::DIRECTION_REVERSE);
     $vertices = $alg->getVertices();
     $this->graph = $this->graph->createGraphCloneVertices($vertices);
 }
开发者ID:vend,项目名称:doxport,代码行数:14,代码来源:EntityGraph.php

示例3: createGraph

 public function createGraph()
 {
     $graph = new Graph();
     $file = $this->getLines();
     $vertexCount = $this->readInt($file[0]);
     $edgeCounter = 0;
     if (count($file) !== $vertexCount + 1) {
         throw new UnexpectedValueException('Expects ' . ($vertexCount + 1) . ' lines, but found ' . count($file));
     }
     $graph->createVertices($vertexCount);
     $parts = array_fill(0, $vertexCount, 'int');
     for ($i = 0; $i < $vertexCount; $i++) {
         // Add Vertices
         $this->writeDebugMessage("Adding vertex {$i}, ");
         $thisVertex = $graph->getVertex($i);
         $currentEdgeList = $this->readLine($file[$i + 1], $parts);
         // $currentEdgeList = explode("\t", $file[$i + 1]);
         for ($k = 0; $k < $vertexCount; $k++) {
             // Add edges
             if ($currentEdgeList[$k] != 0) {
                 $this->writeDebugMessage(" and edge #{$edgeCounter}: {$i} -> {$k} ");
                 if ($this->directedEdges) {
                     $thisVertex->createEdgeTo($graph->getVertex($k));
                 } else {
                     $thisVertex->createEdge($graph->getVertex($k));
                 }
                 $edgeCounter++;
             }
         }
         $this->writeDebugMessage("\n");
     }
     return $graph;
 }
开发者ID:feffi,项目名称:graph,代码行数:33,代码来源:AdjacencyMatrix.php

示例4: createGraph

 public function createGraph()
 {
     $graph = new Graph();
     $file = $this->getLines();
     $countOfAllVertices = $this->readInt($file[0]);
     $countOfVerticesInA = $this->readInt($file[1]);
     if ($countOfVerticesInA > $countOfAllVertices || $countOfVerticesInA < 0) {
         throw new UnexpectedValueException('Invalid value for number of vertices in group 0');
     }
     $graph->createVertices($countOfAllVertices);
     for ($i = 0; $i < $countOfVerticesInA; ++$i) {
         $graph->getVertex($i)->setGroup(0);
     }
     for ($k = $countOfVerticesInA; $k < $countOfAllVertices; ++$k) {
         $graph->getVertex($k)->setGroup(1);
     }
     unset($file[0]);
     unset($file[1]);
     foreach ($file as $zeile) {
         $parts = $this->readLine($zeile, array('vertex', 'vertex'), $graph);
         if ($this->directedEdges) {
             $edge = $parts[0]->createEdgeTo($parts[1]);
         } else {
             $edge = $parts[0]->createEdge($parts[1]);
         }
     }
     $alg = new AlgorithmGroups($graph);
     if (!$alg->isBipartit()) {
         throw new UnexpectedValueException('Graph read from file does not form a valid bipartit graph');
     }
     return $graph;
 }
开发者ID:graphp,项目名称:plaintext,代码行数:32,代码来源:EdgeListBipartit.php

示例5: createEdges

 /**
  * Create edges between versions graph
  *
  * @param Graph  $graph
  * @param string $className
  */
 private function createEdges(Graph $graph, $className)
 {
     $migrationsAnnotations = $this->reader->getClassMigrationMethodInfo($className);
     $parentVertex = $graph->hasVertex($className) ? $graph->getVertex($className) : $graph->createVertex($className);
     foreach ($migrationsAnnotations as $migrationsAnnotation) {
         if ($migrationsAnnotation->annotation->from) {
             $fromClass = $migrationsAnnotation->annotation->from;
             $fromVertex = $graph->hasVertex($fromClass) ? $graph->getVertex($fromClass) : $graph->createVertex($fromClass);
             if (!$parentVertex->hasEdgeTo($fromVertex)) {
                 $edge = $fromVertex->createEdgeTo($parentVertex);
                 $this->annotations[$this->getEdgeId($edge)] = $migrationsAnnotation;
                 $this->createEdges($graph, $fromClass);
             }
         }
         if ($migrationsAnnotation->annotation->to) {
             $toClass = $migrationsAnnotation->annotation->to;
             $fromVertex = $graph->hasVertex($toClass) ? $graph->getVertex($toClass) : $graph->createVertex($toClass);
             if (!$parentVertex->hasEdgeTo($fromVertex)) {
                 $edge = $parentVertex->createEdgeTo($fromVertex);
                 $this->annotations[$this->getEdgeId($edge)] = $migrationsAnnotation;
                 $this->createEdges($graph, $toClass);
             }
         }
     }
 }
开发者ID:evispa,项目名称:object-migration,代码行数:31,代码来源:VersionPathSearch.php

示例6: createGraph

 public function createGraph()
 {
     $start = microtime(true);
     $graph = new Graph();
     $n = $this->numberOfVertices;
     $this->writeDebugMessage("start creating vertices\n");
     $graph->createVertices($n);
     $this->writeDebugMessage("start creating edges\n");
     for ($i = 0; $i < $n; ++$i) {
         $vertex = $graph->getVertex($i);
         if ($this->directedEdges) {
             for ($j = 0; $j < $n; ++$j) {
                 if ($j !== $i) {
                     $vertex->createEdgeTo($graph->getVertex($j));
                 }
             }
         } else {
             for ($j = $i + 1; $j < $n; ++$j) {
                 $vertex->createEdge($graph->getVertex($j));
             }
         }
     }
     $end = microtime(true);
     $this->writeDebugMessage($end - $start . " done ...\n");
     return $graph;
 }
开发者ID:graphp,项目名称:plaintext,代码行数:26,代码来源:CompleteGraph.php

示例7: setUp

 public function setUp()
 {
     $graph = new Graph();
     $graph->createVertex(1);
     $graph->createVertex(2);
     // 1 -> 2
     $this->edge = $graph->getVertex(1)->createEdge($graph->getVertex(2));
 }
开发者ID:cmfcmf,项目名称:graph,代码行数:8,代码来源:EdgeAttributesTest.php

示例8: createGraphParallelEdge

 protected function createGraphParallelEdge()
 {
     // v1 -> v2, v1 -> v2
     $graph = new Graph();
     $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2'));
     $graph->getVertex('v1')->createEdgeTo($graph->getVertex('v2'));
     return $graph;
 }
开发者ID:faozimipa,项目名称:algorithms,代码行数:8,代码来源:OutTreeTest.php

示例9: testFailCycle

 /**
  * @expectedException UnexpectedValueException
  */
 public function testFailCycle()
 {
     $graph = new Graph();
     $graph->createVertex(1)->createEdgeTo($graph->createVertex(2));
     $graph->getVertex(2)->createEdgeTo($graph->getVertex(1));
     $alg = new TopologicalSort($graph);
     $alg->getVertices();
 }
开发者ID:faozimipa,项目名称:algorithms,代码行数:11,代码来源:TopologicalSortTest.php

示例10: testGraphAntiparallelIsSymmetricr

 public function testGraphAntiparallelIsSymmetricr()
 {
     // 1 -> 2 -> 1
     $graph = new Graph();
     $graph->createVertex(1)->createEdgeTo($graph->createVertex(2));
     $graph->getVertex(2)->createEdgeTo($graph->getVertex(1));
     $alg = new AlgorithmSymmetric($graph);
     $this->assertTrue($alg->isSymmetric());
 }
开发者ID:faozimipa,项目名称:algorithms,代码行数:9,代码来源:SymmetricTest.php

示例11: testEdgePartial

 /**
  * test an edge with capacity remaining
  */
 public function testEdgePartial()
 {
     $graph = new Graph();
     $graph->createVertex(0)->createEdgeTo($graph->createVertex(1))->setFlow(1)->setCapacity(2)->setWeight(3);
     $alg = new ResidualGraph($graph);
     $residual = $alg->createGraph();
     $expected = new Graph();
     $expected->createVertex(0);
     $expected->createVertex(1);
     // remaining edge
     $expected->getVertex(0)->createEdgeTo($expected->getVertex(1))->setFlow(0)->setCapacity(1)->setWeight(3);
     // back edge
     $expected->getVertex(1)->createEdgeTo($expected->getVertex(0))->setFlow(0)->setCapacity(1)->setWeight(-3);
     $this->assertGraphEquals($expected, $residual);
 }
开发者ID:faozimipa,项目名称:algorithms,代码行数:18,代码来源:ResidualGraphTest.php

示例12: testGraphEdgeDirections

 public function testGraphEdgeDirections()
 {
     // 1 -- 2 -> 3 <- 4
     $graph = new Graph();
     $graph->createVertex(1)->createEdge($graph->createVertex(2));
     $graph->getVertex(2)->createEdgeTo($graph->createVertex(3));
     $graph->createVertex(4)->createEdgeTo($graph->getVertex(3));
     $alg = new AlgorithmConnected($graph);
     $this->assertEquals(1, $alg->getNumberOfComponents());
     $this->assertTrue($alg->isSingle());
     $graphs = $alg->createGraphsComponents();
     $this->assertCount(1, $graphs);
     $this->assertGraphEquals($graph, reset($graphs));
     $this->assertGraphEquals($graph, $alg->createGraphComponentVertex($graph->getVertex(1)));
 }
开发者ID:feffi,项目名称:graph,代码行数:15,代码来源:ConnectedComponentsTest.php

示例13: buildTree

 /**
  * Build out-tree graph from defined Processes and their relations.
  *
  * @return OutTree
  */
 public function buildTree()
 {
     if (!$this->tree) {
         $root = $this->graph->createVertex(0);
         // Create edges directed from the root node
         foreach ($this->processes as $processClassName => $processObject) {
             $vertex = $this->graph->getVertex($processClassName);
             if (!$processObject->delayMinutes) {
                 // process doesn't depend on anything => link it to the root node
                 $root->createEdgeTo($vertex)->setWeight(0);
             } else {
                 // link process to its dependency
                 // Throw error if dependency is to not existing vertex
                 if (!$this->graph->hasVertex($processObject->delayAfter)) {
                     throw new \InvalidArgumentException(sprintf('Testcase "%s" has @delayAfter dependency on "%s", but this testcase was not defined.', $processClassName, $processObject->delayAfter));
                 }
                 $this->graph->getVertex($processObject->delayAfter)->createEdgeTo($vertex)->setWeight($processObject->delayMinutes);
             }
         }
     }
     $this->tree = new OutTree($this->graph);
     if (!$this->tree->isTree()) {
         throw new \InvalidArgumentException(sprintf('Cannot build tree graph from tests dependencies. Probably some cyclic dependency is present.'));
     }
     return $this->tree;
 }
开发者ID:mhujer,项目名称:steward,代码行数:31,代码来源:ProcessSet.php

示例14: createGraph

 /**
  *
  * @param string $dir
  * @return \Fhaculty\Graph\Graph
  */
 public function createGraph()
 {
     $graph = new Graph();
     foreach ($this->dependencyGraph->getPackages() as $package) {
         $name = $package->getName();
         $start = $graph->createVertex($name, true);
         $label = $name;
         if ($package->getVersion() !== null) {
             $label .= ': ' . $package->getVersion();
         }
         $this->setLayout($start, array('label' => $label) + $this->layoutVertex);
         foreach ($package->getOutEdges() as $requires) {
             $targetName = $requires->getDestPackage()->getName();
             $target = $graph->createVertex($targetName, true);
             $label = $requires->getVersionConstraint();
             $edge = $start->createEdgeTo($target);
             $this->setLayout($edge, array('label' => $label) + $this->layoutEdge);
             if ($requires->isDevDependency()) {
                 $this->setLayout($edge, $this->layoutEdgeDev);
             }
         }
     }
     $root = $graph->getVertex($this->dependencyGraph->getRootPackage()->getName());
     $this->setLayout($root, $this->layoutVertexRoot);
     return $graph;
 }
开发者ID:clue,项目名称:graph-composer,代码行数:31,代码来源:GraphComposer.php

示例15: testVertexWithUndirectedEdgeHasInvalidFlow

 /**
  * @expectedException UnexpectedValueException
  */
 public function testVertexWithUndirectedEdgeHasInvalidFlow()
 {
     // 1 -- 2
     $graph = new Graph();
     $graph->createVertex(1)->createEdge($graph->createVertex(2))->setFlow(10);
     $alg = new AlgorithmFlow($graph);
     $alg->getFlowVertex($graph->getVertex(1));
 }
开发者ID:faozimipa,项目名称:algorithms,代码行数:11,代码来源:FlowTest.php


注:本文中的Fhaculty\Graph\Graph::getVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。