‹

05 · The Algorithmic Path

05 · The Algorithmic Path

05 · ​เส้นทาง​แบบ​อัลกอริทึม

THE SHORTEST PATH — A History of the Art and Science of Problem-Solving

​เส้นทาง​ที่​สั้น​ที่สุด — ​ประวัติศาสตร์​ของ​ศิลปะ​และ​ศาสตร์​แห่ง​การแก้ปัญหา



Amsterdam, a café terrace, 1956

​อัมสเตอร์ดัม ​ระเบียง​ร้านกาแฟ ​ปี 1956

Edsger Dijkstra was twenty-six, shopping with his fiancée Ria, and tired. He had recently taken a job at the Mathematisch Centrum in Amsterdam demonstrating a new computer called the ARMAC, and he wanted a problem simple enough to explain to a nontechnical audience yet impressive enough to show the machine earning its keep. Sitting down for coffee, without pencil, paper, or access to a library, he set himself the question of the shortest route between two Dutch cities and, in his own later telling, worked out the solution in about twenty minutes (David Gries, "Edsger Dijkstra and the Shortest-Path Algorithm," Cornell CS). The algorithm he sketched that morning — grow a set of cities whose shortest distance from the start is already known for certain, and at each step add whichever unvisited city is now closest — is still, seven decades later, the default answer whenever a computer needs to find the cheapest way from here to there. He did not publish it until three years afterward, as a spare three-page note that solved two unrelated graph problems in the space most papers need for an abstract (Dijkstra, "A Note on Two Problems in Connexion with Graphs," Numerische Mathematik 1 (1959)).

​อัลกอริทึม​ที่​ยัง​เป็น​คำตอบ​ตั้งต้น​ของ​คอมพิวเตอร์​ทุก​เครื่อง​เมื่อ​ต้องหา​ทาง​ที่​ถูกที่​สุด​จาก​ที่นี่​ไป​ที่นั่น ​ถูก​คิด​ขึ้น​ใน​ร้านกาแฟ ​ใน​เวลา​ราว​ยี่สิบ​นาที Edsger Dijkstra ​อายุ​ยี่สิบ​หก ​ออก​ไป​เดิน​ซื้อ​ของ​กับ Ria ​คู่หมั้น​ของ​เขา ​และ​เหนื่อย ​เขา​เพิ่ง​รับงาน​ที่ Mathematisch Centrum ​ใน​อัมสเตอร์ดัม ​หน้าที่​คือ​สาธิต​คอมพิวเตอร์​เครื่อง​ใหม่​ชื่อ ARMAC ​เขา​ต้องการ​โจทย์​ที่​ง่าย​พอ​จะ​อธิบาย​ให้​คนนอก​สาย​เทคนิค​ฟังได้ ​แต่​ก็​น่าประทับใจ​พอ​จะ​แสดงว่า​เครื่อง​นี้​คุ้มค่า​ที่​เลี้ยง​ไว้ ​พอ​นั่งลง​ดื่ม​กาแฟ ​ไม่​มี​ดินสอ ​ไม่​มี​กระดาษ ​ไม่​มี​ห้องสมุด​ให้​ค้น ​เขา​ตั้งคำถาม​กับ​ตัวเอง​ว่า​เส้นทาง​ที่​สั้น​ที่สุด​ระหว่าง​เมือง​ดัตช์​สอง​เมือง​คือ​เส้น​ไหน ​ตัวเลข​ยี่สิบ​นาที​มาจาก​ปาก​เขา​เอง​ใน​ภายหลัง (David Gries, "Edsger Dijkstra and the Shortest-Path Algorithm," Cornell CS) ​วิธี​ที่​เขา​ร่าง​เช้า​วันนั้น​มี​สอง​ก้าว — ​ขยาย​กลุ่ม​เมือง​ที่​รู้​ระยะสั้น​ที่สุด​จาก​จุด​ตั้งต้น​แน่นอน​แล้ว ​และ​ทุก​ก้าว​เพิ่ม​เมือง​ที่​ยัง​ไม่​ได้​ไป​ซึ่ง​ตอนนี้​ใกล้​ที่สุด​เข้าไป — ​เจ็ด​ทศวรรษ​ให้หลัง​ยัง​ไม่​มี​ใคร​แทน​มัน ​เขา​ไม่​ได้​ตีพิมพ์​จน​อีก​สาม​ปี​ต่อมา ​และ​ตีพิมพ์​เป็น​โน้ต​สาม​หน้าที่​เขียน​อย่าง​ประหยัด ​แก้ปัญหา​กราฟ​สอง​ข้อ​ที่​ไม่​เกี่ยว​กัน​เลย ​ใน​เนื้อที่​ที่​บทความ​ส่วนใหญ่​ใช้​เขียน​แค่​บทคัดย่อ (Dijkstra, "A Note on Two Problems in Connexion with Graphs," Numerische Mathematik 1 (1959))

There is a pleasing, almost too-neat symmetry in the fact that a book called The Shortest Path arrives, in its fifth chapter, at an algorithm literally named for finding shortest paths, invented over coffee in less time than it takes to read this paragraph twice. But the neatness is real, not manufactured, and it marks the hinge this chapter turns on. Chapter 04 showed a generation of scientists discovering that real-world problems — convoys, diets, factories — could be captured as mathematical objects and solved by general-purpose procedures. This chapter is about what happened next: those procedures themselves became objects of study. People began asking not just "does a method exist?" but "how good a method can exist, and how would we know?" Search — the raw, brute business of trying paths through a space of possibilities — became a subject with its own theory, its own proofs, and eventually its own machines.

​หนังสือ​ชื่อ ​เส้นทาง​ที่​สั้น​ที่สุด ​เดิน​มาถึง​บท​ที่​ห้า​แล้ว​เจอ​อัลกอริทึม​ที่ตั้ง​ชื่อ​ตาม​การหา​เส้นทาง​สั้น​ที่สุด​ตรงๆ ​คิด​ขึ้น​ระหว่าง​จิบ​กาแฟ ​ใน​เวลา​น้อยกว่า​ที่​ใช้​อ่าน​ย่อหน้า​นี้​สอง​รอบ ​ความสมมาตร​นี้​น่าพอใจ ​เกือบจะ​เรียบร้อย​เกินไป ​แต่​มัน​เป็น​ของจริง ​ไม่​ได้​จัดฉาก ​และ​มัน​คือ​บานพับ​ที่​บท​นี้​หมุน​อยู่​บน ​บท​ที่ 04 ​แสดงให้เห็น​นักวิทยาศาสตร์​รุ่น​หนึ่ง​ค้นพบ​ว่า​ปัญหา​ใน​โลก​จริง — ​กองเรือ​คุ้มกัน ​สูตร​อาหาร ​โรงงาน — ​จับ​ใส่​กรอบ​เป็น​วัตถุ​ทาง​คณิตศาสตร์​แล้ว​แก้​ด้วย​ขั้นตอนวิธี​อเนกประสงค์​ได้ ​บท​นี้​ว่าด้วย​สิ่ง​ที่เกิด​ขึ้น​ต่อจากนั้น: ​ขั้นตอนวิธี​เหล่านั้น​เอง​กลายเป็น​วัตถุ​ที่​ถูก​ศึกษา ​คำถาม​เปลี่ยน​จาก "​มี​วิธี​อยู่​ไหม" ​เป็น "​วิธี​ที่ ​ดี​แค่​ไหน ​จึง​จะ​มี​อยู่​ได้ ​และ​เรา​จะ​รู้​ได้​อย่างไร" ​การค้นหา (search) — ​งาน​ดิบ​ที่​ใช้กำลัง​ล้วน​ลอง​เดินเส้น​ทาง​ต่างๆ ​ผ่าน​พื้นที่​ของ​ความเป็นไปได้ — ​กลายเป็น​วิชา​ที่​มี​ทฤษฎี​ของ​ตัวเอง ​มี​บทพิสูจน์​ของ​ตัวเอง ​และ​ในที่สุด​ก็​มี​เครื่องจักร​ของ​ตัวเอง

The Man Whose Name Became a Word

​ชาย​ผู้​มีชื่อ​กลายเป็น​คำศัพท์

The word for what Dijkstra did that morning — devise a step-by-step procedure guaranteed to reach a correct answer — is algorithm, and the word has its own long detour before it lands in a computer science course.

​สิ่ง​ที่ Dijkstra ​ทำ​เช้า​วันนั้น — ​คิด​ขั้นตอน​ทีละ​ก้าว​ที่​รับประกัน​ว่า​จะ​ไป​ถึง​คำตอบ​ที่​ถูกต้อง — ​มีชื่อ​เรียก​ว่า ​อัลกอริทึม ​คำ​นี้​เดินทาง​อ้อม​มายาว​ก่อน​จะ​ลงเอย​ใน​ห้องเรียน​วิทยาการ​คอมพิวเตอร์

