本文整理匯總了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'));
}