當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Graph::addEdge方法代碼示例

本文整理匯總了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());
 }
開發者ID:aiolos,項目名稱:haltes,代碼行數:13,代碼來源:GraphTest.php

示例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;
}
開發者ID:jonnung,項目名稱:word_ladder_graph,代碼行數:32,代碼來源:word_ladder.php

示例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'));
 }
開發者ID:atabel,項目名稱:php-graph,代碼行數:7,代碼來源:GraphTest.php


注:本文中的Graph::addEdge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。