PHP中的简单寻路

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).