It comes from the Latinized name of a ninth-century scholar working in the House of Wisdom in Baghdad: Muhammad ibn Musa al-Khwarizmi. His treatise on Hindu-Arabic numerals, translated into Latin as Algoritmi de numero Indorum, gave medieval Europe both a new way to calculate — the positional decimal system, replacing Roman numerals — and, eventually, a new word: algorismus, referring at first specifically to arithmetic done this new way. Only much later, in the twentieth century, did "algorithm" widen into its modern sense: any finite, unambiguous, mechanically executable procedure for solving a class of problems (findanexpert.unimelb.edu.au, "Why are algorithms called algorithms?"; NPR, "How 'algorithm' got its name from a 9th-century Persian mathematician"). Al-Khwarizmi's other great book gave mathematics the word algebra, from al-jabr, "completion" or "restoration" — a term for the operation of moving a quantity from one side of an equation to the other. The scribes of chapter 01 wrote down individual solved problems as teaching examples; al-Khwarizmi wrote down the procedure itself, stripped of any particular numbers, so that it could be applied to numbers no one had thought of yet. That abstraction — the method as an object in its own right, portable across every instance of a problem — is the direct ancestor of everything in this chapter.

​คำ​นี้​มาจาก​ชื่อ​ใน​รูป​ละติน​ของ​นักปราชญ์​ศตวรรษ​ที่​เก้า​ผู้ทำงาน​อยู่​ใน​บ้าน​แห่ง​ปัญญา (House of Wisdom) ​ที่​แบกแดด: Muhammad ibn Musa al-Khwarizmi ​ตำรา​ของ​เขา​ว่าด้วย​เลข​ฮินดู-​อารบิก ​ถูก​แปล​เป็น​ละติน​ใน​ชื่อ Algoritmi de numero Indorum ​มัน​มอบ​สอง​อย่าง​ให้​ยุโรป​ยุค​กลาง ​อย่าง​แรก​คือ​วิธี​คำนวณ​แบบ​ใหม่ — ​ระบบ​ทศนิยม​เชิง​ตำแหน่ง​ที่มา​แทน​เลขโรมัน ​อย่าง​ที่สอง​มา​ช้า​กว่า ​คือ​คำ​ใหม่​คำ​หนึ่ง: algorismus ​ตอนแรก​หมายถึง​เลขคณิต​ที่​ทำ​ด้วย​วิธี​ใหม่​นี้​โดยเฉพาะ ​คำ​ว่า "algorithm" ​ต้อง​รอ​ถึง​ศตวรรษ​ที่​ยี่สิบ​จึง​ขยาย​มาสู่​ความหมาย​สมัยใหม่: ​ขั้นตอนวิธี​ใดๆ ​ที่​มี​จำนวน​ก้าว​จำกัด ​ไม่​กำกวม ​และ​เครื่องจักร​ทำตาม​ได้ ​สำหรับ​แก้ปัญหา​ทั้ง​ชั้น (findanexpert.unimelb.edu.au, "Why are algorithms called algorithms?"; NPR, "How 'algorithm' got its name from a 9th-century Persian mathematician") ​หนังสือ​เล่ม​ใหญ่​อีก​เล่ม​ของ al-Khwarizmi ​มอบ​คำ​ว่า algebra ​ให้​คณิตศาสตร์ ​มาจาก al-jabr ​ที่​แปล​ว่า "​การเติม​ให้​ครบ" ​หรือ "​การคืน​สภาพ" — ​ศัพท์​เรียก​การย้าย​ปริมาณ​จาก​ข้าง​หนึ่ง​ของ​สมการ​ไป​อีก​ข้าง​หนึ่ง ​ความต่าง​จาก​อาลักษณ์​ใน​บท​ที่ 01 ​อยู่​ตรงนี้: ​อาลักษณ์​จด​โจทย์​ที่​แก้​แล้ว​ทีละ​ข้อ​ไว้​เป็นตัว​อย่าง​สอน; al-Khwarizmi ​จด ​ตัว​ขั้นตอนวิธี​เอง ​ถอด​ตัวเลข​เฉพาะ​ออก​หมด ​เพื่อให้​เอา​ไป​ใช้กับ​ตัวเลข​ที่​ยัง​ไม่​มี​ใคร​นึกถึง​ได้ ​วิธี​ใน​ฐานะ​วัตถุ​ที่​มี​สถานะ​ของ​ตัวเอง ​ยก​ไป​ใช้ได้​กับ​ทุก​อิน​สแตนซ์ (instance) ​ของ​ปัญหา — ​นามธรรม​ข้อ​นี้​คือ​บรรพบุรุษ​สาย​ตรง​ของ​ทุกอย่าง​ใน​บท​นี้

The Primitive Moves: Sweeping Outward, Plunging Deep

​ท่า​พื้นฐาน: ​กวาด​ออก​ไป​รอบตัว ​กับ​ดำ​ดิ่ง​ลง​ลึก

Before Dijkstra's algorithm, and underneath it, sit two even more basic strategies for exploring a space of possibilities, and it is worth naming them plainly because everything more sophisticated in this chapter is built from them.

​ใต้​อัลกอริทึม​ของ Dijkstra ​มี​กลยุทธ์​พื้นฐาน​กว่า​อีก​สอง​อย่าง​สำหรับ​สำรวจ​พื้นที่​ของ​ความเป็นไปได้ ​ทั้งสอง​มา​ก่อน​มัน ​ควร​เรียกชื่อ​ให้​ชัด ​เพราะ​ทุกอย่าง​ที่​ซับซ้อน​กว่า​นั้น​ใน​บท​นี้​สร้าง​ขึ้น​จาก​สอง​อย่างนี้

Imagine a maze, or a family tree, or a web of friendships, represented the way chapter 02 taught Euler to represent Königsberg: as a graph of nodes and connecting edges. Breadth-first search starts at one node and explores outward in expanding rings — first everything one step away, then everything two steps away, and so on — guaranteeing that the first time it reaches any given node, it has found the shortest possible route to it, measured in number of steps. It was reinvented for exactly this purpose in 1959 by Edward F. Moore, who wanted a mechanical way to find the shortest way out of a maze, though a similar idea had been buried, unpublished, in Konrad Zuse's rejected 1945 doctoral thesis (Wikipedia, "Breadth-first search"). Depth-first search, by contrast, commits to a single path and follows it as far as it can go before backing up — plunging down one corridor of the maze to its very end before trying another. It has no built-in guarantee of finding the shortest route, but it uses far less memory to run and, in the hands of Robert Tarjan and John Hopcroft in the early 1970s, turned out to unlock efficient solutions to a surprising range of graph problems, from testing whether a map can be drawn without crossing lines to finding a network's structural weak points (Wikipedia, "Depth-first search").

​เริ่ม​จาก​เขาวงกต ​หรือ​แผนผัง​ตระกูล ​หรือ​ใย​ความสัมพันธ์​ของ​เพื่อนฝูง ​แทน​ด้วย​วิธี​เดียว​กับ​ที่​บท​ที่ 02 ​เล่า​ว่า Euler ​แทน Königsberg: ​เป็น​กราฟ​ของ​โหนด​กับ​เส้น​เชื่อม ​ค้น​ตาม​ความกว้าง (breadth-first search, BFS) ​เริ่ม​ที่​โหนด​หนึ่ง​แล้ว​สำรวจ​ออก​ไป​เป็น​วง​ที่​ขยาย​กว้าง​ขึ้น — ​ทุกอย่าง​ที่​ห่าง​หนึ่ง​ก้าว​ก่อน ​แล้ว​ทุกอย่าง​ที่​ห่าง​สอง​ก้าว ​ไล่​ไป​เรื่อยๆ ​ผล​คือ​การรับประกัน​ข้อ​หนึ่ง: ​ครั้งแรก​ที่​มัน​ไป​ถึง​โหนด​ใด​ก็ตาม ​มัน​ได้​พบ​เส้นทาง*​ที่​สั้น​ที่สุด*​ไป​ยัง​โหนด​นั้น​แล้ว ​วัด​ด้วย​จำนวน​ก้าว Edward F. Moore ​คิด​มัน​ขึ้น​ใหม่​เพื่อ​จุดประสงค์​นี้​พอดี​ใน​ปี 1959 ​เขา​ต้องการ​วิธี​เชิงกล​ไก​ใน​การหาทาง​ออก​ที่​สั้น​ที่สุด​จาก​เขาวงกต ​ไอเดีย​คล้าย​กัน​ฝัง​อยู่​ก่อน​แล้ว​โดย​ไม่​ได้​ตีพิมพ์ ​ใน​วิทยานิพนธ์​ปริญญาเอก​ปี 1945 ​ของ Konrad Zuse ​ที่​ถูก​ปฏิเสธ (Wikipedia, "Breadth-first search") ​ค้น​ตาม​ความลึก (depth-first search, DFS) ​ทำ​ตรงกันข้าม: ​เลือก​เส้นทาง​เดียว​แล้ว​เดินตาม​ให้​ไกล​ที่สุด​ก่อน​ถอยกลับ — ​ดำ​ดิ่ง​ลง​ช่องทาง​หนึ่ง​ของ​เขาวงกต​จน​สุด​ทาง ​แล้วจึง​ลอง​ช่อง​อื่น ​มัน​ไม่​รับประกัน​ว่า​จะ​พบ​เส้นทาง​สั้น​ที่สุด ​แต่​ใช้​หน่วยความจำ​น้อยกว่า​มาก ​และ​ใน​มือ​ของ Robert Tarjan ​กับ John Hopcroft ​ช่วงต้น​ทศวรรษ 1970 ​มัน​ปลดล็อก​คำตอบ​ที่​มีประสิทธิภาพ​ให้​ปัญหา​กราฟ​หลายชนิด​ที่​ไม่​มี​ใคร​คาด ​ตั้งแต่​ทดสอบ​ว่า​แผนที่​หนึ่ง​วาด​โดย​ไม่​มี​เส้น​ตัดกัน​ได้​หรือไม่ ​ไป​จนถึง​หา​จุดอ่อน​เชิง​โครงสร้าง​ของ​เครือข่าย (Wikipedia, "Depth-first search")

