当前位置: 首页>>代码示例>>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;未经允许,请勿转载。