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


PHP Graph::createVertices方法代码示例

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


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

示例1: createGraph

 /**
  *
  */
 public function createGraph()
 {
     $graph = new Graph();
     $file = $this->getLines();
     $graph->createVertices($this->readInt($file[0]));
     unset($file[0]);
     // set the value of the vertices
     $zeile = 1;
     foreach ($graph->getVertices() as $vertex) {
         $vertex->setBalance($this->readFloat($file[$zeile]));
         unset($file[$zeile]);
         ++$zeile;
     }
     foreach ($file as $zeile) {
         $parts = $this->readLine($zeile, array('vertex', 'vertex', 'float', 'float'), $graph);
         if ($this->directedEdges) {
             $edge = $parts[0]->createEdgeTo($parts[1]);
         } else {
             $edge = $parts[0]->createEdge($parts[1]);
         }
         $edge->setWeight($parts[2]);
         $edge->setCapacity($parts[3]);
     }
     return $graph;
 }
开发者ID:graphp,项目名称:plaintext,代码行数:28,代码来源:EdgeListWithWeightedCapacityAndBalance.php

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

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

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

 public function createGraph()
 {
     $graph = new Graph();
     $file = $this->getLines();
     $graph->createVertices($this->readInt($file[0]));
     unset($file[0]);
     foreach ($file as $zeile) {
         $parts = $this->readLine($zeile, array('vertex', 'vertex', 'float'), $graph);
         if ($this->directedEdges) {
             $edge = $parts[0]->createEdgeTo($parts[1]);
         } else {
             $edge = $parts[0]->createEdge($parts[1]);
         }
         $edge->setWeight($parts[2]);
     }
     return $graph;
 }
开发者ID:graphp,项目名称:plaintext,代码行数:17,代码来源:EdgeListWeighted.php

示例6: createGraph

 public function createGraph()
 {
     $graph = new Graph();
     $file = $this->getLines();
     $vertexCount = $this->readInt($file[0]);
     $this->writeDebugMessage('create ' . $vertexCount . ' vertices');
     $graph->createVertices($vertexCount);
     $this->writeDebugMessage('parse edges');
     unset($file[0]);
     foreach ($file as $zeile) {
         $ends = $this->readLine($zeile, array('from' => 'vertex', 'to' => 'vertex'), $graph);
         if ($this->directedEdges) {
             $ends['from']->createEdgeTo($ends['to']);
         } else {
             $ends['from']->createEdge($ends['to']);
         }
     }
     return $graph;
 }
开发者ID:feffi,项目名称:graph,代码行数:19,代码来源:EdgeList.php

示例7: testGraphUndirectedWithIsolatedVerticesFirst

    public function testGraphUndirectedWithIsolatedVerticesFirst()
    {
        // a -- b -- c   d
        $graph = new Graph();
        $graph->createVertices(array('a', 'b', 'c', 'd'));
        $graph->getVertex('a')->createEdge($graph->getVertex('b'));
        $graph->getVertex('b')->createEdge($graph->getVertex('c'));
        $expected = <<<VIZ
graph G {
  "d"
  "a" -- "b"
  "b" -- "c"
}

VIZ;
        $this->assertEquals($expected, $this->graphViz->createScript($graph));
    }
开发者ID:graphp,项目名称:graphviz,代码行数:17,代码来源:GraphVizTest.php

示例8: testCreateVerticesContainsInvalid

 /**
  * @expectedException InvalidArgumentException
  */
 public function testCreateVerticesContainsInvalid()
 {
     $graph = new Graph();
     $graph->createVertices(array(1, 2, array(), 3));
 }
开发者ID:feffi,项目名称:graph,代码行数:8,代码来源:GraphTest.php

示例9: generateVertices

 /**
  * @param Graph $graph
  * @param int $count
  * @return \Fhaculty\Graph\Vertex[]
  */
 public function generateVertices(Graph $graph, $count = 5)
 {
     for ($i = 1; $i <= $count; $i++) {
         $ids[] = "node_{$i}";
     }
     return $graph->createVertices($ids)->getMap();
 }
开发者ID:relaxedws,项目名称:lca,代码行数:12,代码来源:LowestCommonAncestorTest.php


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