Neither strategy knows anything about the problem it is solving beyond the bare shape of the graph. That ignorance is their strength — they work on any graph whatsoever — and their weakness: they waste enormous effort exploring directions that, to anyone who actually understood the problem, would look obviously hopeless. Dijkstra's algorithm is breadth-first search's more disciplined cousin, expanding outward not ring by ring but always toward whichever unvisited node is currently cheapest to reach — which is why it finds not just a short path but provably the shortest one, for any graph where distances are never negative.

​ทั้งสอง​กลยุทธ์​ไม่​รู้​อะไร​เลย​เกี่ยวกับ​ปัญหา​ที่​กำลัง​แก้ ​นอกจาก​รูปร่าง​เปล่าๆ ​ของ​กราฟ ​ความไม่รู้​นั้น​คือ​จุดแข็ง — ​ใช้ได้​กับ​กราฟ​ทุกชนิด — ​และ​คือ​จุดอ่อน: ​มัน​ผลาญ​แรง​ไป​กับ​ทิศทาง​ที่​ใครก็ตาม​ที่​เข้าใจ​ปัญหา​จริงๆ ​จะ​เห็น​ทันที​ว่า​ไร้​ความหวัง ​อัลกอริทึม​ของ Dijkstra ​คือ​ญาติ​ที่​มีวินัย​กว่า​ของ BFS ​มัน​ไม่​ขยาย​ทีละ​วง ​แต่​มุ่ง​ไป​ยัง​โหนด​ที่​ยัง​ไม่​ได้​ไป​ซึ่ง​ตอนนี้​ไป​ถึง​ได้​ถูกที่​สุด​เสมอ ​นั่น​คือ​เหตุผล​ที่​มัน​ไม่​ได้​แค่​หา​เส้นทาง​สั้น*​เส้น​หนึ่ง* ​แต่​พิสูจน์​ได้​ว่า​เป็น​เส้น*​ที่​สั้น​ที่สุด* ​สำหรับ​กราฟ​ใด​ก็ตาม​ที่​ระยะทาง​ไม่​เคย​ติดลบ

A Mouse Named Theseus

​หนู​ตัว​หนึ่ง​ชื่อ Theseus

Six years before Dijkstra's coffee, at Bell Labs in 1950, Claude Shannon — already famous for founding information theory — built a smaller, stranger monument to the same idea: a maze-solving mechanical mouse he named Theseus, after the hero who navigated the Minotaur's labyrinth by unspooling a thread behind him.

​หก​ปีก่อน​กาแฟ​ถ้วย​นั้น​ของ Dijkstra ​ที่ Bell Labs ​ใน​ปี 1950 Claude Shannon ​สร้าง​อนุสาวรีย์​ของ​ไอเดีย​เดียวกัน​ที่​เล็ก​กว่า​และ​แปลก​กว่า ​เขา​มีชื่อเสียง​อยู่แล้ว​จาก​การก่อตั้ง​ทฤษฎี​สารสนเทศ ​สิ่ง​ที่​เขา​สร้าง​คือ​หนู​กลไก​แก้​เขาวงกต ​เขา​ตั้งชื่อ​มัน​ว่า Theseus ​ตาม​วีรบุรุษ​ผู้​หาทาง​ใน​เขาวงกต​ของ​มิ​โน​ทอร์​ด้วย​การคลี่​เส้นด้าย​ทิ้ง​ไว้​ข้างหลัง

Theseus was, mechanically, a magnet wrapped in a metal shell, dragged along underneath a re-configurable five-by-five maze by an electromagnet hidden beneath the floor, itself driven by a bank of telephone relays functioning as memory. Released into an unfamiliar maze, the mouse would blunder forward, bumping walls, backing up, trying again — a physical enactment of depth-first search with backtracking — until it stumbled onto a hidden slice of "cheese" that closed an electrical contact. But every turn it made was recorded in the relay memory as it went. Reset to the start of the same maze, Theseus would now glide directly to the goal without a single wrong turn, having converted its earlier blind search into a stored, reusable solution (cyberneticzoo.com, "1952 – 'Theseus' Maze-Solving Mouse – Claude Shannon"). This is worth pausing on, because it is a genuinely early and genuinely physical demonstration of the idea that would come to define machine intelligence: search followed by memory is learning. The first pass through a space costs the full price of exploring it. Every later pass can spend that stored knowledge instead of paying again — the same insight, in miniature and in copper wire, that would let Bellman's dynamic programming (chapter 04) avoid resolving identical sub-problems, and that lets a chess program in chapter 10 remember a position it has already evaluated.

​ใน​เชิงกล​ไก Theseus ​คือ​แม่เหล็ก​หุ้ม​เปลือก​โลหะ ​มัน​ถูก​ลาก​ไป​ใต้​เขาวงกต​ขนาด​ห้า​คูณ​ห้า​ที่​ปรับ​ผัง​ใหม่​ได้ ​ด้วย​แม่เหล็ก​ไฟฟ้า​ที่ซ่อน​อยู่​ใต้​พื้น ​แม่เหล็ก​ไฟฟ้า​นั้น​ถูก​ขับ​ด้วย​แผง​รีเลย์​โทรศัพท์​ที่​ทำหน้าที่​เป็น​หน่วยความจำ ​ปล่อย​เข้า​เขาวงกต​ที่​ไม่​คุ้นเคย ​หนู​จะ​เดิน​ซุ่มซ่าม​ไป​ข้างหน้า ​ชน​กำแพง ​ถอยหลัง ​ลอง​ใหม่ — DFS ​พร้อม​การย้อนรอย (backtracking) ​ใน​รูปธรรม — ​จน​สะดุด​เข้ากับ "​ชีส" ​ชิ้น​ที่ซ่อน​อยู่ ​ซึ่ง​ทำให้​หน้า​สัมผัส​ไฟฟ้า​ปิด​วงจร ​ทุก​การเลี้ยว​ระหว่างทาง​ถูก​บันทึก​ไว้​ใน​หน่วยความจำ​รีเลย์ ​ตั้ง​กลับ​ไป​ที่​จุดเริ่มต้น​ของ​เขาวงกต*​อัน​เดิม* Theseus ​จะ​แล่น​ตรง​ไป​ยัง​เป้าหมาย​โดย​ไม่​เลี้ยว​ผิด​แม้แต่​ครั้ง​เดียว ​การค้นหา​แบบ​ตาบอด​รอบ​ก่อน​กลายเป็น​คำตอบ​ที่เก็บ​ไว้​และ​ใช้​ซ้ำ​ได้ (cyberneticzoo.com, "1952 – 'Theseus' Maze-Solving Mouse – Claude Shannon") ​ตรงนี้​ควร​หยุด​ดู ​เพราะ​มัน​คือ​การสาธิต​ที่​เก่า​จริง​และ​เป็น​รูปธรรม​จริง​ของ​ไอเดีย​ที่​ต่อมา​จะ​นิยาม​ปัญญา​ของ​เครื่องจักร: ​การค้นหา​ที่​ตาม​ด้วย​ความจำ ​คือ​การเรียนรู้ ​รอบ​แรก​จ่าย​ราคา​เต็ม​ของ​การสำรวจ​พื้นที่ ​ทุก​รอบ​หลังจากนั้น​ใช้​ความรู้​ที่เก็บ​ไว้​แทน​การจ่าย​ซ้ำ ​นี่​คือ​การหยั่ง​เห็น (insight) ​เดียวกัน ​ใน​ขนาด​จิ๋ว​และ​ใน​สาย​ทองแดง ​ที่​ทำให้​กำหนดการ​พลวัต (dynamic programming) ​ของ Bellman (​บท​ที่ 04) ​ไม่ต้อง​แก้ปัญหา​ย่อย​ที่​เหมือนกัน​ซ้ำ ​และ​ที่​ทำให้​โปรแกรม​หมากรุก​ใน​บท​ที่ 10 ​จำ​ตำแหน่ง​ที่​มัน​ประเมิน​ไป​แล้ว​ได้

