當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Graph::createVertex方法代碼示例

本文整理匯總了PHP中Fhaculty\Graph\Graph::createVertex方法的典型用法代碼示例。如果您正苦於以下問題:PHP Graph::createVertex方法的具體用法?PHP Graph::createVertex怎麽用?PHP Graph::createVertex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Fhaculty\Graph\Graph的用法示例。


在下文中一共展示了Graph::createVertex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testMixedParallelEdgesMultiple

 public function testMixedParallelEdgesMultiple()
 {
     // 1 -> 2
     // 1 -> 2
     // 1 -- 2
     // 1 -- 2
     // 2 -> 1
     // 2 -> 1
     $graph = new Graph();
     $v1 = $graph->createVertex(1);
     $v2 = $graph->createVertex(2);
     $e1 = $v1->createEdgeTo($v2);
     $e2 = $v1->createEdgeTo($v2);
     $e3 = $v1->createEdge($v2);
     $e4 = $v1->createEdge($v2);
     $e5 = $v2->createEdgeTo($v1);
     $e6 = $v2->createEdgeTo($v1);
     $alg = new AlgorithmParallel($graph);
     $this->assertTrue($alg->hasEdgeParallel());
     $this->assertEquals(array($e2, $e3, $e4), $alg->getEdgesParallelEdge($e1)->getVector());
     $this->assertEquals(array($e1, $e3, $e4), $alg->getEdgesParallelEdge($e2)->getVector());
     $this->assertEquals(array($e1, $e2, $e4, $e5, $e6), $alg->getEdgesParallelEdge($e3)->getVector());
     $this->assertEquals(array($e1, $e2, $e3, $e5, $e6), $alg->getEdgesParallelEdge($e4)->getVector());
     $this->assertEquals(array($e3, $e4, $e6), $alg->getEdgesParallelEdge($e5)->getVector());
     $this->assertEquals(array($e3, $e4, $e5), $alg->getEdgesParallelEdge($e6)->getVector());
 }
開發者ID:faozimipa,項目名稱:algorithms,代碼行數:26,代碼來源:ParallelTest.php

示例2: 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

示例3: testShouldOptimizeOrderBasedOnMaxSubtreeDelay

 public function testShouldOptimizeOrderBasedOnMaxSubtreeDelay()
 {
     //     -------ROOT-------
     //    / 0   / 0    \ 0   \ 0
     //   A      B      F     H
     //       3 / \ 5   | 11  | 4
     //        C   D    G     I
     //     10 |
     //        E
     // Build graph
     $graph = new Graph();
     $root = $graph->createVertex(0);
     $root->createEdgeTo($graph->createVertex('A'))->setWeight(0);
     $root->createEdgeTo($vertexB = $graph->createVertex('B'))->setWeight(0);
     $vertexB->createEdgeTo($vertexC = $graph->createVertex('C'))->setWeight(3);
     $vertexB->createEdgeTo($graph->createVertex('D'))->setWeight(5);
     $vertexC->createEdgeTo($graph->createVertex('E'))->setWeight(10);
     $root->createEdgeTo($vertexF = $graph->createVertex('F'))->setWeight(0);
     $vertexF->createEdgeTo($graph->createVertex('G'))->setWeight(11);
     $root->createEdgeTo($vertexH = $graph->createVertex('H'))->setWeight(0);
     $vertexH->createEdgeTo($graph->createVertex('I'))->setWeight(4);
     // Check the vertices have proper order value
     $strategy = new MaxTotalDelayStrategy();
     $evaluatedOrder = $strategy->optimize(new OutTree($graph));
     $this->assertSame($evaluatedOrder['A'], 0);
     $this->assertSame($evaluatedOrder['B'], 13);
     $this->assertSame($evaluatedOrder['C'], 10);
     $this->assertSame($evaluatedOrder['D'], 0);
     $this->assertSame($evaluatedOrder['E'], 0);
     $this->assertSame($evaluatedOrder['F'], 11);
     $this->assertSame($evaluatedOrder['G'], 0);
     $this->assertSame($evaluatedOrder['H'], 4);
     $this->assertSame($evaluatedOrder['I'], 0);
 }
開發者ID:mhujer,項目名稱:steward,代碼行數:34,代碼來源:MaxTotalDelayStrategyTest.php

