r/algorithms • • 29d ago

Help Longest path in undirected graph with weights associated to edges

Hello fellow algorithms comrades, recently I got project on my university about finding best algorithm for (in title). Currently I'm working with algorithm that builds path from random dfs and increases its weight by rotations, restarting, rebuilding fragments and adding nodes to solution. Does anyone have a better approach to such solution? I'm not asking for any finished algorithm but just thoughts that could help me improve my algorithm and maybe come up with something new
If you know any research papers worth reading in this topic, please give their names

Graph is general and can have cycles, I know that it is NP-Hard thats why I'm asking about any ideas

Thank you all in advance

5 Upvotes

6 comments sorted by

6

u/SignificantFidgets 29d ago

Of the graph is acyclic (a dag) then there are fast algorithms for this. If the graph is general and can have cycles, then it's NP-hard, so it's likely that no efficient algorithm exists.

2

u/entinko 29d ago

Graph is general and can have cycles, I added this info to post because it is important, thanks for pointing this out

And also I know it is NP-hard that's why I'm asking for any ideas, because current algorithm is nice but I'm wondering if I can improve it somehow or try something different

0

u/[deleted] 28d ago

[deleted] — view deleted comment

2

u/PurpleDevilDuckies 28d ago

This is not true, the A is for Acyclic, and cycles are what make it hard. For dags, this is linear

2

u/AerosolHubris 28d ago

Shoot. I just spaced out on that. Of course you're right.

2

u/Ordoviz11q 29d ago

Sagemath includes a heuristic algorithm and an exact Integer Linear Programming algorithm for Longest Path, see its source code.