30 likes | 184 Views
*23. *23. *14. *14. 11. 11. 12. 12. 9. 9. *09. *09. 7. 7. 6. 6. *06. *06. 14. 14. 9. 9. 11. 11. 12. 12. 4. 4. 12. 12. 9. 9. *13. *13. 13. 13. *11. *11. 5. 5. 7. 7. *05. *05. 22. 22. 18. 18. 12. 12. 44. 14. 14. 40. 40. *03. *03. *02. *02. 8.
E N D
*23 *23 *14 *14 11 11 12 12 9 9 *09 *09 7 7 6 6 *06 *06 14 14 9 9 11 11 12 12 4 4 12 12 9 9 *13 *13 13 13 *11 *11 5 5 7 7 *05 *05 22 22 18 18 12 12 44 14 14 40 40 *03 *03 *02 *02 8 8 7 7 11 11 9 9 *01 *01 *26 8 8 26 26 6 6 35 *07 *07 16 27 27 *17 *17 8 8 16 27 27 *10 *10 13 13 *19 *19 33 10 10 13 13 25 29 29 33 *12 *12 *21 *21 31 31 14 14 9 9 21 21 33 28 28 33 14 14 20 20 *15 *15 23 23 14 14 14 14 25 25 *08 *08 29 29 31 31 27 27 17 17 *16 *16 17 17 *24 *24 *04 *04 22 26 26 25 21 21 43 11 11 25 25 34 *22 *22 *25 45 15 *20 *20 19 19 24 24 24 11 11 *18 *18 US Capitals 1821 1837 ノード数 接続経路数 巡回経路総数 最小巡回距離 : 24 : 122 : 34,380 : 313 : 26 : 136 : 359,640 : 340 ノード数 接続経路数 巡回経路総数 最小巡回距離
; *01 Dover : Delaware [ December 7, 1787 ] (REGISTER '*01 '*01->*02 '*02) (DEFINE 'T.*01->*02 9) (REGISTER '*01 '*01->*03 '*03) (DEFINE 'T.*01->*03 7) (REGISTER '*01 '*01->*07 '*07) (DEFINE 'T.*01->*07 6) ; *02 Harrisburg : Pennsylvania [ December 12, 1787 ] (REGISTER '*02 '*02->*01 '*01) (DEFINE 'T.*02->*01 9) (REGISTER '*02 '*02->*03 '*03) (DEFINE 'T.*02->*03 8) (REGISTER '*02 '*02->*07 '*07) (DEFINE 'T.*02->*07 8) (REGISTER '*02 '*02->*11 '*11) (DEFINE 'T.*02->*11 18) (REGISTER '*02 '*02->*17 '*17) (DEFINE 'T.*02->*17 26) ; *03 Trenton : New Jersey [ December 18, 1787 ] (REGISTER '*03 '*03->*01 '*01) (DEFINE 'T.*03->*01 7) (REGISTER '*03 '*03->*02 '*02) (DEFINE 'T.*03->*02 8) (REGISTER '*03 '*03->*05 '*05) (DEFINE 'T.*03->*05 12) (REGISTER '*03 '*03->*07 '*07) (DEFINE 'T.*03->*07 11) (REGISTER '*03 '*03->*11 '*11) (DEFINE 'T.*03->*11 14) (REGISTER '*03 '*03->*13 '*13) (DEFINE 'T.*03->*13 22) ; *04 Atlanta : Georgia [ January 2, 1788 ] (REGISTER '*04 '*04->*08 '*08) (DEFINE 'T.*04->*08 17) (REGISTER '*04 '*04->*15 '*15) (DEFINE 'T.*04->*15 25) (REGISTER '*04 '*04->*16 '*16) (DEFINE 'T.*04->*16 17) (REGISTER '*04 '*04->*22 '*22) (DEFINE 'T.*04->*22 11) ; *05 Hartford : Connecticut [ January 9, 1788 ] (REGISTER '*05 '*05->*03 '*03) (DEFINE 'T.*05->*03 12) (REGISTER '*05 '*05->*06 '*06) (DEFINE 'T.*05->*06 9) (REGISTER '*05 '*05->*09 '*09) (DEFINE 'T.*05->*09 11) (REGISTER '*05 '*05->*11 '*11) (DEFINE 'T.*05->*11 7) (REGISTER '*05 '*05->*13 '*13) (DEFINE 'T.*05->*13 5) (REGISTER '*05 '*05->*14 '*14) (DEFINE 'T.*05->*14 14) ; *06 Boston : Massachusetts [ February 6, 1788 ] (REGISTER '*06 '*06->*05 '*05) (DEFINE 'T.*06->*05 9) (REGISTER '*06 '*06->*09 '*09) (DEFINE 'T.*06->*09 6) (REGISTER '*06 '*06->*11 '*11) (DEFINE 'T.*06->*11 13) (REGISTER '*06 '*06->*13 '*13) (DEFINE 'T.*06->*13 4) (REGISTER '*06 '*06->*23 '*23) (DEFINE 'T.*06->*23 12) ; *07 Annapolis : Maryland [ April 28, 1788 ] (REGISTER '*07 '*07->*01 '*01) (DEFINE 'T.*07->*01 6) (REGISTER '*07 '*07->*02 '*02) (DEFINE 'T.*07->*02 8) (REGISTER '*07 '*07->*03 '*03) (DEFINE 'T.*07->*03 11) (REGISTER '*07 '*07->*10 '*10) (DEFINE 'T.*07->*10 8) (REGISTER '*07 '*07->*17 '*17) (DEFINE 'T.*07->*17 27) ; *08 Columbia : South Carolina [ May 23, 1788 ] (REGISTER '*08 '*08->*04 '*04) (DEFINE 'T.*08->*04 17) (REGISTER '*08 '*08->*12 '*12) (DEFINE 'T.*08->*12 14) (REGISTER '*08 '*08->*15 '*15) (DEFINE 'T.*08->*15 28) (REGISTER '*08 '*08->*16 '*16) (DEFINE 'T.*08->*16 29) (REGISTER '*08 '*08->*17 '*17) (DEFINE 'T.*08->*17 33) (REGISTER '*08 '*08->*22 '*22) (DEFINE 'T.*08->*22 26) ; *09 Concord : New Hampshire [ June 21, 1788 ] (REGISTER '*09 '*09->*05 '*05) (DEFINE 'T.*09->*05 11) (REGISTER '*09 '*09->*06 '*06) (DEFINE 'T.*09->*06 6) (REGISTER '*09 '*09->*11 '*11) (DEFINE 'T.*09->*11 12) (REGISTER '*09 '*09->*13 '*13) (DEFINE 'T.*09->*13 9) (REGISTER '*09 '*09->*14 '*14) (DEFINE 'T.*09->*14 7) (REGISTER '*09 '*09->*23 '*23) (DEFINE 'T.*09->*23 9) ; *10 Richmond : Virginia [ June 25, 1788 ] (REGISTER '*10 '*10->*07 '*07) (DEFINE 'T.*10->*07 8) (REGISTER '*10 '*10->*12 '*12) (DEFINE 'T.*10->*12 10) (REGISTER '*10 '*10->*15 '*15) (DEFINE 'T.*10->*15 33) (REGISTER '*10 '*10->*17 '*17) (DEFINE 'T.*10->*17 27) ; *11 Albany : New York [ July 26, 1788 ] (REGISTER '*11 '*11->*02 '*02) (DEFINE 'T.*11->*02 18) (REGISTER '*11 '*11->*03 '*03) (DEFINE 'T.*11->*03 14) (REGISTER '*11 '*11->*05 '*05) (DEFINE 'T.*11->*05 7) (REGISTER '*11 '*11->*06 '*06) (DEFINE 'T.*11->*06 13) (REGISTER '*11 '*11->*09 '*09) (DEFINE 'T.*11->*09 12) (REGISTER '*11 '*11->*14 '*14) (DEFINE 'T.*11->*14 12) (REGISTER '*11 '*11->*17 '*17) (DEFINE 'T.*11->*17 40) ; *12 Raleigh : North Carolina [ November 21, 1789 ] (REGISTER '*12 '*12->*08 '*08) (DEFINE 'T.*12->*08 14) (REGISTER '*12 '*12->*10 '*10) (DEFINE 'T.*12->*10 10) (REGISTER '*12 '*12->*15 '*15) (DEFINE 'T.*12->*15 31) (REGISTER '*12 '*12->*17 '*17) (DEFINE 'T.*12->*17 29) ; *13 Providence : Rhode Island [ May 29, 1790 ] (REGISTER '*13 '*13->*03 '*03) (DEFINE 'T.*13->*03 22) (REGISTER '*13 '*13->*05 '*05) (DEFINE 'T.*13->*05 5) (REGISTER '*13 '*13->*06 '*06) (DEFINE 'T.*13->*06 4) (REGISTER '*13 '*13->*09 '*09) (DEFINE 'T.*13->*09 9) ; *14 Montpelier : Vermont [ March 4, 1791 ] (REGISTER '*14 '*14->*05 '*05) (DEFINE 'T.*14->*05 14) (REGISTER '*14 '*14->*09 '*09) (DEFINE 'T.*14->*09 7) (REGISTER '*14 '*14->*11 '*11) (DEFINE 'T.*14->*11 12) (REGISTER '*14 '*14->*23 '*23) (DEFINE 'T.*14->*23 11) ; *15 Frankfort : Kentucky [ June 1, 1792 ] (REGISTER '*15 '*15->*04 '*04) (DEFINE 'T.*15->*04 25) (REGISTER '*15 '*15->*08 '*08) (DEFINE 'T.*15->*08 28) (REGISTER '*15 '*15->*10 '*10) (DEFINE 'T.*15->*10 33) (REGISTER '*15 '*15->*12 '*12) (DEFINE 'T.*15->*12 31) (REGISTER '*15 '*15->*16 '*16) (DEFINE 'T.*15->*16 14) (REGISTER '*15 '*15->*17 '*17) (DEFINE 'T.*15->*17 13) (REGISTER '*15 '*15->*19 '*19) (DEFINE 'T.*15->*19 9) (REGISTER '*15 '*15->*21 '*21) (DEFINE 'T.*15->*21 21) ; *16 Nashville : Tennessee [ June 1, 1796 ] (REGISTER '*16 '*16->*04 '*04) (DEFINE 'T.*16->*04 17) (REGISTER '*16 '*16->*08 '*08) (DEFINE 'T.*16->*08 29) (REGISTER '*16 '*16->*15 '*15) (DEFINE 'T.*16->*15 14) (REGISTER '*16 '*16->*19 '*19) (DEFINE 'T.*16->*19 20) (REGISTER '*16 '*16->*20 '*20) (DEFINE 'T.*16->*20 25) (REGISTER '*16 '*16->*21 '*21) (DEFINE 'T.*16->*21 23) (REGISTER '*16 '*16->*22 '*22) (DEFINE 'T.*16->*22 21) (REGISTER '*16 '*16->*24 '*24) (DEFINE 'T.*16->*24 27) 1821のデータ定義 ; *17 Columbus : Ohio [ March 1, 1803 ] (REGISTER '*17 '*17->*02 '*02) (DEFINE 'T.*17->*02 26) (REGISTER '*17 '*17->*07 '*07) (DEFINE 'T.*17->*07 27) (REGISTER '*17 '*17->*08 '*08) (DEFINE 'T.*17->*08 33) (REGISTER '*17 '*17->*10 '*10) (DEFINE 'T.*17->*10 27) (REGISTER '*17 '*17->*11 '*11) (DEFINE 'T.*17->*11 40) (REGISTER '*17 '*17->*12 '*12) (DEFINE 'T.*17->*12 29) (REGISTER '*17 '*17->*15 '*15) (DEFINE 'T.*17->*15 13) (REGISTER '*17 '*17->*19 '*19) (DEFINE 'T.*17->*19 13) ; *18 Baton Rouge : Louisiana [ April 30, 1812 ] (REGISTER '*18 '*18->*20 '*20) (DEFINE 'T.*18->*20 11) (REGISTER '*18 '*18->*22 '*22) (DEFINE 'T.*18->*22 24) (REGISTER '*18 '*18->*24 '*24) (DEFINE 'T.*18->*24 45) ; *19 Indianapolis : Indiana [ December 11, 1816 ] (REGISTER '*19 '*19->*15 '*15) (DEFINE 'T.*19->*15 9) (REGISTER '*19 '*19->*16 '*16) (DEFINE 'T.*19->*16 20) (REGISTER '*19 '*19->*17 '*17) (DEFINE 'T.*19->*17 13) (REGISTER '*19 '*19->*21 '*21) (DEFINE 'T.*19->*21 14) ; *20 Jackson : Mississippi [ December 10, 1817 ] (REGISTER '*20 '*20->*16 '*16) (DEFINE 'T.*20->*16 25) (REGISTER '*20 '*20->*18 '*18) (DEFINE 'T.*20->*18 11) (REGISTER '*20 '*20->*22 '*22) (DEFINE 'T.*20->*22 19) (REGISTER '*20 '*20->*24 '*24) (DEFINE 'T.*20->*24 34) ; *21 Springfield : Illinois [ December 3, 1818 ] (REGISTER '*21 '*21->*15 '*15) (DEFINE 'T.*21->*15 21) (REGISTER '*21 '*21->*16 '*16) (DEFINE 'T.*21->*16 23) (REGISTER '*21 '*21->*19 '*19) (DEFINE 'T.*21->*19 14) (REGISTER '*21 '*21->*24 '*24) (DEFINE 'T.*21->*24 14) ; *22 Montgomery : Alabama [ December 14, 1819 ] (REGISTER '*22 '*22->*04 '*04) (DEFINE 'T.*22->*04 11) (REGISTER '*22 '*22->*08 '*08) (DEFINE 'T.*22->*08 26) (REGISTER '*22 '*22->*16 '*16) (DEFINE 'T.*22->*16 21) (REGISTER '*22 '*22->*18 '*18) (DEFINE 'T.*22->*18 24) (REGISTER '*22 '*22->*20 '*20) (DEFINE 'T.*22->*20 19) (REGISTER '*22 '*22->*24 '*24) (DEFINE 'T.*22->*24 43) ; *23 Augusta : Maine [ March 15, 1820 ] (REGISTER '*23 '*23->*06 '*06) (DEFINE 'T.*23->*06 12) (REGISTER '*23 '*23->*09 '*09) (DEFINE 'T.*23->*09 9) (REGISTER '*23 '*23->*14 '*14) (DEFINE 'T.*23->*14 11) ; *24 Jefferson : Missouri [ August 10, 1821 ] (REGISTER '*24 '*24->*16 '*16) (DEFINE 'T.*24->*16 27) (REGISTER '*24 '*24->*18 '*18) (DEFINE 'T.*24->*18 45) (REGISTER '*24 '*24->*20 '*20) (DEFINE 'T.*24->*20 34) (REGISTER '*24 '*24->*21 '*21) (DEFINE 'T.*24->*21 14) (REGISTER '*24 '*24->*22 '*22) (DEFINE 'T.*24->*22 43)
全巡回経路と所要時間を求めるプログラム ; ===== SIMPLE TSP ======================================================================= (declaim (special *NUMBER-OF-NODES* *SHORTEST-TIME* *SHORTEST-ROUTE* *ROUTE-COUNT*)) (defun simple-tsp () ; ; ; KENiB(6): (HOW-DEFINED 'A) --> ((A->C C) (A->B B)) ; ; ; +-- B +-- D +-- F ; | | | ; A --+-- C --+-- E --+-- G --+-- D ; ; ; ( ((A->C C)) ((A->B B))) ; ; ( ((C->E E)(A->C C)) ((C->D D)(A->C C)) ((A->B B))) ; ; (((E->G G)(C->E E)(A->C C)) ((E->F F)(C->E E)(A->C C)) ((C->D D)(A->C C)) ((A->B B))) ; ; (setf *NUMBER-OF-NODES* (length (objects))) (setf *SHORTEST-TIME* 99999999999999999999) (setf *SHORTEST-ROUTE* nil) (setf *ROUTE-COUNT* 0) ; (let ((the-point (car (objects)))) (simple-tsp-search the-point (mapcar #'list (how-defined the-point))))) ; ----- SubRoutines for TSP -------------------------------------------------------------- (defun arc-time (p) (eval (intern (concatenate 'string "T." (symbol-name p))))) ; ----- SIMPLE TSP SEARCH ---------------------------------------------------------------- (defun simple-tsp-search (target queue) (labels ((total-time (p) (let ((RESULT nil)) (apply #'+ (dolist (ELEMENT p RESULT) (setf RESULT (cons (arc-time (car ELEMENT)) RESULT))))))) (cond ;-----------------------------------------------------------< END OF THE PROCESS >----- ((null queue) (print *SHORTEST-TIME*) (mapcar #'(lambda (p) (print (reverse p))) *SHORTEST-ROUTE*) (eof)) ; ;------------------------------------------------------------< GOT TO THE TARGET >----- ((eq (cadaar queue) target) (when (eq (length (car queue)) *NUMBER-OF-NODES*) (let ((TIME (total-time (car queue)))) (when (= *SHORTEST-TIME* TIME) (setf *SHORTEST-ROUTE* (cons (car queue) *SHORTEST-ROUTE*))) (when (> *SHORTEST-TIME* TIME) (setf *SHORTEST-TIME* TIME) (setf *SHORTEST-ROUTE* (list (car queue)))) (setf *ROUTE-COUNT* (+ 1 *ROUTE-COUNT*)) (format t "~d~a ~d ~a ~d ~%" *ROUTE-COUNT* "." TIME "shortest:" *SHORTEST-TIME*))) (simple-tsp-search target (cdr queue))) ; ;-----------------------------------------------------------------< DO Otherwise >----- (t (let* ((HOW-DEFN (how-defined (cadaar queue))) (DISMISS (mapcar #'cadr (car queue))) (CHILDREN (remove-if #'(lambda (p) (member (cadr p) DISMISS)) HOW-DEFN))) (if (null CHILDREN) (simple-tsp-search target (cdr queue)) ; ;---------------------< EXPAND THE TOP QUEUE AND ATACHES IT/THEM TO THE TOP >----- (let* ((expanded-top-queue (mapcar #'(lambda (p) (cons p (car queue))) CHILDREN)) (new-queue (append expanded-top-queue (cdr queue)))) (simple-tsp-search target new-queue)))))))) *注:このプログラムはすべての巡回経路とその所要時間を求める 方法を示すもので、最少時間で解を求める方法ではありません。