本文整理汇总了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());
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
}
}
}
示例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;
}
示例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));
}
示例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();
}
示例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());
}
示例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));
}
示例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());
}
示例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());
}
示例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;
}
示例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();
}