fork download
  1. op("a","b").
  2. op("b","c").
  3. op("c","d").
  4. op("d","c").
  5. op("c","g").
  6. op("g","h").
  7. op("d","h").
  8. op("h","n").
  9. op("n","h").
  10. op("h","s").
  11. op("s","f").
  12. op("n","f").
  13.  
  14. xy("a",3,7).
  15. xy("b",4,6).
  16. xy("c",4,5).
  17. xy("d",2,3).
  18. xy("g",5,4).
  19. xy("h",7,2).
  20. xy("n",8,4).
  21. xy("s",7,1).
  22. xy("f",10,2).
  23.  
  24. cmp(A, B, C):-
  25. xy(A, XA, YA),
  26. xy(B, XB, YB),
  27. C is sqrt(((XA-XB)*(XA-XB)) + ((YA-YB)*(YA-YB))).
  28.  
  29. cost(A, AY, C):-
  30. cmp(A, AY, C).
  31.  
  32. hn(N, HN):-
  33. theGoal(S),
  34. xy(S, XS, YS),
  35. xy(N, XN, YN),
  36. HN is sqrt(((XN-XS)*(XN-XS)) + ((YN-YS)*(YN-YS))).
  37.  
  38. sear([T|Queue], S):-
  39. ( goalReached(T)
  40. -> S = T
  41. ; Extension = [E || toDaughter(T,E)],
  42. NewQueue = list::append(Queue,Extension),
  43. BestFirst = list::sortBy(cmp,NewQueue),
  44. sear(BestFirst, S)
  45. ).
  46.  
  47. toDaughter(t(_F, G, [r(B, N)|Path]), t(F1, G1, [r(Op, Child), r(B, N)|Path])):-
  48. op(N, Child),
  49. format(atom(Op), "Винни-Пух передвигается из пункта ~w в пункт ~w", [N, Child]),
  50. not_in_circle(Child, Path),
  51. G1 is G + cost(N, Child, _),
  52. hn(Child, HN),
  53. F1 is G1 + HN.
  54.  
  55. prtSolution(t(_, _, T)):-
  56. foreach X = getMember_nd(reverse(T)) do
  57. write("", X),
  58. end foreach.
  59.  
  60. solve():-
  61. ( init(E) ->
  62. sear([t(hn(E),0,[r("",E)])],S),
  63. write("\nВинниПух начинает движение из пункта : ",E,"\n");
  64.  
  65. prtSolution(S);
  66.  
  67. write("Нет решения")
  68. ).
  69. run():-
  70. solve(),
  71. write("END"),nl.
  72.  
  73. :- main.
Success #stdin #stdout #stderr 0.04s 6920KB
stdin
1
2
10
42
11
stdout
Standard output is empty
stderr
ERROR: /home/W9Jm5p/prog:74:7: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit