backtrck.red 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module backtrck;
  2. fluid '(g_skip_to_level);
  3. symbolic procedure generate_next_choice(sc, partial_perm, canon);
  4. begin scalar
  5. next_perm, comparison, extensions;
  6. integer
  7. n_points, len, next_img;
  8. n_points := upbve(car sc);
  9. g_skip_to_level := len := upbve(partial_perm) + 1;
  10. next_img := 1;
  11. sc_setbase(sc, partial_perm);
  12. repeat
  13. <<
  14. extensions := candidate_extensions(sc, partial_perm);
  15. if (member(next_img, extensions)) then
  16. <<
  17. next_perm := vectappend1(partial_perm, next_img);
  18. if acceptable(next_perm) then
  19. <<
  20. assign(next_perm);
  21. comparison := compare(next_perm, canon);
  22. if comparison = 0 then % 0 = indifferent
  23. <<
  24. if len < n_points then
  25. canon := car generate_next_choice(sc, next_perm, canon)
  26. else if canon then
  27. process_new_automorphism(sc,
  28. pe_mult(pe_inv(canon), next_perm));
  29. >>
  30. else if comparison = 1 then % 1 = better
  31. if len < n_points then
  32. canon := car generate_next_choice(sc, next_perm, canon)
  33. else
  34. canon := copy(next_perm);
  35. deassign(next_perm)
  36. >>
  37. >>;
  38. next_img := next_img + 1
  39. >>
  40. until (next_img > n_points) or (len > g_skip_to_level);
  41. return canon . sc;
  42. end;
  43. symbolic procedure candidate_extensions(sc, partial_perm);
  44. begin scalar extensions;
  45. % integer count;
  46. if null sc_stabdesc(sc, upbve(partial_perm) + 1) then
  47. extensions := for count := 1:upbve(car sc) collect count
  48. else
  49. extensions := venth(venth(cdr sc, upbve(partial_perm) +1), 5);
  50. % remove elts of partial_perm from extensions
  51. for count := 1: upbve(partial_perm) do
  52. extensions := delete(venth(partial_perm, count), extensions);
  53. return extensions;
  54. end;
  55. symbolic procedure process_new_automorphism(sc, new_aut);
  56. begin scalar inv_new_aut, sd;
  57. integer count;
  58. inv_new_aut := pe_inv(new_aut);
  59. %% update stab chain
  60. count := 0;
  61. repeat
  62. <<
  63. count := count + 1;
  64. sd := sc_stabdesc(sc, count);
  65. if null sd then
  66. sd := sd_create(upbve(car sc), venth(car sc, count));
  67. sd_addgen(sd, new_aut, inv_new_aut);
  68. putve(cdr sc, count, sd)
  69. >>
  70. until (pe_apply(new_aut, venth(car sc, count)) neq
  71. venth(car sc, count));
  72. g_skip_to_level := count;
  73. end;
  74. symbolic procedure canon_order(n);
  75. begin scalar aut_sc;
  76. aut_sc := sc_create(n);
  77. return generate_next_choice(aut_sc, mkve(0), nil);
  78. end;
  79. endmodule;
  80. end;