本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例8: testCreateVerticesContainsInvalid
/**
* @expectedException InvalidArgumentException
*/
public function testCreateVerticesContainsInvalid()
{
$graph = new Graph();
$graph->createVertices(array(1, 2, array(), 3));
}
示例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();
}