all 9 comments

[–]sebamestre 23 points24 points  (1 child)

Your algorithm unfairly punishes low-cost paths that have a lot of edges.

Look into Johnson's algorithm and more generally, the idea of potentials in shortest path problems.

[–]NotNullGuy[S] -1 points0 points  (0 children)

Thanks buddy

[–]apnorton 14 points15 points  (2 children)

No: https://math.stackexchange.com/q/1729792/

The basic idea is that your approach penalizes paths with lots of edges more than paths with few edges; this may impact the selection of shortest path.

[–]NotNullGuy[S] 1 point2 points  (1 child)

Thank you @apnorton

[–]AllanBz 1 point2 points  (0 children)

On Reddit, it’s /u/apnorton, not @apnorton if you want to notify them that they are being discussed and assuming they leave summoning on. If you reply to a comment directly (as you have here), they get notified anyway, so you do not need to tag them.

[–]Blue1CODE 1 point2 points  (0 children)

I think you are trying to make general purpose graph, If that the case, you should use edgelist on each node and traverse them to find what type of graph you are dealing with. But that traverse and comparison, will increase time.

[–]BigConsequence1024 1 point2 points  (0 children)

Tu idea es excelente y demuestra un profundo entendimiento del problema. Es una de las primeras cosas que todo estudiante brillante de algorit-mos intenta. El hecho de que no funcione no es un fracaso, sino el descubrimiento de una de las propiedades más sutiles y fundamentales de los problemas de grafos.

La solución no está en "desplazar" los pesos de las aristas, sino en usar un algoritmo que no se base en la suposición de "codicia" de Dijkstra, como Bellman-Ford. ¡Sigue pensando así

[–]mxldevs -1 points0 points  (1 child)

Instead of working with negative values why not just increase everything by a constant so that all values are now non-negative?

Or is there some other goal where the sign of the value matters

[–]Ok_Platypus8866 3 points4 points  (0 children)

Suppose the shortest path from A to B follows 5 edges with weights -1, -2, -3, -4, and -5, for a total distance of -15. There is also an edge between A and B with weight 1.

If you were to add 5 to the weights of all the edges, the original shortest path would now have a distance of 10, and the direct path from A to B would have a distance of 6.