Algorithm ASP经典选择更好的行程

Algorithm ASP经典选择更好的行程,algorithm,asp-classic,selection,routes,shortest-path,Algorithm,Asp Classic,Selection,Routes,Shortest Path,我正在开发一个网站,用于在一家公司发布部分内容,我一直在满足以下需求: 该公司有几个分支机构,每个分支机构都有不同的邮寄路线 例如,我的想法如下: 第一单元只发送给第二单元,第二单元只发送给第三单元 所以,如果我想从第1单元发布到第6单元,它必须通过第2、3、4和5单元。在此之前,我可以使用下面的代码: <% origem = int(request.querystring("origem")) destino = int(request.querystring("destino")) c

我正在开发一个网站,用于在一家公司发布部分内容,我一直在满足以下需求:

该公司有几个分支机构,每个分支机构都有不同的邮寄路线

例如,我的想法如下:

第一单元只发送给第二单元,第二单元只发送给第三单元

所以,如果我想从第1单元发布到第6单元,它必须通过第2、3、4和5单元。在此之前,我可以使用下面的代码:

<%
origem = int(request.querystring("origem"))
destino = int(request.querystring("destino"))
codcorrespondencia = int(request.querystring("codcorrespondencia"))

set rs = server.CreateObject("ADODB.Recordset")
set rs2 = server.CreateObject("ADODB.Recordset")

base = destino
caminho = base

do while not base = origem
rs.open "select * from ESCALAS where codunidade_post = " & base, conexao

    if not rs.fields("codunidade") = origem then
        do while not rs.eof
        rs2.open "select * from ESCALAS where codunidade_post = " & rs.fields("codunidade"), conexao
            if not rs2.eof then
            escalacao = int(rs.fields("codunidade")) & " - " & base & "; " & escalacao 'novas linhas
            base = int(rs.fields("codunidade"))
            end if
        rs2.close

        rs.movenext
        loop
    else
    escalacao = rs.fields("codunidade") & " - " & base & "; " & escalacao 'novas linhas
    base = origem
    end if
rs.close
caminho = base & "," & caminho
loop

response.Write(escalacao)
%>

但是,如果发生以下情况:

单元1至2、2至3、4至5、4至6和5至6

代码选择从4发送到5,从5发送到6,而不是直接从4发送到6

我的代码如何变得智能并选择最短的路径


为了进行测试,我使用了var-escalaco。它向我展示了代码选择的方式。

看起来您需要实现最短路径算法,以便为您的帖子找到最佳路径,因为您有多条从4到6的路径(直接4->6和间接4->5->6)

见维基百科