Optimism That Never Lies

​การมองโลกในแง่ดี​ที่​ไม่​เคย​โกหก

Dijkstra's algorithm is exhaustive within its expanding frontier — it never skips a node that might turn out to matter — and that thoroughness is also its limit. On a graph with millions of nodes, exploring "everything closer than the current best" before considering anything farther away wastes effort in every direction that has nothing to do with where you are actually trying to go.

​ความครบถ้วน​ของ​อัลกอริทึม​ของ Dijkstra ​คือ​ขีดจำกัด​ของ​มัน​ด้วย ​มัน​ไล่​ครบ​ทุก​โหนด​ภายใน​แนวหน้า​ที่​กำลัง​ขยาย ​ไม่​เคย​ข้าม​โหนด​ที่​อาจ​กลายเป็น​เรื่องสำคัญ ​บน​กราฟ​ที่​มี​โหนด​เป็น​ล้าน ​การสำรวจ "​ทุกอย่าง​ที่​ใกล้​กว่า​ค่า​ดี​ที่สุด​ตอนนี้" ​ก่อน​จะ​พิจารณา​อะไร​ที่​ไกล​กว่า​นั้น ​ผลาญ​แรง​ไป​ใน​ทุก​ทิศ​ที่​ไม่​เกี่ยวกับ​ที่​ที่ตั้ง​ใจ​จะ​ไป​จริงๆ

The fix arrived in 1968 from a robotics project at the Stanford Research Institute, where researchers Peter Hart, Nils Nilsson, and Bertram Raphael were trying to give a mobile robot named Shakey — one of the first machines able to reason about its own actions in a real room — a way to plan efficient routes around obstacles without exploring the entire building's floor plan every time (Engineering and Technology History Wiki, "Milestones: SHAKEY: The World's First Mobile Intelligent Robot, 1972"). Their algorithm, which came to be called A* (pronounced "A-star"), adds one ingredient to Dijkstra's method: at each step, instead of ranking unexplored nodes purely by the distance already traveled to reach them, A* ranks them by that distance plus a guess — a heuristic estimate of how much farther the goal must still be. On a road map, the straight-line, "as the crow flies" distance to the destination is a natural guess: it is easy to compute and it can never overestimate the true remaining driving distance, since no road is ever shorter than a straight line between the same two points.

​ทางแก้​มาถึง​ใน​ปี 1968 ​จาก​โครงการ​หุ่นยนต์​ที่ Stanford Research Institute ​นักวิจัย​สาม​คน Peter Hart, Nils Nilsson ​และ Bertram Raphael ​ต้องการ​ให้​หุ่นยนต์​เคลื่อนที่​ชื่อ Shakey — ​หนึ่ง​ใน​เครื่องจักร​รุ่น​แรก​ที่​ให้เหตุผล​ถึง​สิ่ง​ที่​ตัวเอง​ทำ​ใน​ห้อง​จริง​ได้ — ​วางแผน​เส้นทาง​อ้อม​สิ่งกีดขวาง​อย่าง​ประหยัด ​โดย​ไม่ต้อง​สำรวจ​ผัง​พื้น​ทั้ง​อาคาร​ทุกครั้ง (Engineering and Technology History Wiki, "Milestones: SHAKEY: The World's First Mobile Intelligent Robot, 1972") ​อัลกอริทึม​ของ​พวกเขา​ภายหลัง​ได้ชื่อ​ว่า A\ (​อ่าน​ว่า "​เอ-​สตาร์") ​มัน​เติม​ส่วนผสม​เพียง​หนึ่ง​อย่าง​ลง​ใน​วิธี​ของ Dijkstra: ​ใน​แต่ละ​ก้าว ​แทนที่จะ​จัดอันดับ​โหนด​ที่​ยัง​ไม่​สำรวจ​ด้วย​ระยะทาง​ที่​เดิน​มาถึง​มัน​แล้ว​ล้วนๆ A\ ​จัดอันดับ​ด้วย​ระยะทาง​นั้น ​บวก​กับ​การเดา — ​ค่า​ประมาณ​จาก​วิธี​เดา​อย่าง​มี​หลัก (heuristic) ​ว่า​เป้าหมาย​น่าจะ​ยังอยู่​ไกล​ออก​ไป​อีก​เท่าไร ​บน​แผนที่​ถนน ​ระยะ​เส้นตรง​แบบ "​นก​บิน​ตรง" ​ไป​ยัง​จุดหมาย​คือ​ตัว​เดา​ที่​เหมาะ​เอง ​คำนวณ​ง่าย ​และ​ไม่​มีทาง​ประเมิน​ระยะ​ขับรถ​ที่​เหลือ​จริง​เกิน​ความจริง ​เพราะ​ไม่​มี​ถนน​เส้น​ไหน​สั้น​กว่า​เส้นตรง​ระหว่าง​จุด​สอง​จุด​เดียวกัน

That last property — never overestimating — is the entire secret, and it is worth explaining in plain terms because it is one of the most beautiful small theorems in this book's whole story. A heuristic with this property is called admissible: it may be wrong, but it is never wrong in the optimistic direction beyond the truth — it can underestimate the remaining distance, but it can never claim a path is shorter than it actually is. Give A* an admissible heuristic, however crude, and it is mathematically guaranteed to still find the truly shortest path, exactly as Dijkstra's algorithm would, while typically exploring only a sliver of the space Dijkstra's algorithm would have to touch. The heuristic doesn't need to be right. It only needs to never lie in the direction of false hope. Optimism, bounded so it can never overshoot the truth, turns out to be free — you get to search faster and you are never fooled into a wrong answer. Hart, Nilsson, and Raphael's original 1968 paper, "A Formal Basis for the Heuristic Determination of Minimum Cost Paths in Graphs," struggled to find a journal willing to publish it, and Raphael, frustrated, eventually helped found a new AI journal partly so the paper would have somewhere to appear (IEEE Transactions on Systems Science and Cybernetics 4, no. 2 (1968); doi 10.1109/TSSC.1968.300136). A* now runs, in one variant or another, inside video game pathfinding, logistics routing, and the descendants of Shakey still driving across the surface of Mars.

​คุณสมบัติ​ข้อ​สุดท้าย​นั้น — ​ไม่​ประเมิน​เกิน — ​คือ​ความลับ​ทั้งหมด ​และ​สมควร​อธิบาย​ด้วย​คำธรรมดา ​เพราะ​มัน​คือ​หนึ่ง​ใน​ทฤษฎีบท​เล็กๆ ​ที่​งาม​ที่สุด​ใน​เรื่องราว​ทั้งหมด​ของ​หนังสือ​เล่ม​นี้ heuristic ​ที่​มี​คุณสมบัติ​นี้​เรียก​ว่า ​ไม่​ประเมิน​เกิน (admissible): ​มัน​ผิด​ได้ ​แต่​ไม่​เคย​ผิด​ไป​ทาง​มองโลกในแง่ดี​เกิน​ความจริง ​มัน​ประเมิน​ระยะ​ที่​เหลือ​ต่ำกว่า​จริง​ได้ ​แต่​ไม่​มี​วัน​อ้างว่า​เส้นทาง​หนึ่ง​สั้น​กว่า​ที่​มัน​เป็นจริง ​ให้ admissible heuristic ​กับ A\* ​ต่อให้​หยาบ​แค่​ไหน ​มัน​ก็​ยัง​รับประกัน​ทาง​คณิตศาสตร์​ว่า​จะ​หา​เส้นทาง​ที่​สั้น​ที่สุด*​จริงๆ* ​พบ ​เหมือน​ที่​อัลกอริทึม​ของ Dijkstra ​ทำ ​แต่​โดยทั่วไป​แตะ​พื้นที่​เพียง​เสี้ยว​เดียว​ของ​ที่​อัลกอริทึม​ของ Dijkstra ​ต้อง​แตะ heuristic ​ไม่​จำเป็นต้อง​ถูก ​มัน​แค่​ต้อง​ไม่​โกหก​ไป​ทาง​ความหวัง​ลมๆ ​แล้งๆ ​การมองโลกในแง่ดี​ที่​ถูก​ล็อก​ไว้​ไม่​ให้​เลย​ความจริง ​จึง​กลายเป็น​ของ​ฟรี ​ค้นหา​ได้​เร็ว​ขึ้น ​และ​ไม่​มี​วัน​ถูก​หลอก​ไป​สู่​คำตอบ​ที่​ผิด ​บทความ​ต้นฉบับ​ปี 1968 ​ของ Hart, Nilsson ​และ Raphael ​ชื่อ "A Formal Basis for the Heuristic Determination of Minimum Cost Paths in Graphs" ​หา​วารสาร​ที่​ยอม​ตีพิมพ์​แทบ​ไม่​ได้ ​ในที่สุด Raphael ​ที่​อึดอัด​กับ​เรื่อง​นี้​ก็​มีส่วน​ก่อตั้ง​วารสาร AI ​ฉบับ​ใหม่​ขึ้น​มา ​ส่วนหนึ่ง​ก็​เพื่อให้​บทความ​มี​ที่​ลง (IEEE Transactions on Systems Science and Cybernetics 4, no. 2 (1968); doi 10.1109/TSSC.1968.300136) ​ทุกวันนี้ A\* ​ทำงาน​อยู่​ใน​รูปแบบ​ใด​รูปแบบ​หนึ่ง ​ทั้ง​ใน​การหา​เส้นทาง​ของ​วิดีโอ​เกม ​การจัด​เส้นทาง​โลจิสติกส์ ​และ​ใน​ลูกหลาน​ของ Shakey ​ที่​ยัง​แล่น​อยู่​บน​พื้นผิว​ดาวอังคาร

