This library can be used to find the shortest route between two point in a net of nodes (like a matrix in a game or net of roads).
The library needs a public sub in the calling module named
[Eventname]_Neighbors(x As Double, y As Double) As List
This sub should provide a list of all neighbor nodes.
Another sub that may (or may not) be used is the sub that calculates the distance between two points.
If it doesn't exist, the library uses a simple distance: Sqrt((x1-x2)^2 + (y1-y2)^2).
If you want To use a more sophisticated cost calculation, for example the time of passing the leg (distance/speed) then you should include another Sub In the calling module:
Public Sub [Eventname]_Distance(dbl() As Double) As Double
The library will use that sub if it exists.
Please let me know if there are any malfunctions or anomalies in the operation of the library (it is based on published pseudo_code but includes some added improvements by me.
Edit: Ver 1.1 now works on other types of nets, see post #4.
Edit: Ver.1.1 library doesn't work on B4J, so I added a jAstar library.
Edit: Ver 2.0 works for nets and roads, there are two examples. JAstar is for B4j.
The library needs a public sub in the calling module named
[Eventname]_Neighbors(x As Double, y As Double) As List
This sub should provide a list of all neighbor nodes.
Another sub that may (or may not) be used is the sub that calculates the distance between two points.
If it doesn't exist, the library uses a simple distance: Sqrt((x1-x2)^2 + (y1-y2)^2).
If you want To use a more sophisticated cost calculation, for example the time of passing the leg (distance/speed) then you should include another Sub In the calling module:
Public Sub [Eventname]_Distance(dbl() As Double) As Double
The library will use that sub if it exists.
Please let me know if there are any malfunctions or anomalies in the operation of the library (it is based on published pseudo_code but includes some added improvements by me.
Edit: Ver 1.1 now works on other types of nets, see post #4.
Edit: Ver.1.1 library doesn't work on B4J, so I added a jAstar library.
Edit: Ver 2.0 works for nets and roads, there are two examples. JAstar is for B4j.
Attachments
Last edited: