F
F
FreeZa2015-07-20 03:03:19
PHP
FreeZa, 2015-07-20 03:03:19

How to search for array elements in a chain (search for the optimal path)?

Cheerful time of day!
I'm looking for an algorithm to solve my problem, even in php, even in js, it doesn't matter.
Given an array:

[0, "name", x, y, z, 10, [1,2]],
[1, "name", x, y, z, 10, [0,3]],
[2, "name", x, y, z, 5, [0,3,4]],
[3, "name", x, y, z, 10, [2,1,4]],
[4, "name", x, y, z, 10, [3,2]],
[5, "name", x, y, z, 10, [4]]

in fact, each element of the array is a point in space that is connected to other similar points, the points with which it connects are stored in a nested array.
Of course, the points are not all directly connected to each other. that is, from point 0 to point 5 you can only get through neighboring points, and you can get there in different ways, for example:
1) 0->2->3->4->5
2) 0->1->3->4->5
3) 0->2->4->5

3 the path is the shortest in terms of the number of links, this is one of the goals of the algorithm to find a short path, but that's not all)
each point has a security value, for example point 0 has a value of 10 (safe),
and point 2 has a security level below 6 , which is not safe.
the output of the algorithm should be 2 sets of points in our case:
2) 0->1->3->4->5  // самый короткий из безопасных путей
3) 0->2->4->5       // самый короткий путь

Actually advise the optimal solution in your opinion for this problem.
PS. the array consists of more than 1000
PPS elements. Many thanks in advance! =)
PPPS. I've attached a picture for clarity =)
906804a5c01c469c97016b431ec4a6de.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2015-07-20
@FreeZa

Have you decided to make a map for EVE Online with your own hands? All prerequisites, including the picture, speak of this. :)
Any pathfinding algorithm will help you. Look towards A*, its implementation exists, probably, even at brainfuck, so the code is simply inappropriate.
The route search is done once for the safest route and once again for the shortest.
In the first case, the weight of the node will be the s-level of the star. Heuristic - average sec-level per number of jumps to the target.
In the second case, the weight will already be the number of jumps themselves, and the heuristic will have to be calculated from the number of jumps to the target.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question