示例4: createGraph

 /**
  *
  * @param  string                $dir
  * @return \Fhaculty\Graph\Graph
  */
 public function createGraph($vendorName = null, $excludeDevDependency = true)
 {
     $graph = new Graph();
     foreach ($this->dependencyGraph->getPackages() as $package) {
         $name = $package->getName();
         if (null !== $vendorName && false === strpos($name, $vendorName)) {
             continue;
         }
         $start = $graph->createVertex($name, true);
         $label = $name;
         if ($package->getVersion() !== null) {
             $label .= ': ' . $package->getVersion();
         }
         $start->setLayout(array('label' => $label) + $this->getLayoutVertex($name));
         foreach ($package->getOutEdges() as $requires) {
             $targetName = $requires->getDestPackage()->getName();
             if (null !== $vendorName && false === strpos($targetName, $vendorName)) {
                 continue;
             }
             if ($excludeDevDependency && $requires->isDevDependency()) {
                 continue;
             }
             $target = $graph->createVertex($targetName, true);
             $label = $requires->getVersionConstraint();
             $start->createEdgeTo($target)->setLayout(array('label' => $label) + $this->layoutEdge);
         }
     }
     return $graph;
 }
開發者ID:tonydub,項目名稱:jarvis,代碼行數:34,代碼來源:GraphComposer.php

示例5: testInvalidBipartit

 /**
  * expect exception for non-bipartit graphs
  * @expectedException UnexpectedValueException
  */
 public function testInvalidBipartit()
 {
     $graph = new Graph();
     $graph->createVertex(0)->setGroup(1)->createEdge($graph->createVertex(1)->setGroup(1));
     $alg = new Flow($graph);
     $alg->getNumberOfMatches();
 }
開發者ID:faozimipa,項目名稱:algorithms,代碼行數:11,代碼來源:FlowTest.php

示例6: 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

示例7: 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

示例8: 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

示例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: testGraphSingleUndirectedIsSymmetricr

 public function testGraphSingleUndirectedIsSymmetricr()
 {
     // 1 -- 2
     $graph = new Graph();
     $graph->createVertex(1)->createEdge($graph->createVertex(2));
     $alg = new AlgorithmSymmetric($graph);
     $this->assertTrue($alg->isSymmetric());
 }
開發者ID:faozimipa,項目名稱:algorithms,代碼行數:8,代碼來源:SymmetricTest.php

示例11: 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

示例12: testGraphWithUnweightedEdges

 /**
  *
  * @param Graph $graph
  * @depends testGraphSimple
  */
 public function testGraphWithUnweightedEdges(Graph $graph)
 {
     $graph->createVertex(5)->createEdgeTo($graph->createVertex(6))->setFlow(7);
     $alg = new AlgorithmWeight($graph);
     $this->assertEquals(3, $alg->getWeight());
     $this->assertEquals(12, $alg->getWeightFlow());
     $this->assertEquals(3, $alg->getWeightMin());
     $this->assertTrue($alg->isWeighted());
 }
開發者ID:feffi,項目名稱:graph,代碼行數:14,代碼來源:WeightTest.php

示例13: testGraphMixed

 public function testGraphMixed()
 {
     // 1 -- 2 -> 3
     $graph = new Graph();
     $graph->createVertex(1)->createEdge($graph->createVertex(2));
     $graph->getVertex(2)->createEdgeTo($graph->createVertex(3));
     $alg = new AlgorithmDirected($graph);
     $this->assertTrue($alg->hasDirected());
     $this->assertTrue($alg->hasUndirected());
     $this->assertTrue($alg->isMixed());
 }
開發者ID:faozimipa,項目名稱:algorithms,代碼行數:11,代碼來源:DirectedTest.php

示例14: drawTransitions

 /**
  * Draw all Transitions
  *
  * @return array
  */
 public function drawTransitions()
 {
     $transitions = array();
     foreach ($this->transitionsStorage as $transition) {
         $fromState = $this->graph->createVertex($transition['fromStateId'], true);
         $targetState = $this->graph->createVertex($transition['targetStateId'], true);
         $edge = $fromState->createEdgeTo($targetState)->setLayout($transition['styleAttributes']);
         $transitions[] = $edge;
     }
     return $transitions;
 }
開發者ID:cosma,項目名稱:simple-state-machine,代碼行數:16,代碼來源:Graphic.php

示例15: testGraphParallelNegative

 /**
  * @expectedException UnexpectedValueException
  */
 public function testGraphParallelNegative()
 {
     // 1 -[10]-> 2
     // 1 -[-1]-> 2
     $graph = new Graph();
     $v1 = $graph->createVertex(1);
     $v2 = $graph->createVertex(2);
     $e1 = $v1->createEdgeTo($v2)->setWeight(10);
     $e2 = $v1->createEdgeTo($v2)->setWeight(-1);
     $alg = $this->createAlg($v1);
     $alg->getEdges();
 }
開發者ID:feffi,項目名稱:graph,代碼行數:15,代碼來源:DijkstraTest.php


注:本文中的Fhaculty\Graph\Graph::createVertex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。