本文整理汇总了PHP中Graph::addEdge方法的典型用法代码示例。如果您正苦于以下问题:PHP Graph::addEdge方法的具体用法?PHP Graph::addEdge怎么用?PHP Graph::addEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::addEdge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetDistance
/**
* @covers Application\Math\Graph::getDistance
* @covers Application\Math\Graph::solve
*/
public function testGetDistance()
{
$this->object->addEdge(2100, 2101, 10);
$this->object->addEdge(2101, 2102, 5);
$this->object->addEdge(2101, 2100, 10);
$this->object->addEdge(2102, 2101, 5);
$this->object->setStartVertex(strtoupper(2100))->setEndVertex(strtoupper(2102));
$this->assertSame(15, $this->object->getDistance());
}
示例2: buildWordLadderGraph
/**
* 단어 목록으로 인접 리스트를 사용해서 그래프 생성
*
* @param string $word_file 단어파일
* @return object Graph 그래프객체
* @throws Exception
*/
function buildWordLadderGraph($word_file)
{
$container = array();
$graph = new Graph();
$f = fopen($word_file, "r");
if ($f) {
while (($word = fgets($f)) !== false) {
$container = setBucketContainer($container, trim($word));
}
fclose($f);
} else {
throw new Exception('파일을 읽을 수 없습니다.');
}
$bucket_keys = array_keys($container);
foreach ($bucket_keys as $bucket) {
foreach ($container[$bucket] as $word1) {
foreach ($container[$bucket] as $word2) {
if ($word1 != $word2) {
$graph->addEdge($word1, $word2);
}
}
}
}
return $graph;
}
示例3: testCanNotAddRepeatedEdges
public function testCanNotAddRepeatedEdges()
{
$graph = new Graph(self::UNDIRECTED_GRAPH, self::NON_WEIGHTED_GRAPH);
$graph->addEdge('node1', 'node2');
$graph->addEdge('node1', 'node2');
$this->assertCount(1, $graph->getEdges('node1'));
}