Machines That Prove Theorems

​เครื่องจักร​ที่​พิสูจน์​ทฤษฎีบท

While Shannon's mouse learned mazes and Dijkstra timed his coffee, a separate group at the RAND Corporation was attempting something that, in 1955, sounded closer to science fiction than engineering: teaching a machine to do mathematics.

​ขณะที่​หนู​ของ Shannon ​เรียนรู้​เขาวงกต​และ Dijkstra ​จับเวลา​กาแฟ​ของ​เขา ​อีก​กลุ่ม​หนึ่ง​ที่ RAND Corporation ​กำลัง​สอน​เครื่องจักร​ให้​ทำ​คณิตศาสตร์ ​ใน​ปี 1955 ​เรื่อง​นี้​ฟัง​ดู​ใกล้​นิยาย​วิทยาศาสตร์​มากกว่า​วิศวกรรม

Allen Newell, Herbert Simon, and the programmer Cliff Shaw set out to build a program that could prove theorems in formal logic — specifically, theorems from Principia Mathematica, the monumental three-volume attempt by Alfred North Whitehead and Bertrand Russell to derive all of mathematics from a small set of logical axioms. Their program, the Logic Theorist, represented each logical statement as a tree-shaped data structure and searched through chains of substitution, detachment, and inference rules — the same problem-space idea chapter 00 traces to Newell and Simon's later theoretical work — hunting for a sequence of legal steps connecting the axioms to the theorem to be proved. Because the space of possible deductions explodes combinatorially with every added step, Newell and Simon needed a way to prune obviously unpromising branches, and borrowed a word for the rules of thumb they used to do it: heuristics, a term Newell had encountered in George Pólya's How to Solve It, the handbook chapter 03 covers in full (Wikipedia, "Logic Theorist").

Allen Newell, Herbert Simon ​และ​โปรแกรมเมอร์ Cliff Shaw ​ตั้งใจ​สร้าง​โปรแกรม​ที่​พิสูจน์​ทฤษฎีบท​ใน​ตรรกศาสตร์​รูป​นัย​ได้ ​เป้าหมาย​เจาะจง​คือ​ทฤษฎีบท​จาก Principia Mathematica ​งาน​สาม​เล่ม​ของ Alfred North Whitehead ​กับ Bertrand Russell ​ที่​พยายาม​อนุมาน​คณิตศาสตร์​ทั้งหมด​จาก​สัจพจน์​ทาง​ตรรกะ​ชุด​เล็กๆ ​โปรแกรม​ของ​พวกเขา​ชื่อ Logic Theorist ​มัน​แทน​ข้อความ​ทาง​ตรรกะ​แต่ละ​ข้อ​ด้วย​โครงสร้าง​ข้อมูล​รูป​ต้นไม้ ​แล้ว​ค้นหา​ไป​ตาม​โซ่​ของ​การแทนค่า ​การตัดออก ​และ​กฎ​การอนุมาน ​เพื่อ​ล่า​ลำดับ​ก้าว​ที่​ถูก​กติกา​ซึ่ง​เชื่อม​สัจพจน์​เข้ากับ​ทฤษฎีบท​ที่​ต้อง​พิสูจน์ ​นี่​คือ​ไอเดีย​พื้นที่​ปัญหา (problem space) ​อัน​เดียว​กับ​ที่​บท​ที่ 00 ​สืบ​ย้อน​ไป​ถึง​งาน​ทฤษฎี​ใน​ภายหลัง​ของ Newell ​กับ Simon ​พื้นที่​ของ​การอนุมาน​ที่​เป็นไปได้​ระเบิด​ออกแบบ​เชิง​การจัด​หมู่​ทุกครั้งที่​เพิ่ม​ก้าว​เข้าไป​หนึ่ง​ก้าว Newell ​กับ Simon ​จึง​ต้อง​ตัด​กิ่ง​ที่​เห็นชัด​ว่า​ไม่​มี​อนาคต​ทิ้ง ​และ​หยิบยืม​คำ​มา​เรียก​กฎ​สามัญสำนึก​ที่​ใช้​ทำ​เรื่อง​นั้น: heuristic Newell ​เคย​เจอ​คำ​นี้​ใน How to Solve It ​ของ George Pólya ​คู่มือ​ที่​บท​ที่ 03 ​ครอบคลุม​ไว้​เต็มๆ (Wikipedia, "Logic Theorist")

Completed in 1956, the Logic Theorist went on to prove 38 of the first 52 theorems in Chapter 2 of Principia Mathematica — and, in one case, found a proof more elegant than the one Whitehead and Russell had labored over by hand. The theorem is commonly cited by the number 2.85, although a documented note on Wikipedia's account points out that in the original 1910 and 1963 Cambridge editions of Principia the same theorem is actually numbered 2.53 — a small numbering discrepancy in the popular retelling worth flagging exactly because this book asks its readers to distrust anecdotes that have been smoothed in the retelling. What is well attested is Russell's reaction: Simon showed him the machine's shorter proof, and Russell reportedly responded with delight. The two men then tried to publish the new proof in The Journal of Symbolic Logic, only to have it rejected on the grounds that a new proof of an elementary theorem was not a notable result — the reviewers apparently missing, or unmoved by, the fact that one of the "authors" credited was a computer program (Wikipedia, "Logic Theorist").

Logic Theorist ​สร้าง​เสร็จ​ใน​ปี 1956 ​และ​พิสูจน์​ทฤษฎีบท​ได้ 38 ​ข้อ​จาก 52 ​ข้อ​แรก​ใน​บท​ที่ 2 ​ของ Principia Mathematica ​ใน​กรณี​หนึ่ง​มัน​พบ​บทพิสูจน์​ที่​สง่างาม​กว่า​บทพิสูจน์​ที่ Whitehead ​กับ Russell ​ตรากตรำ​ทำ​ด้วยมือ ​หมายเลข​ของ​ทฤษฎีบท​ข้อ​นี้​ไม่​ตรงกัน​สอง​แหล่ง ​เรื่องเล่า​ที่​แพร่หลาย​อ้าง​หมายเลข 2.85 ​แต่​หมายเหตุ​ที่​มี​เอกสาร​รองรับ​ใน​บทความ​ของ Wikipedia ​ชี้​ว่า​ใน​ฉบับ Cambridge ​ปี 1910 ​และ 1963 ​ของ Principia ​ทฤษฎีบท​ข้อ​เดียวกัน​นี้​มี​หมายเลข 2.53 ​เล่ม​นี้​กาง​ความคลาดเคลื่อน​นี้​ออก​ให้​เห็น ​เพราะ​เล่ม​นี้​ขอให้​ผู้อ่าน​ไม่​ไว้ใจ​เกร็ด​เล่า​ที่​ถูก​ขัด​ให้​เรียบ​ระหว่าง​การเล่า​ต่อ ​สิ่ง​ที่​มี​หลักฐาน​รองรับ​ดี​คือ​ปฏิกิริยา​ของ Russell: Simon ​เอา​บทพิสูจน์​ที่​สั้น​กว่า​ของ​เครื่อง​ให้​เขา​ดู ​และ​มี​รายงาน​ว่า Russell ​ตอบรับ​ด้วยความยินดี ​ทั้งสอง​คน​พยายาม​ตีพิมพ์​บทพิสูจน์​ใหม่​นี้​ใน The Journal of Symbolic Logic ​วารสาร​ปฏิเสธ ​เหตุผล​คือ​บทพิสูจน์​ใหม่​ของ​ทฤษฎีบท​พื้นฐาน​ไม่​ใช่​ผลงาน​ที่​น่าสนใจ ​ผู้ประเมิน​ดูจะ​มองข้าม ​หรือไม่​ก็​ไม่​รู้สึก​อะไร ​กับ​ข้อเท็จจริง​ที่ว่า​หนึ่ง​ใน "​ผู้เขียน" ​ที่​ให้​เครดิต​ไว้​คือ​โปรแกรมคอมพิวเตอร์ (Wikipedia, "Logic Theorist")

Newell, Simon, and Shaw followed the Logic Theorist with a more ambitious successor between 1957 and 1959: the General Problem Solver, or GPS, intended not merely to prove logic theorems but to tackle any problem expressible as a set of states and legal operators — the general problem-space formalism this book leans on throughout. GPS's central technique, means-ends analysis, is simple to state and turned out to be extraordinarily durable: compare your current state to your goal state, identify the single biggest difference between them, and select whichever available operator is known to reduce differences of exactly that kind. Solve the biggest gap first, then repeat on whatever gap remains. It is, in miniature, a general-purpose engine for narrowing an enormous space one deliberate step at a time, rather than wandering it at random (Wikipedia, "General Problem Solver"; Wikipedia, "Means–ends analysis"). GPS eventually ran into the same wall every general method runs into — later chapters, especially 06, will explain why generality and efficiency pull in opposite directions — but the technique it introduced still shows up, essentially unchanged, inside modern automated planning systems.

​ระหว่าง​ปี 1957 ​ถึง 1959 Newell, Simon ​และ Shaw ​ต่อยอด Logic Theorist ​ด้วย​ทายาท​ที่​ทะเยอทะยาน​กว่า: General Problem Solver ​หรือ GPS ​มัน​ไม่​ได้​ตั้งใจ​แค่​พิสูจน์​ทฤษฎีบท​ตรรกะ ​แต่​จัดการ​ปัญหา​ใด​ก็ตาม​ที่​เขียน​ออกมา​เป็น​ชุด​ของ​สถานะ (state) ​กับ​ตัวดำเนินการ (operator) ​ที่​ถูก​กติกา​ได้ — ​รูป​นัย​ของ​พื้นที่​ปัญหา​แบบ​ทั่วไป​ที่​หนังสือ​เล่ม​นี้​พิง​อยู่​ตลอด ​เทคนิค​หลัก​ของ GPS ​คือ​การวิเคราะห์​วิธี-​เป้าหมาย (means–ends analysis) ​พูด​ออกมา​ง่าย ​และ​ทนทาน​เกินคาด: ​เทียบ​สถานะ​ปัจจุบัน​กับ​สถานะ​เป้าหมาย ​ระบุ​ความต่าง​ที่​ใหญ่​ที่สุด​ข้อ​เดียว ​แล้ว​เลือก operator ​ที่​มี​อยู่ตัว​ที่​รู้​ว่า​ลด​ความต่าง​ชนิด​นั้น​พอดี ​แก้​ช่องว่าง​ที่​ใหญ่​ที่สุด​ก่อน ​แล้ว​ทำซ้ำ​กับ​ช่องว่าง​ที่​เหลือ ​มัน​คือ​เครื่องยนต์​อเนกประสงค์​ขนาด​จิ๋ว​สำหรับ​บีบ​พื้นที่​มหาศาล​ให้​แคบ​ลง​ทีละ​ก้าว​อย่าง​ตั้งใจ ​แทนที่จะ​เดิน​เตร็ดเตร่​ใน​นั้น​แบบ​สุ่ม (Wikipedia, "General Problem Solver"; Wikipedia, "Means–ends analysis") ​ในที่สุด GPS ​ก็​ชน​กำแพง​เดียว​กับ​ที่​วิธี​ทั่วไป​ทุก​วิธี​ชน ​บท​หลังจากนี้ ​โดยเฉพาะ​บท​ที่ 06 ​จะ​อธิบาย​ว่า​ทำไม​ความเป็น​ทั่วไป​กับ​ประสิทธิภาพ​ถึง​ดึง​กัน​คนละ​ทาง ​แต่​เทคนิค​ที่​มัน​แนะนำ​ไว้​ยังอยู่ ​แทบ​ไม่​เปลี่ยนรูป ​ใน​ระบบ​วางแผน​อัตโนมัติ​สมัยใหม่

Five Bets About the Shape of the Space

​ห้า​เดิมพัน​ว่าด้วย​รูปร่าง​ของ​พื้นที่

Step back from any single algorithm in this chapter and a shared logic becomes visible: every search strategy is, underneath its details, a bet about what kind of space it is searching. Naming the bets explicitly turns them from a grab-bag of tricks into a genuine toolkit, one you can hold up against a new problem and ask which bet fits.

​กลยุทธ์​การค้นหา​ทุก​แบบ ​ใต้​รายละเอียด​ของ​มัน ​คือ​การเดิมพัน​ว่า​พื้นที่​ที่​มัน​กำลัง​ค้นหา​เป็นพื้น​ที่​ชนิด​ไหน ​ถอย​ออกมา​จาก​อัลกอริทึม​ตัว​ใด​ตัว​หนึ่ง​ใน​บท​นี้​แล้ว​ตรรกะ​ร่วม​ข้อ​นี้​จะ​ปรากฏ ​เรียกชื่อ​เดิมพัน​เหล่านี้​ให้​ชัด ​แล้ว​ถุง​ลูกเล่น​คละ​กัน​จะ​กลายเป็น​ชุด​เครื่องมือ​จริง ​ชุด​ที่​ยกขึ้น​เทียบ​กับ​ปัญหา​ใหม่​แล้ว​ถาม​ได้​ว่า​เดิมพัน​ไหน​เข้ากัน

Greedy algorithms bet that making the locally best choice at every step, without ever reconsidering it, will add up to a globally good result. This is a dangerous bet — it is easy to construct problems where it fails outright — but when a problem's structure guarantees the bet pays off (a property mathematicians call the matroid or exchange condition in the cleanest cases), greedy strategies are unbeatable for their simplicity and speed. Dijkstra's algorithm is, in this light, a greedy algorithm that happens to be provably safe: always finalize whichever unvisited node is currently cheapest, and never look back.

​อัลกอริทึม​แบบ​โลภ (greedy) ​เดิมพัน​ว่า​เลือก​สิ่ง​ที่​ดี​ที่สุด​เฉพาะถิ่น​ใน​ทุก​ก้าว ​ไม่​ย้อนกลับ​มา​ทบทวน​เลย ​แล้ว​ผลรวม​จะ​ดี​ใน​ระดับ​ทั้งหมด ​เดิมพัน​นี้​อันตราย — ​สร้าง​ปัญหา​ที่​มัน​ล้มเหลว​โดยสิ้นเชิง​ได้​ง่ายๆ — ​แต่​เมื่อ​โครงสร้าง​ของ​ปัญหา​รับประกัน​ว่า​เดิมพัน​ได้ผล (​คุณสมบัติ​ที่​นัก​คณิตศาสตร์​เรียก​ว่า​เงื่อนไข​มา​ทรอย​ด์​หรือ​เงื่อนไข​แลกเปลี่ยน​ในกรณีที่​สะอาด​ที่สุด) ​กลยุทธ์ greedy ​ไม่​มี​อะไร​สู้​ได้​ในแง่​ความเรียบง่าย​และ​ความเร็ว ​มอง​แบบนี้ ​อัลกอริทึม​ของ Dijkstra ​คือ​อัลกอริทึม greedy ​ที่​บังเอิญ​พิสูจน์​ได้​ว่า​ปลอดภัย: ​ปิดตาย​โหนด​ที่​ยัง​ไม่​ได้​ไป​ซึ่ง​ถูกที่​สุด​ตอนนี้​เสมอ ​และ​ไม่​หันกลับ​ไป​มอง​อีก

Divide-and-conquer bets that a hard problem can be split into smaller, structurally identical copies of itself, solved independently, and stitched back together. It is the strategy behind fast sorting and multiplication algorithms, and its bet is about decomposability: does solving the pieces really tell you how to solve the whole?

​แบ่ง​แล้ว​พิชิต (divide and conquer) ​เดิมพัน​ว่า​ปัญหา​ยาก​ข้อ​หนึ่ง​แยก​ออก​เป็น​สำเนา​ของ​ตัว​มัน​เอง​ที่​เล็ก​ลง​และ​มี​โครงสร้าง​เหมือนกัน​ได้ ​แก้​แยกกัน ​แล้ว​เย็บ​กลับ​เข้าด้วยกัน ​มัน​คือ​กลยุทธ์​เบื้องหลัง​อัลกอริทึม​เรียงลำดับ​และ​คูณ​เลขที่​เร็ว ​เดิมพัน​ของ​มัน​คือ ​การแยกส่วน​ได้: ​แก้​ชิ้นส่วน​แล้ว​รู้​จริง​หรือว่า​จะ​แก้​ทั้ง​ก้อน​อย่างไร

Dynamic programming, which chapter 04 introduced through Bellman's principle of optimality, bets that a problem's sub-problems overlap — that the same smaller question will recur many times inside a larger search — and that storing each answer the first time it is computed will save enormous repeated effort later. Where divide-and-conquer's pieces are independent, dynamic programming's pieces share work, and the technique exists precisely to avoid redoing that shared work, the way Shannon's mouse never re-explored a corridor it had already mapped.

