在此图表任务中,最小化道路成本的算法

发布于 2025-02-09 22:41:06 字数 157 浏览 3 评论 0原文

来完成这项任务

最近,我根据双向道路的系统 ,确定值得在哪个城市之间建造道路,以便在不到n公里以下的任何城市到其他任何城市。合格道路的距离和建筑成本分别指定。最小化道路建设成本。

我从两个矩阵中制作了Java图,以可视化初始合格的道路,但无法提出算法,我并不真正熟悉图形)

Recently I get this task

Based on the system of two-way roads, determine between which cities it is worth building roads so that one can get from any city to any other in less than N km. The distances and construction costs of eligible roads are specified separately. Minimize road construction costs.

I made java graph from two matrix for visualize initial eligible roads, but can't come up with algorithm, I'm not really familiar with graphs)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤痕我心 2025-02-16 22:41:06
FOR EVER
    M = 0
    LOOP over every pair of cities 
        If min distance ( Dijkstra algorithm ) between cities > M
           M = min distance
    IF M <= N
        BREAK
    LOOP over eligible roads in order of increasing cost
        IF road would reduce distance between two most distant cities
             BUILD the road

请注意,Dijkstra的许多实现都将使Minumim从源到每个可能的目的地的距离。这可以用于优化计算M的循环

FOR EVER
    M = 0
    LOOP over every pair of cities 
        If min distance ( Dijkstra algorithm ) between cities > M
           M = min distance
    IF M <= N
        BREAK
    LOOP over eligible roads in order of increasing cost
        IF road would reduce distance between two most distant cities
             BUILD the road

Note that many implementations of Dijkstra will give the minumim distance from a source to every possible destination. This can be used to optimize the loop calculating M

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文