E N D
Kiểmtralớp K58C – Ngày 20/1/2011 • Cho đồthịđườngđigiữacácthànhphốtrong slide phíasau. Chúngtacầntìmđườngđitừthànhphố A (Arad) đến B (Bucharest). (các con sốtrênmộtcạnhlàbiểudiễnchíphígiữahaithànhphố, cácsốbêntayphảiđồthịlàkhoảngcáchƠclittừcácthànhphốđếnthànhphốđích) • Cho thuậttoántìmkiếmtốtnhấtđầutiêntrong slide kếtiếp. • Yêucầu: Hãyhiểnthịtrạngtháicácbiến node, ordered-array, father khithựchiệnthuậttoántrênchođồthị ở trêntươngứngvới 3 hàmđánhgiá h nhưsau: • h(n) làtổng chi phítừthànhphốđầu (A) đếnthànhphố n • h(n) làkhoảngcáchƠclittừthànhphố n đếnthànhphốđích (B) • h làtổngcủahaihàmnóitrên
Romania with step costs in km 374 253 329
Cài đặt chi tiết giải thuật Best-first search Function General-Search(problem, ordered-array,h) returns a solution, or failure ordered-array make-queue(make-node(initial-state[problem])); father(initial-state[problem]) = empty; while (1) if ordered-array is empty then return failure; node = pop(ordered-array) ; // node with min h if test(node,Goal[problem]) then return path(node,father); expand-nodes adjacent-nodes(node, Operators[problem]); push(ordered-array, expand-nodes ,h); foreach ex-node in expand-nodes father(ex-node) = node; end Lấy các đỉnh kề với node, nhưng chưa xuất hiện trong ordered-array Function push(ordered-array, expand-nodes ,h); Chèncác nodes trong expand-nodes vàoordered-array saochomảngordered-arraysắptheothứtựtăng/giảmtheohàmh