letournel/path-finder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

letournel/path-finder

Composer 安装命令:

composer require letournel/path-finder

包简介

Path finder algorithm

README 文档

README

Latest Stable Version Build Status Scrutinizer Code Quality

PathFinder is a standalone library aiming to implement famous path and route finding algorithms in PHP to solve classical problems such as:

Features

Roadmap

Classes

Core Classes

  • Heuristic: A distance with a floating weight.
  • Node: A node entity used in NodeGrid, NodeGraph, NodeMap or NodePath which is basically a couple of coordinates (x, y) or indices (i,j)
  • NodeGraph: A graph is a set of vertices connected by edges. Here, vertices are nodes and any couple of them can be connected by an edge with a floating value. By default, the graph is symmetric so the edge from vertex A to vertex B and vice versa have the same value.
  • NodeGrid: Simply a matrix of Nodes with coordinates (x, y) or indices (i,j) using the following pattern:
    .--------------> j (width) coord y
    | 1,1 1,2 1,3
    | 2,1 2,2 2,3
    | 3,1 ...
    |
    i (height) coord x
  • NodeMap: A map or dictionary which maps a Node (as key) to an object (as value) which can be a Node, boolean, ...
  • NodePath: A linked list of successive Nodes which forms a path

Algorithms Classes

  • ShortestDistance\Dijkstra: Compute shortest distance with Dijkstra algorithm
  • ShortestDistance\FloydWarshall: Compute shortest distance with FloydWarshall algorithm
  • ShortestPath\AStar: Compute shortest path with AStar algorithm
  • ShortestPath\Dijkstra: Compute shortest path with Dijkstra algorithm
  • TravelingSalesman\NearestNeighbour: Compute shortest tour with NearestNeighbour algorithm
  • TravelingSalesman\ThreeOpt: Improve shortest tour with ThreeOpt algorithm
  • TravelingSalesman\TwoOpt: Improve shortest tour with TwoOpt algorithm

Converters Classes

  • Grid\ASCIISyntax: Allow converting map with an ASCII syntax to NodeMap, NodePath, Node Objects back and forth

Distances Classes

  • Chebyshev: Compute the Chebyshev distance between two nodes which is max(|dx|, |dy|)
  • Euclidean: Compute the Euclidean distance between two nodes which is sqrt(|dx|^2 + |dy|^2)
  • Manhattan: Compute the Manhattan distance between two nodes which is |dx| + |dy|
  • Octile : Compute the Octile distance between two nodes which is (|dx| < |dy|) ? (sqrt(2) - 1) * |dx| + |dy|: (sqrt(2) - 1) * |dy| + |dx|
  • Zero : Compute the null or zero distance between two nodes A and B which is always 0

Examples

ASCIISyntax for maps:

  • Path: '.'
  • Source: '>'
  • Target: '<'
  • Wall: 'X'

SSP solving:

    require __DIR__ . '/vendor/autoload.php';
    
    use Letournel\PathFinder\Algorithms;
    use Letournel\PathFinder\Converters\Grid\ASCIISyntax;
    use Letournel\PathFinder\Core;
    use Letournel\PathFinder\Distances;
    
    function solve($map, $algorithm)
    {
        $converter = new ASCIISyntax();
        $grid = $converter->convertToGrid($map);
        $matrix = $converter->convertToMatrix($map);
        $source = $converter->findAndCreateNode($matrix, ASCIISyntax::IN);
        $target = $converter->findAndCreateNode($matrix, ASCIISyntax::OUT);
        
        $algorithm->setGrid($grid);
        $starttime = microtime(true);
        $path = $algorithm->computePath($source, $target);
        $endtime = microtime(true);
        
        if($path instanceof Core\NodePath)
        {
            echo "Path found in " . floor(($endtime - $starttime) * 1000) . " ms\n";
            echo $converter->convertToSyntaxWithPath($grid, $path);
        }
        else
        {
            echo "No path found\n";
        }
    }
    
    $map =
        '                ' . "\n" .
        '.XXXXXX XXXXXXXX' . "\n" .
        ' X   XX<X  X    ' . "\n" .
        ' X X  XXX X   X ' . "\n" .
        '   X           >' . "\n" ;
    
    $distance = new Distances\Euclidean();
    $heuristic = new Core\Heuristic(new Distances\Euclidean(), 1);
    
    echo "Solving SSP with AStar:\n";
    solve($map, new Algorithms\ShortestPath\AStar($distance, $heuristic));
    echo "\n\n\n";
    
    echo "Solving SSP with Dijkstra:\n";
    solve($map, new Algorithms\ShortestPath\Dijkstra($distance));
    echo "\n\n\n";

Installation

Use composer:

{
    "require": {
        "letournel/path-finder" : "~1.0"
    }
}

Legal

Letournel/PathFinder is Copyright(c) 2015 Letournel

Code released under the MIT license

letournel/path-finder 适用场景与选型建议

letournel/path-finder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.97k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2015 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「shortest path」 「dijkstra」 「Graph algorithms」 「travelling salesman」 「astar」 「floydwarshall」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 letournel/path-finder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 letournel/path-finder 我们能提供哪些服务?
定制开发 / 二次开发

基于 letournel/path-finder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-30