PHP中的简单寻路 [英] Simple pathfinding in PHP

查看:68
本文介绍了PHP中的简单寻路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在PHP中是否有一种简单的方法来进行寻路?

Does anyone know if there is a simple way to do pathfinding in PHP?

我基本上有一个数字列表,例如

I basically have a list of numbers, e.g.


  • {origin:11485,outboundDirections: 11486,11487,11488}

  • {origin:11487,outboundDirections: 11485 ,11676,94185}

  • {origin:11485,outboundDirections:"11486,11487,11488"}
  • {origin:11487,outboundDirections:"11485,11676,94185"}

,从11485变为94185将导致 11485> 11487> 94185 并具有退出的方式,而我正在尝试找出方法(它不一定是最短的路径或类似AI的任何东西,一种从A到B的方式)

and getting from 11485 to 94185 would result in 11485>11487>94185 with ways to "exit", and I'm trying to figure out how to do this (it doesn't really have to be shortest path or anything AI-like, just a way to get from A to B)

不幸的是,我根本不知道从哪里开始

I have no idea where to start at all, unfortunately

推荐答案

您可能想阅读宽度优先搜索 Dijkstra的算法。这两种都是公认的(而且相当简单)的算法,可以找到最短的路径(宽度优先搜索可以最大程度地减少跳数,Dijkstra的算法可以最小化总距离)。

You may want to read up on either breadth-first search or Dijkstra's algorithm for this problem. These are both well-established (and fairly straightforward) algorithms for finding shortest paths (breadth-first search to minimize the number of hops, Dijkstra's algorithm to minimize the total distance).

这篇关于PHP中的简单寻路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