dynamic programming ​ที่​บท​ที่ 04 ​แนะนำ​ผ่าน​หลัก​ความเหมาะ​ที่สุด​ของ Bellman ​เดิมพัน​ว่า​ปัญหา​ย่อย​ของ​ปัญหา​หนึ่ง ​ซ้อนทับ​กัน — ​คำถาม​เล็ก​ข้อ​เดิม​จะ​วน​กลับมา​หลายครั้ง​ภายใน​การค้นหา​ที่​ใหญ่​กว่า — ​และ​เก็บ​คำตอบ​แต่ละ​ข้อ​ไว้​ตั้งแต่​ครั้งแรก​ที่​คำนวณ​จะ​ประหยัด​แรง​ที่​ต้อง​ทำซ้ำ​ใน​ภายหลัง ​ชิ้นส่วน​ของ​แบ่ง​แล้ว​พิชิต​เป็นอิสระ​ต่อกัน ​ชิ้นส่วน​ของ dynamic programming ​แบ่งงาน​กัน​ใช้ ​เทคนิค​นี้​มี​อยู่​เพื่อ​เลี่ยง​การทำงาน​ร่วม​นั้น​ซ้ำ​พอดี ​เหมือน​ที่​หนู​ของ Shannon ​ไม่​เคย​กลับ​ไป​สำรวจ​ช่องทาง​ที่​มัน​ทำ​แผนที่​ไว้​แล้ว

Backtracking bets that a space can be searched depth-first, provided the search can recognize a dead end early and retreat before wasting further effort down it — the disciplined version of what Theseus did by trial, bump, and correction.

backtracking ​เดิมพัน​ว่า​พื้นที่​หนึ่ง​ค้นหา​แบบ DFS ​ได้ ​ตราบใดที่​การค้นหา​รู้ตัว​เร็ว​ว่า​เจอ​ทางตัน ​แล้ว​ถอยกลับ​ก่อน​ผลาญ​แรง​ลง​ไป​ใน​นั้น​อีก ​มัน​คือ​เวอร์ชัน​มีวินัย​ของ​สิ่ง​ที่ Theseus ​ทำ​ด้วย​การลอง ​ชน ​และ​แก้

Branch-and-bound, formalized in 1960 by Ailsa Land and Alison Doig for problems requiring whole-number rather than fractional solutions, bets that you can compute a cheap bound on how good any solution branching from a given partial choice could possibly be — and use that bound to prune away entire branches of the search tree without ever visiting them, the instant the bound proves they cannot beat a solution you already have in hand (Wikipedia, "Branch and bound"). It is A*'s admissible heuristic, generalized from finding paths on a map to finding optimal points in a much wider variety of combinatorial spaces.

​แตก​กิ่ง​แล้ว​ตี​กรอบ (branch and bound) ​เดิมพัน​ว่า​เรา​คำนวณ ​ขอบเขต ​ราคา​ถูก​ได้​ว่า​คำตอบ​ใด​ก็ตาม​ที่​แตก​กิ่ง​ออกจาก​ตัวเลือก​บางส่วน​อัน​หนึ่ง​จะ​ดี​ได้มาก​ที่สุด​แค่​ไหน ​ทันทีที่​ขอบเขต​พิสูจน์​ว่า​กิ่ง​นั้น​ชนะ​คำตอบ​ที่​ถือ​อยู่​ใน​มือ​แล้ว​ไม่​ได้ ​ก็​ตัด​กิ่ง​ทั้ง​กิ่ง​ของ​ต้นไม้​การค้นหา​ทิ้ง​โดย​ไม่ต้อง​เข้าไป​ดู​เลย Ailsa Land ​กับ Alison Doig ​ทำให้​มัน​เป็น​รูป​นัย​ใน​ปี 1960 ​สำหรับ​ปัญหา​ที่​ต้องการ​คำตอบ​เป็น​จำนวนเต็ม​แทนที่จะ​เป็น​เศษส่วน (Wikipedia, "Branch and bound") ​มัน​คือ admissible heuristic ​ของ A\* ​ที่​ถูก​ทำให้​ทั่วไป​ขึ้น ​จาก​การหา​เส้นทาง​บน​แผนที่ ​ไป​สู่​การหา​จุด​เหมาะ​ที่สุด​ใน​พื้นที่​เชิง​การจัด​หมู่​ที่​หลากหลาย​กว่า​มาก

Five bets, five different guesses about the hidden shape of a problem space. None of them is "the" right way to search; each is the right way when its bet about the space happens to be true. Reading a new problem well enough to know which bet applies is, itself, most of the skill this book is trying to name.

​ห้า​เดิมพัน ​คือ​ห้า​การเดา​ที่​ต่างกัน​เกี่ยวกับ​รูปร่าง​ที่ซ่อน​อยู่​ของ​พื้นที่​ปัญหา ​ไม่​มี​อัน​ไหน​เป็น​วิธี​ค้นหา​ที่​ถูก "​อันนั้น"; ​แต่ละ​อัน​ถูก ​เมื่อ​เดิมพัน​ของ​มัน​เกี่ยวกับ​พื้นที่​บังเอิญ​เป็นจริง ​อ่าน​ปัญหา​ใหม่​ได้ดี​พอ​จะ​รู้​ว่า​เดิมพัน​ไหน​ใช้ได้ — ​นั่น​คือ​ทักษะ​เกือบ​ทั้งหมด​ที่​หนังสือ​เล่ม​นี้​พยายาม​เรียกชื่อ

An Algorithm Is a Heuristic That Earned a Proof

​อัลกอริทึม​คือ heuristic ​ที่​หาบท​พิสูจน์​มา​ได้

There is a temptation, looking backward from a world of route planners and chess engines, to treat "algorithm" and "heuristic" as opposites — one rigorous and guaranteed, the other a rough guess that might fail. The history in this chapter argues for a different picture. Dijkstra's algorithm began as an informal insight about which city to visit next; what made it an algorithm, rather than a hunch, was that Dijkstra could prove the insight always worked. A*'s heuristic estimate is explicitly, by name, a guess — yet paired with the single provable property of admissibility, that guess becomes part of an algorithm with an ironclad optimality guarantee. Newell and Simon's "rules of thumb" for pruning theorem-proving searches were heuristics in the older, looser sense: useful, unproven, sometimes wrong. The field's entire maturation across this chapter is the slow conversion of hunches into guarantees — not by abandoning intuition, but by discovering exactly which intuitions can be proven never to betray you.

"​อัลกอริทึม" ​กับ "heuristic" ​ไม่​ใช่​ขั้ว​ตรงข้าม ​มอง​ย้อน​จาก​โลก​ที่​มี​ตัว​วางแผน​เส้นทาง​และ​เครื่องยนต์​หมากรุก ​มี​สิ่งล่อใจ​ให้​ถือว่า​อย่างหนึ่ง​เข้มงวด​และ​รับประกัน​ได้ ​อีก​อย่าง​เป็นการ​เดา​หยาบๆ ​ที่​อาจ​พลาด ​ประวัติศาสตร์​ใน​บท​นี้​เถียง​ให้​ภาพ​อีก​แบบ ​อัลกอริทึม​ของ Dijkstra ​เริ่ม​จาก insight ​แบบ​ไม่​เป็นทางการ​ว่า​ควร​ไป​เมือง​ไหน​ต่อ; ​สิ่ง​ที่​ทำให้​มัน​เป็น​อัลกอริทึม​แทนที่จะ​เป็น​ลางสังหรณ์ ​คือ Dijkstra ​พิสูจน์​ได้​ว่า insight ​นั้น​ใช้ได้​เสมอ ​ค่า​ประมาณ​แบบ heuristic ​ของ A\* ​เป็นการ​เดา​อย่าง​เปิดเผย​ตั้งแต่​ชื่อ ​แต่​พอ​จับคู่​กับ​คุณสมบัติ​ที่​พิสูจน์​ได้​ข้อ​เดียว​คือ admissibility ​การเดา​นั้น​ก็​กลายเป็น​ส่วนหนึ่ง​ของ​อัลกอริทึม​ที่​รับประกัน​คำตอบ​เหมาะ​ที่สุด​อย่าง​หักล้าง​ไม่​ได้ ​กฎ​สามัญสำนึก​ของ Newell ​กับ Simon ​ที่​ใช้​ตัด​กิ่ง​ใน​การค้นหา​บทพิสูจน์​ทฤษฎีบท ​เป็น heuristic ​ใน​ความหมาย​เก่า​ที่​หลวม​กว่า: ​มีประโยชน์ ​ยัง​ไม่​พิสูจน์ ​และ​บางที​ก็​ผิด ​สาขา​นี้​เติบโต​ตลอดทั้ง​บท​ด้วย​การค่อยๆ ​แปลง​ลางสังหรณ์​ให้​เป็นการ​รับประกัน ​ไม่​ใช่​ด้วย​การทิ้ง​สัญชาตญาณ ​แต่​ด้วย​การค้น​ให้​เจอ​ว่า​สัญชาตญาณ​ข้อ​ไหน​กัน​แน่​ที่​พิสูจน์​ได้​ว่า​จะ​ไม่​มี​วัน​ทรยศ

