質問

このようにしていな比較が簡単にできるアルゴリズムの解の対称旅行営業マンの問題、最適なソリューションのヒューリスティックス.私(や参照のコードの両方のアルゴリズムだけを指定し、実施詳細は、関連するのと比較しました。っ F#コード の解決に到コード 日18 1.ではBFSに適応した最適な解を探ための重み付きグラフ(最終バージョンの編集からの質問が掲載され、ここでは、といえるが、これを無視しよう。このように作の簡単なデモを入力すstucks永遠に、以下の入力します。

#################
#i.G..c...e..H.p#
########.########
#j.A..b...f..D.o#
########@########
#k.E..a...g..B.n#
########.########
#l.F..d...h..C.m#
#################

これはリストの小文字のcharの頂点と大文字に制約され、先端の加重により異なる点在します。そこでもやってみたいとの比較に基づく時間の複雑なアルゴリズムに関する事例の分析による稜線の数の増加、固定された頂点数分の数が存在.があり 基準液Python を保証するものではなく、高速かなどの基本的な違いをアルゴリズム、その他マイナーコードの違いもので言語が異なる).

ったと 再帰vsキュー, は、 ツリー vsグリッド/地図 (私のgithubの歴史がない幸運です。

の元本の一部のコードは以下のとおりです。では以下の広さ優先探索(BFS)アルゴリズムが実装の詳細に報告されて以下の理論的説明され、標準BFS予測を算出するのに使用した複数の目標をエッジ重み付き仮木の剪定.

こちらはしかし、そんな時こそ、一歩として精巧なソリューションとなります。

1 single step receives as input which is the move index i
2 then it updates the distance of the current solution draft by summing the distance to the vertex i
3 it updates the current position as of vertex i
4 it also updates the list of predecessors by including vertex i
5 it computes the new tree of reachable vertices starting from the `fullGrid` and taking into account the newly updated list of predecessors

ここでは制約のTSP各頂点としての制約、リストの真骨頂。

fullGrid れを含むマトリクスの距離は、それが細かく、値を含んでいた時のデバッグします。ラッピングをソルバーは単なる再帰しくはキュー版のBFS.再び、私は興味のないプログラミングの詳細が理解で概念的なのに、なぜこのような基本となるアルゴリズムの適用はありません、そうで扱い入力例(らかじめご了承ください"16ます。

Start by receiving the graph topology and starting point
    Define a mindistance variable
    and a list of completed solutions, initially empty

    Start looping at the queue of partial solutions
        So a single partial solution is dequeued
        It computes possible vertices based on current predecessors
        Check if nothing remains and adds it to the completed alternatives updating mindistance
        Otherwise loop as in classical BFS
        For all possible moves = reachable vertices

                For each one applies above said single step
                If done updates mindistance and completed alternatives 
                Otherwise enqueue such partial solution 


    Finally select the min alternative by distance.
役に立ちましたか?

解決

私はこの概念の問題です。にBFSのような検索が最適化が必要なのは、 キューの長さ が重要な速度を必ず、トラックの 訪問した ます。

この目的は、 を避ける追加項目別の のキューのとき に存在してい a より良い商品 あります。

一部コードのみを明らかにします。

私の場合 いくらいが丁度いい は、訪問地図

let mutable visited = Map.empty<char,((char list) * int) list>

今enqueuingみをより良い品目:

if visited.ContainsKey(solutionNext.tree.area) 
    && (visited.[solutionNext.tree.area] 
        |> List.exists (
            fun (keys, distance) -> 
            distance <= solutionNext.tree.distance
            && solutionNext.keys |> List.forall(fun k -> keys |> List.contains k)
        ))
then () 
else 
    solution_queue <- enqueue solution_queue solutionNext
    let previous = if visited.ContainsKey(solutionNext.tree.area) then visited.[solutionNext.tree.area] else []
    visited <- Map.add solutionNext.tree.area ((solutionNext.keys, solutionNext.tree.distance) :: previous)  visited

欠で最悪のもの

while (MyQueue.length solution_queue > 0) do
    let solution = dequeue &solution_queue
    if visited.ContainsKey(solution.tree.area) 
        && (visited.[solution.tree.area] 
            |> List.exists (
                fun (keys, distance) -> 
                distance < solution.tree.distance
                && solution.keys |> List.forall(fun k -> keys |> List.contains k)
            ))
    then () else

コスト関数

から理論的観点から、BFSできるよう 液が返されまし として、 る場合のみ ると予想できまひとつひとつの活動をしたが、コスト1.すが、上記の例にも最適なソリューションが グラフコスト関数 はrepresetedによるエッジの 長さの異なる.と クリーン機能 の最短経路が関与:この場合はこちらです。そして最適なもの スペースの複雑さ (前項の規定)を避け、最悪の場合の時間計算量 $O^d)$, は、 $b$ の分岐要因 $d$ の深さの解決策です。するシナリオが $d$ は開始時には、鍵の迷路)の場合の実情については記載が得られた大きな $b$ 数踏切の迷路)

ライセンス: CC-BY-SA帰属
所属していません cs.stackexchange
scroll top