This is also where the algorithmic tradition begins to separate from the operations-research tradition of chapter 04. Linear programming and dynamic programming solve well-defined numerical optimization problems. The algorithms in this chapter solve search problems over discrete, often combinatorial spaces — mazes, graphs, logical proofs, game positions — and their central discovery is that the structure of the space itself (its distances, its overlapping sub-problems, its decomposability) determines which search strategy can be proven correct and fast. That discovery sets up the next and darker discovery, waiting in chapter 06: some spaces have no exploitable structure of this kind at all, and no amount of cleverness can manufacture one where none exists.

​ตรงนี้​เอง​ที่​ธรรมเนียม​เชิง​อัลกอริทึม​เริ่ม​แยก​ออกจาก​ธรรมเนียม​วิจัย​ดำเนินงาน (operational research, OR) ​ของ​บท​ที่ 04 ​กำหนดการ​เชิงเส้น (linear programming) ​และ dynamic programming ​แก้ปัญหา​การหา​ค่า​เหมาะ​ที่สุด​เชิงตัวเลข​ที่​นิยาม​ไว้​ชัดเจน ​อัลกอริทึม​ใน​บท​นี้​แก้ปัญหา*​การค้นหา*​บน​พื้นที่​ไม่​ต่อเนื่อง​ซึ่ง​มัก​เป็น​เชิง​การจัด​หมู่ — ​เขาวงกต ​กราฟ ​บทพิสูจน์​ทาง​ตรรกะ ​ตำแหน่ง​บน​กระดาน ​การค้นพบ​ใจกลาง​ของ​พวก​มัน​คือ ​โครงสร้าง​ของ​พื้นที่​เอง​ต่างหาก (​ระยะทาง​ใน​นั้น ​ปัญหา​ย่อย​ที่​ซ้อนทับ​กัน ​ความแยกส่วน​ได้​ของ​มัน) ​ที่​กำหนด​ว่า​กลยุทธ์​การค้นหา​แบบ​ไหนจะ​พิสูจน์​ได้​ว่า​ถูก​และ​เร็ว ​การค้นพบ​นั้น​ปู​ทาง​ไป​สู่​การค้นพบ​ถัดไป​ที่​มืด​กว่า ​มัน​รอ​อยู่​ใน​บท​ที่ 06: ​พื้นที่​บาง​แบบ​ไม่​มี​โครงสร้าง​ชนิด​นี้​ให้​ใช้ประโยชน์​เลย ​และ​ไม่​ว่า​จะ​ฉลาด​แค่​ไหน​ก็​ผลิต​มัน​ขึ้น​มา​ใน​ที่​ที่​ไม่​มี​ไม่​ได้

The Move

​ท่า​ประจำ​บท

Move 05 — Order the search: exploit structure so good paths come first.

Move 05 — ​จัดลำดับ​การค้นหา — ​ใช้​โครงสร้าง​ดัน​เส้นทาง​ที่​ดีขึ้น​มา​ก่อน

  • Name which of the five bets fits your space before searching it. Overlapping sub-problems call for dynamic programming; decomposable ones call for divide-and-conquer; a provably safe local choice calls for greedy; anything else usually calls for backtracking or branch-and-bound. Guessing the wrong bet wastes the search before it starts.
  • When you must guess, guess optimistically but never past the truth. A* shows that an estimate need not be accurate to be useful — it only needs to be admissible. An honest lower bound on remaining effort is worth more than an unreliable "best guess."
  • Remember what you have already searched. Shannon's mouse and Bellman's functional equations share one lesson: the first pass through a space is allowed to be expensive, provided nothing forces you to pay for the same sub-problem twice.
  • Distinguish a real guarantee from a plausible heuristic, and say out loud which one you're relying on. The Logic Theorist's "rules of thumb" and Dijkstra's proven-optimal frontier are both search strategies — only one of them promises it cannot be wrong.
  • ​เรียกชื่อ​ให้ได้​ว่า​เดิมพัน​ข้อ​ไหน​ใน​ห้า​ข้อ​เข้ากับ​พื้นที่​ของ​คุณ ​ก่อน​จะ​เริ่ม​ค้นหา​มัน ​ปัญหา​ย่อย​ที่​ซ้อนทับ​กัน​เรียกหา dynamic programming; ​ปัญหา​ที่​แยกส่วน​ได้​เรียกหา​แบ่ง​แล้ว​พิชิต; ​ตัวเลือก​เฉพาะถิ่น​ที่​พิสูจน์​ได้​ว่า​ปลอดภัย​เรียกหา greedy; ​นอกนั้น​มัก​เรียกหา backtracking ​หรือ branch and bound ​การเดา​เดิมพัน​ผิด​คือ​การผลาญ​การค้นหา​ทิ้ง​ตั้งแต่​ยัง​ไม่​เริ่ม
  • ​เมื่อ​ต้อง​เดา ​จง​เดา​ในแง่​ดี ​แต่​ห้าม​เลย​ความจริง A\* ​แสดงให้เห็น​ว่า​ค่า​ประมาณ​ไม่​จำเป็นต้อง​แม่น​ถึง​จะ​มีประโยชน์ — ​มัน​แค่​ต้อง admissible ​ขอบ​ล่าง​ที่​ซื่อสัตย์​ของ​แรง​ที่​เหลือ ​มีค่า​มากกว่า "​การเดา​ที่​ดี​ที่สุด" ​ที่​เชื่อถือ​ไม่​ได้
  • ​จำไว้​ว่า​ค้น​อะไร​ไป​แล้ว​บ้าง ​หนู​ของ Shannon ​กับ​สมการ​เชิง​ฟังก์ชัน​ของ Bellman ​มี​บทเรียน​ร่วมกัน​ข้อ​หนึ่ง: ​การเดินผ่าน​พื้นที่​รอบ​แรก​แพง​ได้ ​ตราบใดที่​ไม่​มี​อะไร​บังคับ​ให้​จ่าย​ค่า​ปัญหา​ย่อย​ข้อ​เดียวกัน​สอง​ครั้ง
  • ​แยก​การรับประกัน​ของจริง​ออกจาก heuristic ​ที่​ฟัง​ดู​มีเหตุผล ​แล้ว​พูด​ออกมา​ดังๆ ​ว่า​กำลัง​พึ่ง​อัน​ไหน​อยู่ "​กฎ​สามัญสำนึก" ​ของ Logic Theorist ​กับ​แนวหน้า​ที่​พิสูจน์​ว่า​เหมาะ​ที่สุด​ของ Dijkstra ​ต่าง​ก็​เป็น​กลยุทธ์​การค้นหา — ​แต่​มี​แค่​อัน​เดียว​ที่​สัญญา​ว่า​มัน​ผิด​ไม่​ได้

Next — Chapter 06 · The Wall: not every space bends to a clever order of search. This chapter's algorithms all found structure to exploit — the next chapter meets problems with no exploitable structure at all, and asks what a solver does when the space itself refuses to get shorter.

​ต่อไป — ​บท​ที่ 06 · ​กำแพง: ​ไม่​ใช่​ทุก​พื้นที่​ที่จะ​ยอม​โค้ง​ให้​ลำดับ​การค้นหา​อัน​ชาญฉลาด ​อัลกอริทึม​ทั้งหมด​ใน​บท​นี้​เจอ​โครงสร้าง​ให้​ใช้ประโยชน์ — ​บท​หน้า​จะ​พบ​ปัญหา​ที่​ไม่​มี​โครงสร้าง​ให้​ใช้ประโยชน์​เลย ​และ​ถาม​ว่า​นัก​แก้ปัญหา​ทำ​อย่างไร​เมื่อ​พื้นที่​เอง​ปฏิเสธ​ที่จะ​สั้น​ลง

บทถัดไป · 7 / 1206 · The Wall
Size
Page
Font

The Shortest Path — A History of the Art and Science of Problem-Solving

❦
100 · The Knot and the Path00 · ปมและเส้นทาง201 · The First Methods01 · วิธีชุดแรก302 · The Reframe02 · การเปลี่ยนกรอบ403 · The Heuristic Age03 · ยุค heuristic504 · War and the Science of Search04 · สงครามกับศาสตร์แห่งการค้นหา605 · The Algorithmic Path05 · เส้นทางแบบอัลกอริทึม706 · The Wall06 · กำแพง807 · Gallery I: The Single Move07 · หอเรื่องเล่า I: ท่าเดียวจบ908 · Gallery II: The Modern Solves08 · หอเรื่องเล่า II: การแก้ครั้งใหญ่ยุคใหม่1009 · The Aesthetics of Solution09 · สุนทรียะของคำตอบ1110 · The Future Solver10 · นักแก้ปัญหาแห่งอนาคต1299 · The Leverage Route99 · เส้นทางคานงัด